Commit 47eb1d1c authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

minor bug fixes


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 6f539999
......@@ -30,85 +30,92 @@ std::vector<std::shared_ptr<AcceleratorBuffer>> ReadoutErrorAcceleratorBufferPos
int nKernels = ir.getKernels().size();
int nRepititions = buffers.size() / nKernels;
if (buffers.size() % nKernels != 0) {
xacc::error("ReadoutError Postprocessor: Invalid number of buffers and kernels.");
int nonIdentityKernels = 0;
for (auto& k : ir.getKernels()) {
if (k->nInstructions() > 0) {
nonIdentityKernels++;
}
}
if (buffers.size() % nonIdentityKernels != 0) {
xacc::error("ReadoutError Postprocessor: Invalid number of buffers and kernels - " + std::to_string(buffers.size()) + ", " + std::to_string(nonIdentityKernels) );
}
std::vector<std::vector<std::shared_ptr<AcceleratorBuffer>>> bufvec;
for (int i = 0; i < buffers.size(); i+=nKernels) {
std::vector<std::shared_ptr<AcceleratorBuffer>> sub(buffers.begin() + i, buffers.begin() + i + nKernels);
for (int i = 0; i < buffers.size(); i+=nonIdentityKernels) {
std::vector<std::shared_ptr<AcceleratorBuffer>> sub(buffers.begin() + i, buffers.begin() + i + nonIdentityKernels);
bufvec.push_back(sub);
}
std::vector<std::shared_ptr<AcceleratorBuffer>> fixedBuffers;
for ( auto subList : bufvec) {
std::vector<std::shared_ptr<Function>> nonIdentityKernels;
for (int i = 0; i < nKernels; i++) {
if (ir.getKernels()[i]->nInstructions() > 0) {
nonIdentityKernels.push_back(ir.getKernels()[i]);
std::vector<std::shared_ptr<Function>> nonIdentityKernels;
for (int i = 0; i < nKernels; i++) {
if (ir.getKernels()[i]->nInstructions() > 0) {
nonIdentityKernels.push_back(ir.getKernels()[i]);
}
}
}
auto nIk = nonIdentityKernels.size();
std::map<int, std::pair<double,double>> errorRates;
bool first = true;
int counter = 0, qbitCount=0;
std::vector<double> probs;
for (int i = allTerms.size(); i < nIk; i++) {
auto localBitStr = zeroStr;
auto kernel = nonIdentityKernels[i];
if (first) {
// we have a p01 buffer
auto bit = kernel->getInstruction(0)->bits()[0];
localBitStr[nQubits - bit - 1] = '1';
first = false;
} else {
// we have a p10 buffer
first = true;
}
auto nIk = nonIdentityKernels.size();
std::map<int, std::pair<double,double>> errorRates;
bool first = true;
int counter = 0, qbitCount=0;
std::vector<double> probs;
for (int i = allTerms.size(); i < nIk; i++) {
auto localBitStr = zeroStr;
auto kernel = nonIdentityKernels[i];
if (first) {
// we have a p01 buffer
auto bit = kernel->getInstruction(0)->bits()[0];
localBitStr[nQubits - bit - 1] = '1';
first = false;
} else {
// we have a p10 buffer
first = true;
}
xacc::info(kernel->getName() + " - Computing measurement probability for bit string = " + localBitStr);
xacc::info(kernel->getName() + " - Computing measurement probability for bit string = " + localBitStr);
probs.push_back(subList[i]->computeMeasurementProbability(localBitStr));
counter++;
probs.push_back(subList[i]->computeMeasurementProbability(localBitStr));
counter++;
if (counter == 2) {
errorRates.insert(
{ qbitCount, { std::isnan(probs[0]) ? 0.0 : probs[0],
std::isnan(probs[1]) ? 0.0 : probs[1] } });
counter = 0;
qbitCount++;
probs.clear();
if (counter == 2) {
errorRates.insert(
{ qbitCount, { std::isnan(probs[0]) ? 0.0 : probs[0],
std::isnan(probs[1]) ? 0.0 : probs[1] } });
counter = 0;
qbitCount++;
probs.clear();
}
}
}
for (auto& kv : errorRates) {
std::stringstream s, s2, s3;
s << "Qubit " << kv.first << ": p01 = " << kv.second.first << ", p10 = " << kv.second.second;
xacc::info(s.str());
}
for (auto& kv : errorRates) {
std::stringstream s, s2, s3;
s << "Qubit " << kv.first << ": p01 = " << kv.second.first << ", p10 = " << kv.second.second;
xacc::info(s.str());
}
// Return new AcceleratorBuffers subtype, StaticExpValAcceleratorBuffer that has static
std::map<std::string, double> oldExpects;
for (int i = 0; i < allTerms.size(); i++) {
xacc::info("Raw Expectatations: " + allTerms[i] + " = " + std::to_string(subList[i]->getExpectationValueZ()));
oldExpects.insert({allTerms[i], subList[i]->getExpectationValueZ()});
}
std::map<std::string, double> oldExpects;
for (int i = 0; i < allTerms.size(); i++) {
xacc::info("Raw Expectatations: " + allTerms[i] + " = " + std::to_string(subList[i]->getExpectationValueZ()));
oldExpects.insert({allTerms[i], subList[i]->getExpectationValueZ()});
}
auto fixed = fix_assignments(oldExpects, sites, errorRates);
auto fixed = fix_assignments(oldExpects, sites, errorRates);
// constant fixed expectation value from the calculation
// constant fixed expectation value from the calculation
for (int i = 0; i < allTerms.size(); i++) {
auto staticBuffer = std::make_shared<StaticExpectationValueBuffer>(subList[i]->name(), subList[i]->size(), fixed[allTerms[i]]);
fixedBuffers.push_back(staticBuffer);
}
for (int i = 0; i < allTerms.size(); i++) {
auto staticBuffer = std::make_shared<StaticExpectationValueBuffer>(subList[i]->name(), subList[i]->size(), fixed[allTerms[i]]);
fixedBuffers.push_back(staticBuffer);
}
}
return fixedBuffers;
......
......@@ -33,6 +33,7 @@ std::shared_ptr<AcceleratorBufferPostprocessor> QubitMapIRPreprocessor::process(
int newNQubits = *std::max_element(qubitMap.begin(), qubitMap.end()) + 1;
xacc::setOption("n-qubits",std::to_string(newNQubits));
}
// Construct a ReadoutErrorABPostprocessor
......
......@@ -87,28 +87,36 @@ std::shared_ptr<AcceleratorBufferPostprocessor> ReadoutErrorIRPreprocessor::proc
continue;
}
bool seen = false;
if (inst->getName() == "H") {
pauliStr = "X" + std::to_string(bit) + pauliStr;
pauliTerm[bit] = "X";
seen = true;
} else if (inst->getName() == "Rx") {
pauliStr = "Y" + std::to_string(bit) + pauliStr;
pauliTerm[bit] = "Y";
seen = true;
} else if (inst->getName() == "Measure") {
// do nothing
if (!boost::contains(pauliStr, "X" + std::to_string(bit))
&& !boost::contains(pauliStr,
"Y" + std::to_string(bit))) {
pauliStr = "Z" + std::to_string(bit) + pauliStr;
pauliTerm[bit] = "Z";
}
continue;
} else {
xacc::error("ReadoutErrorIRPreprocessor only can be "
"applied to kernels generated from a Pauli "
"Hamiltonian, cannot have " + inst->getName() + " gate");
}
}
if (!pauliStr.empty()) {
// std::cout << "PTERM: " << pauliStr << "\n";
orderedPauliTerms.push_back(pauliStr);
pauliTerms.push_back(pauliTerm);
}
}
// Use the above info to create the sites map
......
......@@ -175,6 +175,10 @@ public:
return accelerator;
}
void setBufferPostprocessors(std::vector<std::shared_ptr<AcceleratorBufferPostprocessor>> pps) {
bufferPostprocessors = pps;
}
/**
* Templated operator() overload.
*/
......
......@@ -138,6 +138,10 @@ public:
}
}
std::vector<std::shared_ptr<AcceleratorBufferPostprocessor>> getBufferPostprocessors() {
return bufferPostprocessors;
}
std::shared_ptr<IR> getIR() {
return xaccIR;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment