Skip to content

Extend RemoveIdentityEquivalent and CommutativeOptimization with PauliProductRotations#15810

Merged
Cryoris merged 8 commits intoQiskit:mainfrom
alexanderivrii:extend-passes-with-pprs
Mar 30, 2026
Merged

Extend RemoveIdentityEquivalent and CommutativeOptimization with PauliProductRotations#15810
Cryoris merged 8 commits intoQiskit:mainfrom
alexanderivrii:extend-passes-with-pprs

Conversation

@alexanderivrii
Copy link
Copy Markdown
Member

@alexanderivrii alexanderivrii commented Mar 15, 2026

Summary

This PR extends the passes RemoveIdentityEquivalent and CommutativeOptimization to handle PauliProductRotations.

Details and comments

Based on top of the bug-fix PR #15809.

@alexanderivrii alexanderivrii added this to the 2.5.0 milestone Mar 15, 2026
@alexanderivrii alexanderivrii requested a review from a team as a code owner March 15, 2026 11:27
@alexanderivrii alexanderivrii added Changelog: Added Add an "Added" entry in the GitHub Release changelog. mod: transpiler Issues and PRs related to Transpiler labels Mar 15, 2026
@qiskit-bot
Copy link
Copy Markdown
Collaborator

One or more of the following people are relevant to this code:

  • @Cryoris
  • @Qiskit/terra-core
  • @ajavadia

Comment thread crates/transpiler/src/passes/remove_identity_equiv.rs Outdated
Comment thread crates/circuit/src/operations.rs Outdated
Comment thread crates/circuit/src/operations.rs Outdated
@alexanderivrii alexanderivrii requested a review from Cryoris March 23, 2026 12:09
Comment thread crates/circuit/src/operations.rs Outdated
}

/// Attempts to merge `self` and `other`.
/// If successful, returns the merged `PauliProductRotation.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The quotes are a bit off here and below, also we could use [...] since it's Rust docs, right?

Suggested change
/// If successful, returns the merged `PauliProductRotation.
/// If successful, returns the merged [PauliProductRotation].

Comment thread crates/circuit/src/operations.rs Outdated
Comment on lines +3391 to +3392
/// For a `PauliProductRotation`` gate with a floating-point angle return a tuple ``(Tr(gate) / dim, dim)``.
/// Return `None` if the angle is parameterized.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// For a `PauliProductRotation`` gate with a floating-point angle return a tuple ``(Tr(gate) / dim, dim)``.
/// Return `None` if the angle is parameterized.
/// For a [PauliProductRotation] gate with a floating-point angle return a tuple `(Tr(gate) / dim, dim)`.
/// Return `None` if the angle is parameterized.


qc = QuantumCircuit(4)
qc.append(PauliProductRotationGate(Pauli("XXII"), -1), [0, 1, 2, 3])
qc.append(PauliProductRotationGate(Pauli("ZZIY"), 1), [0, 1, 2, 3])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you shuffle the indices here to ensure the merging is not dependent on the index order? E.g.

Suggested change
qc.append(PauliProductRotationGate(Pauli("ZZIY"), 1), [0, 1, 2, 3])
qc.append(PauliProductRotationGate(Pauli("ZZYI"), 1), [1, 0, 2, 3])

(assuming I got it right here lol)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nice catch, the current PR does not support the suggested merging yet, but I can add it by canonicalizing PauliProductRotations/PauliProductMeasurements to have their qubits sorted by index. But of course this will incur some overhead.

If we could assume that the qubits of all PPRs/PPMs in a circuit are sorted, then we could implement commutation checking very efficiently (see the follow-up PR #15815, especially the comment on other potential optimizations).

When we canonicalize gates inside the CommutativeOptimization pass, we only do it tentatively, which means that when a gate is not canceled or merged we use the original instance of the gate in the final circuit. Should we perhaps change this behavior to always canonicalize PPRs/PPMs as a side-effect of the CommutativeOptimization pass? Should we do it in a separate pass?

Having PPRs/PPMs sorted by index would improve performance when running CommutativeOptimizations multiple times in the optimization loop. What do you think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Update: the time for canonicalizing PauliProductRotations by sorting the qubits (and adjusting the Paulis) is negligible both for small- and large- support gates. So this is now implemented in bdbc70d.

@alexanderivrii alexanderivrii requested a review from Cryoris March 24, 2026 15:00
@ShellyGarion ShellyGarion added the fault tolerance related to fault tolerance compilation label Mar 26, 2026
Copy link
Copy Markdown
Collaborator

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

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

LGTM - to double check, does the commutation checker realize that PPMs commute even if their indices are scrambled?

@Cryoris Cryoris added this pull request to the merge queue Mar 30, 2026
@alexanderivrii
Copy link
Copy Markdown
Member Author

LGTM - to double check, does the commutation checker realize that PPMs commute even if their indices are scrambled?

yes!

Merged via the queue into Qiskit:main with commit 50cb9b1 Mar 30, 2026
27 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to Done in Qiskit 2.5 Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: Added Add an "Added" entry in the GitHub Release changelog. fault tolerance related to fault tolerance compilation mod: transpiler Issues and PRs related to Transpiler

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants