feat: add parametric Pauli rotation gates#154
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2013b67885
ℹ️ 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".
| _, params = parsed | ||
| gates = parametric_to_clifford_gates(parsed[0], params) |
There was a problem hiding this comment.
Preserve SPP_DAG direction during Clifford expansion
When a user supplies a half-pi parametric SPP_DAG[...] instruction, Circuit.stim_circuit expands it using only the tag angle and ignores instr.name. For example, SPP_DAG[R_PAULI(theta=0.5*pi)] X0*Y1 is the inverse Pauli rotation, but this maps theta=0.5 to SPP instead of SPP_DAG, changing the unitary returned by the public stim_circuit property. Account for SPP_DAG by negating the effective theta or swapping the expanded SPP/SPP_DAG gates.
Useful? React with 👍 / 👎.
| gate_name, params = parsed | ||
| theta = float(-params["theta"]) | ||
| new_tag = f"{gate_name}(theta={theta}*pi)" | ||
| result.append( | ||
| "SPP", instr.targets_copy(), args, tag=new_tag |
There was a problem hiding this comment.
Keep theta when inverting existing SPP_DAG rotations
For circuits that already contain a parametric SPP_DAG[...] instruction, Stim's inverse flips it to SPP[...] with the same tag, which is already the correct inverse under parse_stim_circuit's is_dag sign handling. This block then negates theta and always appends SPP, so Circuit.from_stim_program(stim.Circuit('SPP_DAG[R_PAULI(theta=0.25*pi)] X0')).inverse() represents the original rotation instead of its inverse. The theta should only be negated for the post-inversion SPP_DAG case, not for SPP.
Useful? React with 👍 / 👎.
Adds
R_XX,R_YY,R_ZZ, andR_PAULIper clifft Pauli rotation spec:exp(-i * alpha * pi/2 * PP).Encoded as
SPP+ parametric tag, same pattern asTPP → SPP[T].Now we can use like-
Closes: #142