Skip to content

feat: add parametric Pauli rotation gates#154

Open
mahbub570 wants to merge 2 commits into
QuEraComputing:mainfrom
mahbub570:gates
Open

feat: add parametric Pauli rotation gates#154
mahbub570 wants to merge 2 commits into
QuEraComputing:mainfrom
mahbub570:gates

Conversation

@mahbub570
Copy link
Copy Markdown

@mahbub570 mahbub570 commented Jun 5, 2026

Adds R_XX, R_YY, R_ZZ, and R_PAULI per clifft Pauli rotation spec: exp(-i * alpha * pi/2 * PP).
Encoded as SPP + parametric tag, same pattern as TPP → SPP[T].

Now we can use like-

from tsim import Circuit

# two-qubit special cases
c = Circuit("""
    R_XX(0.25) 0 1
    R_YY(0.5) 0 1
    R_ZZ(0.3) 0 1
""")
 
c = Circuit("R_PAULI(0.25) X0*Y1*Z2")
 
c = Circuit()
c.append("R_XX", [0, 1], arg=0.25)
c.append("R_PAULI", "X0*Y1", arg=0.25)

# inverse works
assert (c + c.inverse()).to_matrix() ≈ I

Closes: #142

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

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

Comment thread src/tsim/utils/clifford.py Outdated
Comment on lines +209 to +210
_, params = parsed
gates = parametric_to_clifford_gates(parsed[0], params)
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 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 👍 / 👎.

Comment thread src/tsim/circuit.py Outdated
Comment on lines +858 to +862
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
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 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 👍 / 👎.

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