Skip to content

Commit 61b53a1

Browse files
authored
Fix stim.Circuit.explain_detector_error_model_errors over-counting HERALDED_ERASE measurements (#969)
Fixes #968
1 parent 7245235 commit 61b53a1

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

src/stim/simulators/error_matcher.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,12 @@ void ErrorMatcher::err_heralded_pauli_channel_1(const CircuitInstruction &op) {
179179
cur_loc.flipped_measurement.measurement_record_index = UINT64_MAX;
180180

181181
assert(error_analyzer.error_class_probabilities.empty());
182-
error_analyzer.tracker.undo_gate(op);
182+
error_analyzer.tracker.undo_gate(CircuitInstruction{
183+
op.gate_type,
184+
op.args,
185+
op.targets.sub(k, k + 1),
186+
op.tag,
187+
});
183188
error_analyzer.mono_buf.clear();
184189
error_analyzer.error_class_probabilities.clear();
185190
error_analyzer.flushed_reversed_model.clear();

src/stim/simulators/error_matcher.test.cc

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,3 +549,63 @@ ExplainedError {
549549
}
550550
)RESULT");
551551
}
552+
553+
TEST(ErrorMatcher, heralded_error) {
554+
Circuit circuit(R"CIRCUIT(
555+
HERALDED_ERASE(0.01) 0
556+
DETECTOR rec[-1]
557+
HERALDED_ERASE(0.01) 1 2
558+
)CIRCUIT");
559+
DetectorErrorModel filter(R"MODEL(
560+
error(1) D0
561+
)MODEL");
562+
563+
auto actual = ErrorMatcher::explain_errors_from_circuit(
564+
circuit,
565+
&filter,
566+
false);
567+
std::stringstream ss;
568+
for (const auto &match : actual) {
569+
ss << "\n" << match << "\n";
570+
}
571+
ASSERT_EQ(ss.str(), R"RESULT(
572+
ExplainedError {
573+
dem_error_terms: D0
574+
CircuitErrorLocation {
575+
flipped_measurement.measurement_record_index: 0
576+
Circuit location stack trace:
577+
(after 0 TICKs)
578+
at instruction #1 (HERALDED_ERASE) in the circuit
579+
at target #1 of the instruction
580+
resolving to HERALDED_ERASE(0.01) 0
581+
}
582+
CircuitErrorLocation {
583+
flipped_pauli_product: X0
584+
flipped_measurement.measurement_record_index: 0
585+
Circuit location stack trace:
586+
(after 0 TICKs)
587+
at instruction #1 (HERALDED_ERASE) in the circuit
588+
at target #1 of the instruction
589+
resolving to HERALDED_ERASE(0.01) 0
590+
}
591+
CircuitErrorLocation {
592+
flipped_pauli_product: Y0
593+
flipped_measurement.measurement_record_index: 0
594+
Circuit location stack trace:
595+
(after 0 TICKs)
596+
at instruction #1 (HERALDED_ERASE) in the circuit
597+
at target #1 of the instruction
598+
resolving to HERALDED_ERASE(0.01) 0
599+
}
600+
CircuitErrorLocation {
601+
flipped_pauli_product: Z0
602+
flipped_measurement.measurement_record_index: 0
603+
Circuit location stack trace:
604+
(after 0 TICKs)
605+
at instruction #1 (HERALDED_ERASE) in the circuit
606+
at target #1 of the instruction
607+
resolving to HERALDED_ERASE(0.01) 0
608+
}
609+
}
610+
)RESULT");
611+
}

0 commit comments

Comments
 (0)