Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ghost qubit bug #981 #998

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions runtime/nvqir/CircuitSimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,11 @@ class CircuitSimulatorBase : public CircuitSimulator {
if (iter == registerNameToMeasuredQubit.end())
registerNameToMeasuredQubit.emplace(mutableName,
std::vector<std::size_t>{qubitIdx});
else
iter->second.push_back(qubitIdx);
else {
if (std::find(iter->second.begin(), iter->second.end(), qubitIdx) ==
iter->second.end())
iter->second.push_back(qubitIdx);
}

return true;
}
Expand Down
17 changes: 17 additions & 0 deletions unittests/integration/measure_reset_tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,21 @@ TEST(MeasureResetTester, checkBug980) {
EXPECT_EQ(2, result.size());
EXPECT_TRUE(result.count("0") > 0);
EXPECT_TRUE(result.count("1") > 0);
}

TEST(MeasureResetTester, checkBug981) {
bmhowe23 marked this conversation as resolved.
Show resolved Hide resolved

auto bar = []() __qpu__ {
cudaq::qubit a;
cudaq::x(a);
[[maybe_unused]] auto a0 = cudaq::mz(a);
cudaq::reset(a);
[[maybe_unused]] auto a1 = cudaq::mz(a);
};

std::cout << "Bar:\n";
auto result = cudaq::sample(/*shots=*/10, bar);
result.dump();
EXPECT_EQ(1, result.size());
EXPECT_TRUE(result.count("0") > 0);
}
Loading