Integrate Stim Clifford parser with H/HS/CZ basis#236
Merged
Conversation
Codecov Report❌ Patch coverage is 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:
|
masa10-f
marked this pull request as ready for review
July 19, 2026 23:32
…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>
Collaborator
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
stim-clifford-transpilerdraft as the packagedgraphqomb.stim_parserAPIH,C_XNYZ(logicalHS), andCZHS,Circuit.hs(), andMBQCCircuit.hs(), each loweringHS = J(pi/2)to exactly oneJprimitiveWhy
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 !qtargets but dropped the inversion on nativeMX !qandMY !qinstructions. 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
REPEATblocks.Validation
pytest -q --capture=no: 785 passedruff check .: passedmypy graphqomb tests examples: passedpyright graphqomb tests examples: 0 errors, 0 warningssphinx -W -b html docs/source docs/_build/html: passedgraphqomb/stim_parser/__init__.pyand_core.pyare includedThe wheel build emits only the repository's existing Setuptools license deprecation warnings.