Skip to content

Commit 62ca48e

Browse files
committed
throw a warning when same-H diff-O
Signed-off-by: Kaiqi Yan <kaiqiy@nvidia.com>
1 parent cff2fc5 commit 62ca48e

2 files changed

Lines changed: 31 additions & 24 deletions

File tree

libs/qec/lib/detector_error_model.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,29 +76,6 @@ void detector_error_model::canonicalize_for_rounds(
7676
return true;
7777
};
7878

79-
auto observables_less = [&](std::uint32_t lhs, std::uint32_t rhs) {
80-
for (std::size_t r = 0; r < num_obs; r++) {
81-
auto lhs_obs = this->observables_flips_matrix.at({r, lhs});
82-
auto rhs_obs = this->observables_flips_matrix.at({r, rhs});
83-
if (lhs_obs != rhs_obs)
84-
return lhs_obs < rhs_obs;
85-
}
86-
return lhs < rhs;
87-
};
88-
89-
// Keep the PCM/topological ordering from get_sorted_pcm_column_indices, but
90-
// sort equal-syndrome groups by observable signature so merge-compatible DEM
91-
// columns are adjacent.
92-
for (auto group_begin = column_order.begin();
93-
group_begin != column_order.end();) {
94-
auto group_end = group_begin + 1;
95-
while (group_end != column_order.end() &&
96-
row_indices[*group_end] == row_indices[*group_begin])
97-
++group_end;
98-
std::sort(group_begin, group_end, observables_less);
99-
group_begin = group_end;
100-
}
101-
10279
std::vector<std::uint32_t> final_column_order;
10380
// March through the columns in topological order, and combine the probability
10481
// weight vectors if the columns have the same row indices.
@@ -163,7 +140,7 @@ void detector_error_model::canonicalize_for_rounds(
163140
// Either the syndrome differs, or the same syndrome has a different
164141
// observable flip. In both cases this is a distinct error mechanism.
165142
if (prev_row_indices == curr_row_indices) {
166-
cudaq::info(
143+
cudaq::warn(
167144
"detector_error_model::canonicalize_for_rounds: identical "
168145
"syndromes exist in detector_error_matrix but have different "
169146
"observables in observables_flips_matrix; keeping column {} as a "

libs/qec/python/tests/test_dem.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,5 +570,35 @@ def test_pcm_extend_to_n_rounds():
570570
assert np.allclose(H15_new_error_rates, dem15.error_rates, atol=1e-6)
571571

572572

573+
def test_canonicalize_keeps_duplicate_syndromes_with_different_observables():
574+
# Same syndrome but different observable flips are distinct mechanisms.
575+
dem = qec.DetectorErrorModel()
576+
dem.detector_error_matrix = np.array([[1, 1]], dtype=np.uint8)
577+
dem.observables_flips_matrix = np.array([[0, 1]], dtype=np.uint8)
578+
dem.error_rates = [0.1, 0.2]
579+
580+
dem.canonicalize_for_rounds(1)
581+
582+
assert dem.detector_error_matrix.shape[1] == 2
583+
assert dem.observables_flips_matrix.shape[1] == 2
584+
assert np.array_equal(dem.observables_flips_matrix,
585+
np.array([[0, 1]], dtype=np.uint8))
586+
587+
588+
def test_canonicalize_merges_duplicate_syndromes_with_same_observables():
589+
# Same syndrome and same observable flip can be represented by one column.
590+
dem = qec.DetectorErrorModel()
591+
dem.detector_error_matrix = np.array([[1, 1]], dtype=np.uint8)
592+
dem.observables_flips_matrix = np.array([[1, 1]], dtype=np.uint8)
593+
dem.error_rates = [0.1, 0.2]
594+
595+
dem.canonicalize_for_rounds(1)
596+
597+
assert dem.detector_error_matrix.shape[1] == 1
598+
assert dem.observables_flips_matrix.shape[1] == 1
599+
assert np.array_equal(dem.observables_flips_matrix,
600+
np.array([[1]], dtype=np.uint8))
601+
602+
573603
if __name__ == "__main__":
574604
pytest.main()

0 commit comments

Comments
 (0)