Skip to content

Implement R_XX, R_YY, R_ZZ, and R_PAULI parametric rotation gates#164

Open
kish-00 wants to merge 4 commits into
QuEraComputing:mainfrom
kish-00:pr/param-rotations
Open

Implement R_XX, R_YY, R_ZZ, and R_PAULI parametric rotation gates#164
kish-00 wants to merge 4 commits into
QuEraComputing:mainfrom
kish-00:pr/param-rotations

Conversation

@kish-00

@kish-00 kish-00 commented Jun 15, 2026

Copy link
Copy Markdown

Summary

Implements the four parametric rotation gates requested in #142:

  • R_XX(θ): Two-qubit XX rotation
  • R_YY(θ): Two-qubit YY rotation
  • R_ZZ(θ): Two-qubit ZZ rotation
  • R_PAULI(θ) Xa*Yb...: Arbitrary Pauli product rotation

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:

Gate θ=0.5 θ=1.0 θ=-0.5
R_XX SQRT_XX CX+X+CX SQRT_XX_DAG
R_YY SQRT_YY S+S+CX+X+CX+S_DAG+S_DAG SQRT_YY_DAG
R_ZZ SQRT_ZZ CX+Z+CX SQRT_ZZ_DAG
R_PAULI decomposed via Pauli rotation trick

Circuit Integration

  • inverse() with negated angle
  • is_clifford detection for half-π angles
  • stim_circuit with full Clifford expansion (pass-through for non-Clifford angles with parametric tags)
  • Shorthand ↔ Stim bidirectional conversion

Testing

329 unit tests passing (incl. upstream CCZ/CCX tests), including:

  • Shorthand parsing, Stim parity, non-Clifford self-consistency
  • Inverse unitarity, Clifford detection, expansion paths

Closes #142

This PR is a unitaryHACK 2026 submission.

@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: 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".

Comment thread src/tsim/core/parse.py Outdated
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":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment thread src/tsim/utils/clifford.py Outdated
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

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 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 👍 / 👎.

Comment thread src/tsim/circuit.py
Comment on lines +241 to +243
tag = f"R_PAULI(theta={args[0]}*pi)"
name = "SPP"
arg = None

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 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 👍 / 👎.

@kish-00

kish-00 commented Jun 16, 2026

Copy link
Copy Markdown
Author

Fix commits are now on the latest PR head (533ee5d). Current Actions runs for CI, Lint, and Documentation are completed as action_required with zero jobs/logs, and rerun is blocked for this account with “Must have admin rights to Repository.” Could a maintainer approve/re-run the required checks?

@kish-00

kish-00 commented Jun 16, 2026

Copy link
Copy Markdown
Author

Closing due to competing PRs (#152, #154, #161). Reallocating my 4PR slot to an uncontested bounty. Will monitor competitor PRs and may resubmit if they stall.

@kish-00 kish-00 closed this Jun 16, 2026
@kish-00 kish-00 reopened this Jun 16, 2026
@kish-00

kish-00 commented Jun 16, 2026

Copy link
Copy Markdown
Author

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.

kish-00 added 4 commits June 17, 2026 11:09
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
@kish-00 kish-00 force-pushed the pr/param-rotations branch from 533ee5d to 3eb4065 Compare June 17, 2026 08:10
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.

Implement R_XX, R_ZZ, R_YY, and R_PAULI gates

1 participant