diff --git a/runtime/nvqir/CircuitSimulator.h b/runtime/nvqir/CircuitSimulator.h index b4cb7e6fdd..856929caa9 100644 --- a/runtime/nvqir/CircuitSimulator.h +++ b/runtime/nvqir/CircuitSimulator.h @@ -413,8 +413,11 @@ class CircuitSimulatorBase : public CircuitSimulator { if (iter == registerNameToMeasuredQubit.end()) registerNameToMeasuredQubit.emplace(mutableName, std::vector{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; } diff --git a/unittests/integration/measure_reset_tester.cpp b/unittests/integration/measure_reset_tester.cpp index 3319f9cfa3..83ad81fd8e 100644 --- a/unittests/integration/measure_reset_tester.cpp +++ b/unittests/integration/measure_reset_tester.cpp @@ -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) { + + 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); } \ No newline at end of file