Skip to content

fix: To fix DEM canonicalisation#568

Open
kaiqiy-nv wants to merge 7 commits into
NVIDIA:mainfrom
kaiqiy-nv:kaiqiy/fix-DEM-canonicalisation-new
Open

fix: To fix DEM canonicalisation#568
kaiqiy-nv wants to merge 7 commits into
NVIDIA:mainfrom
kaiqiy-nv:kaiqiy/fix-DEM-canonicalisation-new

Conversation

@kaiqiy-nv

Copy link
Copy Markdown
Collaborator

This PR tries to fix [B] 6234203 .

It also strengthen the test cases to expose the bug and test further:

  • Specify merge_strategy='independent' in test_pymatching_decode_to_observable_surface_code_dem, since correct DEMs can contain parallel matching edges.
  • Use the external Stim’s DEM results to compare with the cudaq-qec's results.
  • Stim tests use pytest.importorskip("stim") so unsupported platforms get skipped.

Thank you for looking at this PR.

@kaiqiy-nv kaiqiy-nv requested a review from bmhowe23 May 28, 2026 06:39
@copy-pr-bot

copy-pr-bot Bot commented May 28, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Comment thread libs/qec/lib/detector_error_model.cpp Outdated
Comment on lines +89 to +91
// Keep the PCM/topological ordering from get_sorted_pcm_column_indices, but
// sort equal-syndrome groups by observable signature so merge-compatible DEM
// columns are adjacent.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this happens (same syndrome but different observable), this points to a problem in the QEC code where the code is essentially providing d<2 protection, and no decoder can help provide corrections in this situation. I think that we throw a warning in this case. I don't think that sorting the columns can help the decoder other than by random luck.

@kaiqiy-nv kaiqiy-nv May 29, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the code to remove the extra sorting and show a cudaq::warn when same-H diff-O.

@kaiqiy-nv kaiqiy-nv force-pushed the kaiqiy/fix-DEM-canonicalisation-new branch 2 times, most recently from 62ca48e to c374d76 Compare June 1, 2026 07:15
@bmhowe23

bmhowe23 commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

/ok to test c374d76

@bmhowe23

bmhowe23 commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Thanks, @kaiqiy-nv. Could you please investigate the errors and warnings in

For the warning, could we please cap it at ~10 messages per function invocation so as to not spam the user's console with a short distance code?

@kaiqiy-nv

Copy link
Copy Markdown
Collaborator Author

Hi @bmhowe23 ,

To cap warnings at 10 messages per function invocation -- DONE in the new push

Cause of the CI failure above here:

  1. We updated canonicalize_for_rounds to keep same-H diff-O signatures, which gives parallel edges in matching-graph terms.
  2. z_dem_from_memory_circuit calls canonicalize_for_rounds, so dem.detector_error_matrix now contains those parallel-edge columns.
  3. The failed test case test_sliding_window_1 builds the full decoder first qec.get_decoder(decoder_name, dem.detector_error_matrix). For pymatching, plain construction uses the default merge_strategy = disallow without observables provided, so it rejects the parallel edges, giving ValueError:.

Potential need to update sliding_window.cpp:

Setting merge_strategy="independent" alone does not fix the test logic because it only stops the construction crash, not the assertion. Without O, PyMatching decodes in column space and the full vs. windowed decoders pick different representative columns, so exact-equality still fails.

We may need further updates in sliding_window.cpp (slice and forward the observables matrix O per window, and decode/commit in observable space) to enable a genuinely observable-aware sliding-window decode — i.e., a faithful full-vs-window equivalence for matching decoders.

Do we need to implement this update?
If so, we can do it in another PR, and for now, we only consider to update the test_sliding_window.py.

Quick fix in the local test cases:

We have changed the asserts of the pymatching cases to compare syndrome reproduction ((H @ e) % 2 == syndrome) instead of exact equality, because same-H diff-O columns are identical in H, so the exact column is not unique but every valid correction must still reproduce the syndrome.
single_error_lut cases are kept for strict equality.

We have also added one more test case test_pymatching_parallel_edges_use_observable_faults to make up for direct-PyMatching coverage to make sure that H-only PyMatching rejects parallel edges while the O + merge_strategy path decodes successfully.

@kaiqiy-nv kaiqiy-nv force-pushed the kaiqiy/fix-DEM-canonicalisation-new branch from b53bdce to d0ca533 Compare June 2, 2026 11:24
kaiqiy-nv added 6 commits June 5, 2026 01:53
Signed-off-by: Kaiqi Yan <kaiqiy@nvidia.com>
Signed-off-by: Kaiqi Yan <kaiqiy@nvidia.com>
Signed-off-by: Kaiqi Yan <kaiqiy@nvidia.com>
Signed-off-by: Kaiqi Yan <kaiqiy@nvidia.com>
Signed-off-by: Kaiqi Yan <kaiqiy@nvidia.com>
Signed-off-by: Kaiqi Yan <kaiqiy@nvidia.com>
@kaiqiy-nv kaiqiy-nv force-pushed the kaiqiy/fix-DEM-canonicalisation-new branch from d0ca533 to c522b94 Compare June 5, 2026 01:54
@bmhowe23

bmhowe23 commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

/ok to test 0e431bb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants