Implement R_XX, R_YY, R_ZZ, and R_PAULI parametric rotation gates#164
Implement R_XX, R_YY, R_ZZ, and R_PAULI parametric rotation gates#164kish-00 wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4a0e5f442c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| r_pauli(b, paulis, theta, dagger=is_dag ^ invert) | ||
| continue | ||
| # Fall through to TPP for tag=="T" or other recognized tags | ||
| if instruction.tag == "T": |
There was a problem hiding this comment.
Preserve user-tagged TPP rotations
When a user writes TPP[phase] ..., shorthand encodes it as SPP[T:phase] ...; this branch now only recognizes the exact tag T, so T:... falls through to the plain SPP handler below. That silently changes the operation from a π/8 Pauli-product rotation into a π/4 SPP rotation for any tagged TPP/TPP_DAG circuit.
Useful? React with 👍 / 👎.
| if idx == 2: | ||
| # Full Pauli product: decompose into stim-native gate sequences | ||
| # since single-gate names like "XX" are not stim gates. | ||
| q0, q1 = targets |
There was a problem hiding this comment.
Expand full rotations for every target pair
For a full-π two-qubit rotation applied to more than one pair in a single instruction, such as R_ZZ(1) 0 1 2 3, targets contains four qubits but this unpack expects exactly two. Other paths in this change accept grouped pairs, so Circuit(...).stim_circuit raises instead of expanding the valid batched instruction only when theta maps to index 2.
Useful? React with 👍 / 👎.
| tag = f"R_PAULI(theta={args[0]}*pi)" | ||
| name = "SPP" | ||
| arg = None |
There was a problem hiding this comment.
Export R_PAULI without applying the wrong SPP
Encoding every R_PAULI as a native SPP leaves Circuit('R_PAULI(-0.5) X0').stim_circuit exporting an SPP[...] X0 instruction, because the Clifford expansion path does not rewrite these tags. A plain Stim consumer then executes the +π/2 SPP instead of the requested -π/2 rotation (SPP_DAG), and other Clifford angles like 1.0 are similarly exported with the wrong native operation.
Useful? React with 👍 / 👎.
|
Fix commits are now on the latest PR head ( |
|
Actually, reopening — I want to keep this in play. The competing PRs haven't merged yet either, and mine is aligned with what's requested. |
Add four new parametric rotation gates: - R_XX(θ): Two-qubit XX rotation (θ in units of π) - R_YY(θ): Two-qubit YY rotation - R_ZZ(θ): Two-qubit ZZ rotation - R_PAULI(θ) Xa*Yb...: Pauli rotation on arbitrary Pauli products Gate classes: ParametricTwoQubitRotationGate, ParametricPauliRotationGate Parser: shorthand and program-text syntax for all four gates Requirement: angle parameter is required for these gate types
…for parametric rotations - Add Clifford expansion tables for R_XX/R_YY/R_ZZ (θ=n·π/2) - Add expand_clifford_rotations() for stim_circuit conversion - Add shorthand_to_stim/stim_to_shorthand support for all four gates - Add inverse(), is_clifford, and stim_circuit integration - R_XX(0.5) → SQRT_XX, R_YY(1.0) → S+S+CNOT+X+CNOT+S_DAG+S_DAG, etc.
- Shorthand parsing for R_XX/R_YY/R_ZZ/R_PAULI - Clifford-angle stim parity via statistical comparison - Non-Clifford self-consistency via decomposed reference circuits - Inverse unitarity for all four gate types - Clifford detection for half-π and non-Clifford angles - Gate-level expansion verification for all expansion paths (0.5, 1.0, -0.5)
…ford expansion - parse.py: use is_t_tag() instead of '== "T"' to handle tagged TPP gates - clifford.py: use is_t_tag() in is_clifford() for same reason - clifford.py: fix multi-pair crash in _expand_clifford_gates for R_XX/R_YY/R_ZZ with idx==2 (full Pauli product) by iterating over qubit pairs
533ee5d to
3eb4065
Compare
Summary
Implements the four parametric rotation gates requested in #142:
All angles are in units of π.
Clifford Expansion (θ = n·π/2 → native Stim gates)
When the rotation angle is a multiple of π/2, the gate is automatically expanded to native Stim gates in
stim_circuit:Circuit Integration
inverse()with negated angleis_clifforddetection for half-π anglesstim_circuitwith full Clifford expansion (pass-through for non-Clifford angles with parametric tags)Testing
329 unit tests passing (incl. upstream CCZ/CCX tests), including:
Closes #142
This PR is a unitaryHACK 2026 submission.