Skip to content

Support Stim DEM strings in get_decoder#571

Merged
vedika-saravanan merged 18 commits into
NVIDIA:mainfrom
vedika-saravanan:pr-stim-dem-decoder-init
Jun 8, 2026
Merged

Support Stim DEM strings in get_decoder#571
vedika-saravanan merged 18 commits into
NVIDIA:mainfrom
vedika-saravanan:pr-stim-dem-decoder-init

Conversation

@vedika-saravanan

@vedika-saravanan vedika-saravanan commented May 28, 2026

Copy link
Copy Markdown
Collaborator

Description

Adds unified decoder initialization from either a parity-check matrix or raw Stim detector error model text.

This supports both existing PCM-based decoders and DEM-native decoders needed by #546. PCM-based decoders can parse DEM text into H, O, and error_rate_vec defaults, while DEM-native decoders can consume the raw DEM text without going through a lossy matrix conversion.

API (cudaq/qec/decoder.h)

  • Adds decoder_init = std::variant<sparse_binary_matrix, std::string> as the decoder registry construction input.
  • Keeps existing PCM construction paths:
    • get_decoder(name, H, options)
    • decoder::get(name, H, options)
  • Adds DEM string construction through the same entry points:
    • get_decoder(name, dem_text, options)
    • decoder::get(name, dem_text, options)
  • Adds dem_from_stim_text(dem_text) to parse Stim DEM text into detector_error_model.
  • Adds helper routing for PCM-based decoders so DEM-derived O and error_rate_vec are supplied as defaults when not explicitly provided by the user.

The DEM-to-detector_error_model parser is lossy: it extracts detector flips, observable flips, and per-error probabilities, but drops detector coordinates and separator-encoded correlation structure. DEM-native decoders should consume the raw string alternative in decoder_init.

Python: cudaq_qec.get_decoder(...) now accepts Stim DEM strings. Python-registered decoders currently receive parsed H plus DEM-derived O / error_rate_vec defaults, not raw DEM text.

Dependency / build

QEC now provides its own Stim dependency via FetchContent when libstim is not already available, so standalone QEC builds do not depend on parent CUDA-Q interim build artifacts.

Tests

C++ gtests and Python tests cover:

  • DEM string construction through get_decoder(...)
  • PCM construction still working
  • user-provided options overriding DEM-derived defaults
  • DEM parse edge cases
  • DEMs without observables
  • stim::DemTarget category assumptions

Out of scope / follow-ups

Chromobius plugin integration itself; detector-coordinate storage on detector_error_model; optional PyMatching-specific improvements; user-facing Sphinx/RST docs.

Runtime / performance impact

N/A

Self-review checklist

Please confirm each item before requesting review. Check [x] or strike
through and explain.

Before requesting review

  • I reviewed my own full diff in GitHub or my editor.
  • PR is in Draft if it is not yet ready for review.
  • Temporary / debugging changes have been removed.
  • Local test logs reviewed; no unexplained warnings or errors.
  • CI logs reviewed; no unexplained warnings or errors.
  • Full CI has been run.

Scope and size

  • PR is under ~1000 lines, or an exception is justified in the description.
  • Refactoring-only changes are isolated in their own PR(s).
  • No existing tests were disabled or modified just to make this PR pass
    (if so, an issue has been raised).

Tests

  • New functionality has new tests.
  • Tests fail if the new functionality is broken (including crashes), not
    just when it is missing.
  • Negative tests added where exceptions are expected.
  • Truth data added where simple EXPECT_* / assert checks are
    insufficient for algorithmic correctness.
  • CI runtime impact considered; team notified if significant.

Documentation

  • Public-facing APIs have Doxygen docs.
  • User-visible behavior changes have public docs, or a follow-up is
    tracked.
  • User-facing docs for new features are in a separate PR held until
    release (the docs site publishes immediately on merge to the default
    branch, so feature docs must not land before the feature ships).

Code style

  • Naming follows the existing convention (snake_case vs camelCase) for
    the area being modified.

Dependencies

  • No new third-party dependencies, or the team has been notified and
    OSRB tickets filed.

@vedika-saravanan vedika-saravanan force-pushed the pr-stim-dem-decoder-init branch 4 times, most recently from e034551 to b3aa44a Compare June 2, 2026 15:44
@vedika-saravanan vedika-saravanan marked this pull request as ready for review June 2, 2026 16:02
@vedika-saravanan vedika-saravanan requested review from bmhowe23, justinlietz and melody-ren and removed request for bmhowe23, justinlietz and melody-ren June 2, 2026 16:02
@vedika-saravanan vedika-saravanan force-pushed the pr-stim-dem-decoder-init branch from b3aa44a to bccd851 Compare June 2, 2026 16:19
@vedika-saravanan vedika-saravanan marked this pull request as draft June 2, 2026 16:57
@vedika-saravanan vedika-saravanan marked this pull request as ready for review June 2, 2026 17:03
@vedika-saravanan vedika-saravanan marked this pull request as draft June 3, 2026 03:04
@vedika-saravanan vedika-saravanan force-pushed the pr-stim-dem-decoder-init branch from 5b57205 to 6603369 Compare June 3, 2026 03:14
@vedika-saravanan vedika-saravanan marked this pull request as ready for review June 3, 2026 03:36
Comment thread libs/qec/include/cudaq/qec/decoder.h
Comment thread libs/qec/lib/CMakeLists.txt Outdated
Comment thread libs/qec/include/cudaq/qec/decoder.h Outdated
@vedika-saravanan vedika-saravanan force-pushed the pr-stim-dem-decoder-init branch from 71c1666 to 1b2c61c Compare June 5, 2026 17:47
Signed-off-by: vedika-saravanan <vsaravanan@nvidia.com>
Signed-off-by: vedika-saravanan <vsaravanan@nvidia.com>
Signed-off-by: vedika-saravanan <vsaravanan@nvidia.com>
Signed-off-by: vedika-saravanan <vsaravanan@nvidia.com>
Signed-off-by: vedika-saravanan <vsaravanan@nvidia.com>
Signed-off-by: vedika-saravanan <vsaravanan@nvidia.com>
@NVIDIA NVIDIA deleted a comment from copy-pr-bot Bot Jun 5, 2026
@vedika-saravanan vedika-saravanan marked this pull request as draft June 5, 2026 19:09
Signed-off-by: vedika-saravanan <vsaravanan@nvidia.com>
Signed-off-by: vedika-saravanan <vsaravanan@nvidia.com>
@vedika-saravanan vedika-saravanan force-pushed the pr-stim-dem-decoder-init branch from 00a9838 to fb6dcfc Compare June 8, 2026 16:04
@vedika-saravanan vedika-saravanan force-pushed the pr-stim-dem-decoder-init branch from d6be6ce to f428c85 Compare June 8, 2026 17:08
…vailable

