Skip to content

Add a PauliRotationGate - #8424

Open
Acciaccatura wants to merge 18 commits into
quantumlib:mainfrom
Acciaccatura:issue6598
Open

Acciaccatura wants to merge 18 commits into
quantumlib:mainfrom
Acciaccatura:issue6598

Conversation

@Acciaccatura

@Acciaccatura Acciaccatura commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

this PR:

  • adds a PauliRotationGate gate, which represents the operation $e^{ikP}$ for some Pauli string $P$ and some real exponent $k$, as well as test cases.

PauliRotationGate and PauliRotation

the specs for PauliRotationGate are that:

  • it takes in a DensePauliString or any input that DensePauliString may take in, to define what string it will be rotating.
  • the exponent is parameterizable
  • when decomposed, it is made up of PauliStringPhasor, and uses global phase shifts when the supplied DensePauliString only consists of I's.

Alternatives

alternatively, I considered updating the functionality for PauliSumExponential to do this, but I think this would be tricky for a number of reasons:

  • classes PauliSumExponential depends on take in PauliString. PauliString, in its documentation, specifies that it drops identity gates, meaning the behavior of classes using it to also drop identity is WAI. changing this may break things.
  • to properly calculate rotations for DensePauliString, we would need to update PauliSumExponential and PauliSum to work with DensePauliString or maintain qubits, which might make things more confusing.

happy to discuss alternatives!

closes #6598.

@github-actions github-actions Bot added the size: L 250< lines changed <1000 label Oct 11, 2026
@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.58%. Comparing base (181d009) to head (78d2127).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8424      +/-   ##
==========================================
- Coverage   99.58%   99.58%   -0.01%     
==========================================
  Files        1137     1139       +2     
  Lines      105261   105448     +187     
==========================================
+ Hits       104826   105012     +186     
- Misses        435      436       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Acciaccatura Acciaccatura changed the title Add a PauliRotation operation Add a PauliRotationGate and PauliRotation operation Oct 13, 2026
@Acciaccatura
Acciaccatura marked this pull request as ready for review October 13, 2026 08:46
@Acciaccatura
Acciaccatura requested a review from a team as a code owner October 13, 2026 08:46
@arettig

arettig commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Hello, thanks for looking into this!

A note on the design before I do a full review:

  • I came to the same conclusion as you - we should not keep identities in PauliString so there is therefore no way that PauliSumExponential can correctly generate the unitaries with only a PauliString input. Adding DensePauliString and qubits support to PauliSumExponential would get messy. Adding a new gate therefore makes sense.
  • I am happy with the addition of a new gate, but I see you also added a new operation? GateOperation using your new gate should suffice unless I'm missing something?

@Acciaccatura

Copy link
Copy Markdown
Contributor Author

@arettig hey - thanks for the notes!

  • I am happy with the addition of a new gate, but I see you also added a new operation? GateOperation using your new gate should suffice unless I'm missing something?

I think you're right: the new operation does not add any new value that GateOperation would've. removed!

@arettig
arettig self-requested a review November 17, 2026 19:08

@arettig arettig left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great, thank you! See below for some suggested changes.

Additionally, can you update the title now that the operation has been removed.

TypeError: If `dense_pauli_string` is not a `cirq.DensePauliString` or a string.
"""
if not isinstance(dense_pauli_string, dps.DensePauliString):
dense_pauli_string = dps.DensePauliString(dense_pauli_string)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Calling the constructor with a MutableDensePauliString will treat it as an iterable of Pauli gates which drops the coefficient when converting to a DensePauliString. I suggest changing the constructor parameter type to BaseDensePauliString and simply calling .frozen() on it when setting the property here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure - done! I left in parameters to optionally initialize the underlying DensePauliString with however, just to make code possibly a little cleaner. let me know what your thoughts are!

if self._is_parameterized_():
raise ValueError("PauliRotationGate should not be parameterized.")
angle = complex(self._angle())
if not self._has_real_angle():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The angle can be checked in the constructor, as it is done in PauliSumExponential, so you don't have to worry about it throughout the rest of the implementation.

@Acciaccatura Acciaccatura Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this would make DensePauliString unparameterizable, since you can't do these checks on scipy.Symbol, and I think PauliSumExponential has the same issue with PauliString in its check? is that all right?

assert cirq.resolve_parameters(gate, {'t': 0.5}) == cirq.PauliRotationGate('XZ', 0.5)
coefficient_gate = cirq.PauliRotationGate(cirq.DensePauliString('XZ', coefficient=t))
assert cirq.is_parameterized(coefficient_gate)
assert cirq.parameter_names(coefficient_gate) == {'t'}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: maybe add one more test case with both fields parameterized just for completeness?

@Acciaccatura Acciaccatura Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

makes sense, added! but as per this comment, this possibly wouldn't be applicable anymore if we were to implement that change. wdyt?

@Acciaccatura Acciaccatura changed the title Add a PauliRotationGate and PauliRotation operation Add a PauliRotationGate Nov 19, 2026
@Acciaccatura
Acciaccatura requested a review from arettig November 19, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: L 250< lines changed <1000

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a gate to represent a PauliRotation

2 participants