Skip to content

Add additional Z and X rotation gate handling to CommutativeCancellation#16191

Open
mtreinish wants to merge 6 commits into
Qiskit:mainfrom
mtreinish:extra-gates-commutative-cancellation
Open

Add additional Z and X rotation gate handling to CommutativeCancellation#16191
mtreinish wants to merge 6 commits into
Qiskit:mainfrom
mtreinish:extra-gates-commutative-cancellation

Conversation

@mtreinish
Copy link
Copy Markdown
Member

This commit expands the the handling of Z and X rotations to the
commutative cancellation pass to cover missing gates that it could
easily handle. In addition for the output rotation gates special
handling is added for x and sx gates since we can easily emit those
gates if appropriate when the x rotation angle aligns with using those
gates.

AI/LLM disclosure

  • I didn't use LLM tooling, or only used it privately.
  • I used the following tool to help write this PR description:
  • I used the following tool to generate or modify code:

mtreinish and others added 2 commits May 15, 2026 12:58
This commit expands the the handling of Z and X rotations to the
commutative cancellation pass to cover missing gates that it could
easily handle. In addition for the output rotation gates special
handling is added for x and sx gates since we can easily emit those
gates if appropriate when the x rotation angle aligns with using those
gates.
Co-authored-by: Julien Gacon <gaconju@gmail.com>
@mtreinish mtreinish added this to the 2.5.0 milestone May 15, 2026
@mtreinish mtreinish requested a review from a team as a code owner May 15, 2026 17:11
@mtreinish mtreinish requested a review from Cryoris May 15, 2026 17:11
@qiskit-bot
Copy link
Copy Markdown
Collaborator

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

  • @Qiskit/terra-core

@coveralls
Copy link
Copy Markdown

coveralls commented May 15, 2026

Coverage Report for CI Build 26666113959

Coverage increased (+0.01%) to 87.567%

Details

  • Coverage increased (+0.01%) from the base build.
  • Patch coverage: 1 uncovered change across 1 file (51 of 52 lines covered, 98.08%).
  • 7 coverage regressions across 3 files.

Uncovered Changes

File Changed Covered %
crates/transpiler/src/passes/commutation_cancellation.rs 52 51 98.08%

Coverage Regressions

7 previously-covered lines in 3 files lost coverage.

File Lines Losing Coverage Coverage
crates/qasm2/src/lex.rs 5 91.52%
crates/circuit/src/parameter/symbol_expr.rs 1 73.97%
crates/transpiler/src/passes/commutation_cancellation.rs 1 92.63%

Coverage Stats

Coverage Status
Relevant Lines: 123963
Covered Lines: 108551
Line Coverage: 87.57%
Coverage Strength: 967384.66 hits per line

💛 - Coveralls

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.

The logic LGTM, could you add some tests that emit circuits with the newly added X basis gates -- plus a reno?

Also in an offline discussion we noticed that commutative cancellation does not use the average gate fidelity as metric, even though it also removes identity-equivalent gates. Since that was pre-existing and this PR is adding support for additional gates in the existing framework, the gate fidelity fix should be in a follow up though.

mtreinish added 4 commits May 29, 2026 15:52
This commit adds test coverage for the pass emitting X and SX gates. The
global phase handling for this was incorrect because it was not
correctly accounting for the phase difference between X/SX and RX. This
would lead to the phase being tracked incorrectly because for the
internal pass tracking it's all in terms of RX gates. So if the circuit
was in terms of RX gates added and we emitted an X we'd be off because
we didn't correct for the phase difference in the output circuit. This
was also a problem if the circuit was in terms of X gates and we emit an
X gate we had added the phase difference for the RX tracking but then we
emitted the X gate and didn't need the phase correction. To address this
we need to track the circuit gates and then on the output handle the
correction according to the gate we're emitting. This is different from
how Z angles are tracked because unlike the Z rotation gates, the other
options for X gates are only for discrete angles. We would need similar
handling if Z rotations could emit a Z gate but we don't support that
currently so it's not an issue.
@mtreinish mtreinish requested a review from Cryoris May 29, 2026 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready

Development

Successfully merging this pull request may close these issues.

4 participants