Signed-off-by: vedika-saravanan <vsaravanan@nvidia.com>
@vedika-saravanan vedika-saravanan force-pushed the pr-stim-dem-decoder-init branch from f428c85 to 1253540 Compare June 8, 2026 17:30
@vedika-saravanan vedika-saravanan marked this pull request as ready for review June 8, 2026 17:44
@vedika-saravanan vedika-saravanan changed the title Enable decoder construction from Stim DEM strings Support Stim DEM strings in get_decoder Jun 8, 2026
Signed-off-by: vedika-saravanan <vsaravanan@nvidia.com>
@vedika-saravanan vedika-saravanan force-pushed the pr-stim-dem-decoder-init branch from ccb933f to 05b5d5a Compare June 8, 2026 18:27
Signed-off-by: vedika-saravanan <vsaravanan@nvidia.com>
@vedika-saravanan vedika-saravanan requested a review from bmhowe23 June 8, 2026 19:42

@bmhowe23 bmhowe23 left a comment

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.

This is looking good...thanks, @vedika-saravanan. Just a few follow-up questions below.

Comment thread libs/qec/lib/CMakeLists.txt
Comment thread libs/qec/unittests/test_decoders.cpp
Signed-off-by: vedika-saravanan <vsaravanan@nvidia.com>
@vedika-saravanan vedika-saravanan requested a review from bmhowe23 June 8, 2026 21:34

@bmhowe23 bmhowe23 left a comment

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.

Thanks! Could you please create a follow-up PR/issue to add docs for this capability? We should add a public example for this.

@vedika-saravanan

Copy link
Copy Markdown
Collaborator Author

GHI for adding docs and example #595

@vedika-saravanan vedika-saravanan enabled auto-merge (squash) June 8, 2026 21:41
@vedika-saravanan vedika-saravanan merged commit 795f5fd into NVIDIA:main Jun 8, 2026
23 checks passed
@bmhowe23

Copy link
Copy Markdown
Collaborator

@vedika-saravanan can you please do ninja zip_installed_files and inspect the zip file that it produces? I am seeing many stim binaries and directories that should not be "installed", and I suspect this PR is the one that added them.

vedika-saravanan added a commit that referenced this pull request Jun 10, 2026
…598)

## Description

Updates QEC docs and adds public C++ and Python examples for decoder
construction from Stim DEM strings.

Closes: #595

## Runtime / performance impact

N/A. Documentation/example-only change.

## Self-review checklist

Please confirm each item before requesting review. Check `[x]` or strike
through and explain.

### Before requesting review
- [x] I reviewed my own full diff in GitHub or my editor.
- [ ] PR is in Draft if it is not yet ready for review.
- [x] Temporary / debugging changes have been removed.
- [x] Local test logs reviewed; no unexplained warnings or errors.
- [x] CI logs reviewed; no unexplained warnings or errors.
- [x] Full CI has been run.

### Scope and size
- [x] PR is under ~1000 lines, or an exception is justified in the
description.
- [ ] Refactoring-only changes are isolated in their own PR(s).
- [x] No existing tests were disabled or modified just to make this PR
pass
      (if so, an issue has been raised).

### Tests
- [ ] New functionality has new tests: Docs/example-only PR; runtime
functionality is covered by #571 tests.
- [ ] Tests fail if the new functionality is broken (including crashes),
not
      just when it is missing: N/A, no runtime behavior added.
- [ ] Negative tests added where exceptions are expected: N/A
- [ ] Truth data added where simple `EXPECT_*` / `assert` checks are
      insufficient for algorithmic correctness: N/A
- [x] CI runtime impact considered; team notified if significant.

### Documentation
- [x] Public-facing APIs have Doxygen docs.
- [x] User-visible behavior changes have public docs, or a follow-up is
      tracked.

### Code style
- [x] Naming follows the existing convention (`snake_case` vs
`camelCase`) for
      the area being modified.

### Dependencies
- [x] No new third-party dependencies, **or** the team has been notified
and
      OSRB tickets filed.

---------

Signed-off-by: vedika-saravanan <vsaravanan@nvidia.com>
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