Skip to content

Add Stim circuit importer#229

Merged
masa10-f merged 7 commits into
masterfrom
agent/stim-importer
Jul 16, 2026
Merged

Add Stim circuit importer#229
masa10-f merged 7 commits into
masterfrom
agent/stim-importer

Conversation

@masa10-f

Copy link
Copy Markdown
Collaborator

Summary

  • Rebuild the Stim circuit importer on the current master after Add Stim MPP stabilizer import #217 was squash-merged.
  • Import supported noiseless Clifford unitary blocks and tick-separated MPP blocks.
  • Preserve sparse Stim qubit mappings, QUBIT_COORDS metadata, detector groups, and logical observables across MPP rounds.
  • Register QEC data-layer endpoints as graph inputs and outputs while preserving Type I and Type II foliation behavior.

Correctness fixes

  • Recompute unitary-derived Z correction flows after graph-fragment composition so TICK boundaries do not change circuit semantics.
  • Track absolute Stim measurement-record indices across blocks.
  • Import multiple MPP layers in one tick block and annotation-only tick blocks.
  • Add state-vector equivalence and detector-record regression tests.

Replaces #224, which GitHub cannot reopen after its deleted base branch was squash-merged and the head history was rebuilt.

Validation

  • uv run --no-sync pytest -s -m "not pyzx" -q — 531 passed, 1 skipped.
  • uv run --no-sync pytest -s -m pyzx -q — 13 passed.
  • uv run --no-sync pytest -s --cov=graphqomb --cov-report=term-missing --cov-report=xml --cov-branch -q — 544 passed, 87.98% total coverage.
  • uv run --no-sync ruff check ./graphqomb ./tests ./examples
  • uv run --no-sync ruff format --check --diff
  • uv run --no-sync mypy
  • uv run --no-sync pyright
  • uv run --no-sync sphinx-build -W -E docs/source docs/build

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.85121% with 76 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.09%. Comparing base (c4f600f) to head (ac3c095).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #229      +/-   ##
==========================================
+ Coverage   85.55%   86.09%   +0.54%     
==========================================
  Files          27       29       +2     
  Lines        4035     4451     +416     
  Branches      703      783      +80     
==========================================
+ Hits         3452     3832     +380     
- Misses        413      438      +25     
- Partials      170      181      +11     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@masa10-f
masa10-f marked this pull request as ready for review July 15, 2026 22:27
This was referenced Jul 15, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6db8527614

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread graphqomb/stim_importer.py Outdated
context: _ImportContext,
) -> _Fragment:
text = _stim_text_with_coords(block, coordinate_by_stim_id=context.coordinate_by_stim_id)
extraction = stabilizer_code_from_stim_text(text, mpp_layer=None, coord_dims=context.coord_dims)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Split sequential MPP layers instead of merging them

When one tick block contains multiple MPP layers separated by annotations, such as MPP X0; DETECTOR rec[-1]; MPP Z0, this selects all products into one StabilizerCode and builds a single graph fragment. Stim executes those as sequential measurements, and non-commuting layers collapse the state between records; merging them into one stabilizer-code fragment makes both checks share the same data input/output chain, so the imported pattern can represent the wrong post-measurement state. Split these layers into composed MPP fragments, or reject non-commuting multi-layer blocks.

Useful? React with 👍 / 👎.

@masa10-f

Copy link
Copy Markdown
Collaborator Author

With this branch, I don't fully do integrated tests since a couple of upcoming PRs would touch the same files

@masa10-f
masa10-f merged commit 133621a into master Jul 16, 2026
24 checks passed
@masa10-f
masa10-f deleted the agent/stim-importer branch July 16, 2026 13:33
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.

1 participant