Commit 156d56aa authored by Adams, Austin Joel's avatar Adams, Austin Joel
Browse files

AcceleratorBuffer: Use exp-val-z extra info for getExpectationValueZ() if present



Unconditonally return exp-val-z from AcceleratorBuffer extra info as
getExpectationValueZ() if exists. If we have a more precise result at
hand, why not use it instead of calculating a less precise answer?
Signed-off-by: Adams, Austin Joel's avatarAustin Adams <aja@gatech.edu>
parent 17c30f48
......@@ -424,9 +424,15 @@ const double AcceleratorBuffer::getExpectationValueZ() {
return 1;
};
if (bitStringToCounts.empty() && this->hasExtraInfoKey("exp-val-z")) {
if (this->hasExtraInfoKey("exp-val-z")) {
aver = mpark::get<double>(getInformation("exp-val-z"));
} else {
if (bitStringToCounts.empty()) {
xacc::error("called getExpectationValueZ() on an AcceleratorBuffer with "
"no measurements!");
return 0;
}
for (auto &kv : bitStringToCounts) {
int i = std::stoi(kv.first, nullptr, 2);
auto par = has_even_parity(i);
......
......@@ -55,6 +55,19 @@ TEST(AcceleratorBufferTester, checkGetExpectationValueZ) {
EXPECT_TRUE(std::fabs(b.getExpectationValueZ() - 0.178955078125) < 1e-6);
}
TEST(AcceleratorBufferTester, checkGetExpectationValueZPrioritizesExtraInfo) {
AcceleratorBuffer buffer("qreg", 5);
// Add decoy measurements, which have expected value of Z = 1
buffer.appendMeasurement("00000", 500);
// Add actual expectation we want
buffer.addExtraInfo("exp-val-z", -1.0);
// This should draw from extra info, not calculate from measurements
EXPECT_EQ(buffer.getExpectationValueZ(), -1.0);
}
TEST(AcceleratorBufferTester, checkLoad) {
const std::string bufferStr = R"bufferStr({
"AcceleratorBuffer": {
......
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