Unverified Commit bb89f50b authored by Mccaskey, Alex's avatar Mccaskey, Alex Committed by GitHub
Browse files

Merge pull request #483 from ausbin/feature/acc-buf-exp-z

AcceleratorBuffer: Use exp-val-z extra info for getExpectationValueZ() if present
parents 1d2d12fd 156d56aa
...@@ -424,9 +424,15 @@ const double AcceleratorBuffer::getExpectationValueZ() { ...@@ -424,9 +424,15 @@ const double AcceleratorBuffer::getExpectationValueZ() {
return 1; return 1;
}; };
if (bitStringToCounts.empty() && this->hasExtraInfoKey("exp-val-z")) { if (this->hasExtraInfoKey("exp-val-z")) {
aver = mpark::get<double>(getInformation("exp-val-z")); aver = mpark::get<double>(getInformation("exp-val-z"));
} else { } else {
if (bitStringToCounts.empty()) {
xacc::error("called getExpectationValueZ() on an AcceleratorBuffer with "
"no measurements!");
return 0;
}
for (auto &kv : bitStringToCounts) { for (auto &kv : bitStringToCounts) {
int i = std::stoi(kv.first, nullptr, 2); int i = std::stoi(kv.first, nullptr, 2);
auto par = has_even_parity(i); auto par = has_even_parity(i);
......
...@@ -55,6 +55,19 @@ TEST(AcceleratorBufferTester, checkGetExpectationValueZ) { ...@@ -55,6 +55,19 @@ TEST(AcceleratorBufferTester, checkGetExpectationValueZ) {
EXPECT_TRUE(std::fabs(b.getExpectationValueZ() - 0.178955078125) < 1e-6); 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) { TEST(AcceleratorBufferTester, checkLoad) {
const std::string bufferStr = R"bufferStr({ const std::string bufferStr = R"bufferStr({
"AcceleratorBuffer": { "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