Commit ef1a69b9 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

fixing ordering bug for terms in readout error preprocessor


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent b95fc92a
...@@ -24,7 +24,7 @@ namespace quantum { ...@@ -24,7 +24,7 @@ namespace quantum {
* The DWKernel is an XACC Function that contains * The DWKernel is an XACC Function that contains
* DWQMI Instructions. * DWQMI Instructions.
*/ */
class DWKernel: public virtual Function { class DWKernel: public virtual Function, public std::enable_shared_from_this<DWKernel> {
protected: protected:
...@@ -181,7 +181,6 @@ public: ...@@ -181,7 +181,6 @@ public:
xacc::error("DWKernel does not contain runtime parameters."); xacc::error("DWKernel does not contain runtime parameters.");
} }
EMPTY_DEFINE_VISITABLE() EMPTY_DEFINE_VISITABLE()
}; };
......
...@@ -195,7 +195,6 @@ public: ...@@ -195,7 +195,6 @@ public:
return parameters.size(); return parameters.size();
} }
virtual void evaluateVariableParameters( virtual void evaluateVariableParameters(
std::vector<InstructionParameter> runtimeParameters) { std::vector<InstructionParameter> runtimeParameters) {
......
...@@ -70,54 +70,41 @@ std::shared_ptr<AcceleratorBufferPostprocessor> ReadoutErrorIRPreprocessor::proc ...@@ -70,54 +70,41 @@ std::shared_ptr<AcceleratorBufferPostprocessor> ReadoutErrorIRPreprocessor::proc
// Search IR Functions and construct Pauli Term strings, then add any Pauli that is not there // Search IR Functions and construct Pauli Term strings, then add any Pauli that is not there
std::vector<std::string> orderedPauliTerms; std::vector<std::string> orderedPauliTerms;
std::vector<std::map<int, std::string>> pauliTerms; std::vector<std::map<int, std::string>> pauliTerms;
for (auto kernel : ir.getKernels()) {
std::string pauliStr = "";
CountGatesOfTypeVisitor<Measure> v(kernel);
bool allZTerm = false;
if (kernel->nInstructions() == v.countGates()) {
allZTerm = true;
}
std::map<int, std::string> pauliTerm;
for (auto inst : kernel->getInstructions()) {
auto bit = reversedQubitMap[inst->bits()[0]];
if (allZTerm) { for (auto term : ir.getKernels()) {
pauliTerm[bit] = "Z";
pauliStr = "Z" + std::to_string(bit) + pauliStr; if (term->nInstructions() > 0) {
continue; std::map<int, std::string> termMap;
} std::set<int> qubits;
for (auto pauli : term->getInstructions()) {
if (!pauli->isComposite()) {
auto bit = reversedQubitMap[pauli->bits()[0]];
qubits.insert(bit);
bool seen = false; if (pauli->getName() == "H") {
if (inst->getName() == "H") { termMap.insert( { bit, "X" });
pauliStr = "X" + std::to_string(bit) + pauliStr; } else if (pauli->getName() == "Rx") {
pauliTerm[bit] = "X"; termMap.insert( { bit, "Y" });
seen = true; }
} else if (inst->getName() == "Rx") {
pauliStr = "Y" + std::to_string(bit) + pauliStr; if (!termMap.count(bit)) {
pauliTerm[bit] = "Y"; termMap.insert( { bit, "Z" });
seen = true; }
} else if (inst->getName() == "Measure") {
if (!boost::contains(pauliStr, "X" + std::to_string(bit))
&& !boost::contains(pauliStr,
"Y" + std::to_string(bit))) {
pauliStr = pauliStr + "Z" + std::to_string(bit);
pauliTerm[bit] = "Z";
} }
continue;
} else {
xacc::error("ReadoutErrorIRPreprocessor only can be "
"applied to kernels generated from a Pauli "
"Hamiltonian, cannot have " + inst->getName() + " gate");
} }
} std::string pauliStr = "";
for (auto bit : qubits) {
pauliStr += termMap[bit] + std::to_string(bit);
}
// std::cout << "Pauli: " << pauliStr << "\n";
if (!pauliStr.empty()) {
// std::cout << "PTERM: " << pauliStr << "\n";
orderedPauliTerms.push_back(pauliStr); orderedPauliTerms.push_back(pauliStr);
pauliTerms.push_back(pauliTerm); pauliTerms.push_back(termMap);
} }
} }
// Use the above info to create the sites map // Use the above info to create the sites map
...@@ -133,15 +120,6 @@ std::shared_ptr<AcceleratorBufferPostprocessor> ReadoutErrorIRPreprocessor::proc ...@@ -133,15 +120,6 @@ std::shared_ptr<AcceleratorBufferPostprocessor> ReadoutErrorIRPreprocessor::proc
} }
// std::cout << "SITES:\n";
// for (auto & kv : sites) {
// std::cout << kv.first << " -> (";
// for (auto i : kv.second) {
// std::cout << i << " ";
// }
// std::cout << ")\n";
// }
// Discover any extra kernels we need to compute // Discover any extra kernels we need to compute
std::vector<std::string> extraKernelsNeeded; std::vector<std::string> extraKernelsNeeded;
for (auto t : pauliTerms) { for (auto t : pauliTerms) {
......
...@@ -186,6 +186,16 @@ public: ...@@ -186,6 +186,16 @@ public:
return std::make_shared<options_description>(); return std::make_shared<options_description>();
} }
/**
* Return the last execute call's execution time in seconds.
*
* @return runtime The execution time in seconds.
*/
virtual const double getExecutionTime() {
XACCLogger::instance()->info("getExecutionTime() not implemented by this Accelerator, returning 0.0.");
return 0.0;
}
/** /**
* Given user-input command line options, perform * Given user-input command line options, perform
* some operation. Returns true if runtime should exit, * some operation. Returns true if runtime should exit,
......
...@@ -243,6 +243,8 @@ public: ...@@ -243,6 +243,8 @@ public:
return kernels; return kernels;
} }
virtual ~Program() {}
}; };
} }
......
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