Skip to content

Integrate Stim Clifford parser with H/HS/CZ basis#236

Merged
masa10-f merged 9 commits into
masterfrom
agent/integrate-stim-parser
Jul 20, 2026
Merged

Integrate Stim Clifford parser with H/HS/CZ basis#236
masa10-f merged 9 commits into
masterfrom
agent/integrate-stim-parser

Conversation

@masa10-f

Copy link
Copy Markdown
Collaborator

Summary

  • integrate the stim-clifford-transpiler draft as the packaged graphqomb.stim_parser API
  • normalize supported Stim Clifford operations to H, C_XNYZ (logical HS), and CZ
  • add HS, Circuit.hs(), and MBQCCircuit.hs(), each lowering HS = J(pi/2) to exactly one J primitive
  • route every Stim importer unitary TICK block through the new parser while preserving the existing reset, measurement, annotation, noise-idealization, and qubit-lifetime behavior
  • document the parser and extend parser, gate, circuit, and importer coverage

Why

GraphQOMB previously handled a small fixed set of Stim gates directly in the importer. This made broader Clifford support difficult and left identities such as repeated CZ pairs to fail during graph construction. The new packaged normalization layer provides one canonical GraphQOMB unitary basis and makes the importer independent of Stim's individual Clifford spellings.

Self-review findings

The self-review found that the optimizer preserved inverted M !q targets but dropped the inversion on native MX !q and MY !q instructions. The atomic measurement handling now preserves the inversion for all three Pauli measurement bases, with a regression test for each basis.

Additional regression tests cover cancellation across commuting operations and precise locations for unsupported instructions inside nested REPEAT blocks.

Validation

  • pytest -q --capture=no: 785 passed
  • ruff check .: passed
  • mypy graphqomb tests examples: passed
  • pyright graphqomb tests examples: 0 errors, 0 warnings
  • sphinx -W -b html docs/source docs/_build/html: passed
  • wheel build: passed; both graphqomb/stim_parser/__init__.py and _core.py are included
  • extra semantic audit: all one-qubit H/HS words through length 8, 1,000 randomized four-qubit basis circuits, and all 48 Stim unitary gate names retained Tableau equivalence

The wheel build emits only the repository's existing Setuptools license deprecation warnings.

@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.51485% with 58 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.41%. Comparing base (909cd68) to head (9e07b46).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #236      +/-   ##
==========================================
+ Coverage   86.27%   86.41%   +0.13%     
==========================================
  Files          29       31       +2     
  Lines        4635     5086     +451     
  Branches      799      903     +104     
==========================================
+ Hits         3999     4395     +396     
- Misses        450      488      +38     
- Partials      186      203      +17     
🚀 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 19, 2026 23:32
@masa10-f masa10-f self-assigned this Jul 19, 2026
masa10-f and others added 3 commits July 19, 2026 20:50
…imization

Drop the intermediate H/S/CZ optimization pass: templates now emit HS
directly, and the optimizer canonicalizes every maximal single-qubit gate
run to the shortest H/HS word with the same Clifford action, enumerated
once by BFS over all 24 single-qubit Cliffords. This subsumes the old
pairwise H^2/(HS)^3/S^4 cancellations and guarantees minimal single-qubit
sequences.

Also apply review cleanups: merge the duplicated boundary-replacement
helpers, remove the redundant Circuit.hs()/MBQCCircuit.hs() methods in
favor of apply_macro_gate(HS(q)), deduplicate circuit coercion in
transpile, replace conditional basis plumbing with module constants, and
drop the S_DAG special case.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add the negative-sign XY-plane measurements J(pi) = HZ (Stim SQRT_Y) and
J(-pi/2) = HS_DAG (Stim C_XYZ) alongside H and HS as single-qubit basis
gates. Shortest-word canonicalization over the four generators brings any
single-qubit Clifford down to at most three J primitives (previously up to
seven), i.e. at most three graph nodes and measurements in the compiled
pattern.

Rename optimize_h_hs_cz to optimize_j_cz, export STIM_GATE_J_ANGLES, and
map every basis gate uniformly to one J(angle) macro in the Stim importer.
Statevector tests verify the X-/Y- gate semantics end to end.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@masa10-f

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 03d1c5db24

ℹ️ 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".

@masa10-f
masa10-f merged commit 14e5c92 into master Jul 20, 2026
24 checks passed
@masa10-f
masa10-f deleted the agent/integrate-stim-parser branch July 20, 2026 13:01
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