Skip to content

Fixed commutation checking between two Pauli product measurements (backport #16023)#16040

Merged
alexanderivrii merged 3 commits intostable/2.4from
mergify/bp/stable/2.4/pr-16023
Apr 15, 2026
Merged

Fixed commutation checking between two Pauli product measurements (backport #16023)#16040
alexanderivrii merged 3 commits intostable/2.4from
mergify/bp/stable/2.4/pr-16023

Conversation

@mergify
Copy link
Copy Markdown
Contributor

@mergify mergify Bot commented Apr 15, 2026

Summary

We have recently realized that checking commutativity between two PauliProductMeasurement instructions (introduced in #15359) is incorrect in the case that both measurements measure to the same classical bit. In this case, the later measurement overwrites the result of the earlier measurement, and thus the order of these instructions in the quantum circuit matters. This PR applies a simple fix of saying that two Pauli product measurement instruction do not commute unless they are completely identical (including pauli, qubits and clbits).

(Updated) This also handles "canonicalization": PPM(XZ, qubits=[0,1], clbits=[0]) is the same as PPM(ZX, qubits=[1,0], clbits=[0]), and so they are now also computed to commute.

Note: the current strategy of constructing sparse observable is in the spirit of the existing code, and I am trying to do minimal changes in order to backport a variant of this to 2.4. I have a followup PR #15815 that greatly increases the efficiency of commuting PPRs/PPMs among themselves (including canonicalization, but temporarily having the same problems as being fixed here).

This also updates commutativity checking tests to pass clbits when checking commutativity between two PPMs.

One other question: do we want to backport the fix to 2.4? If so, we would need to adjust this PR to the commutation checker version before #15488.

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:

This is an automatic backport of pull request #16023 done by [Mergify](https://mergify.com).

…6023)

* Fix commutation checking between two PPMs

* fix for the case qubits are different

* additional fixes and improvements following the review

* improve test formatting

* formatting (again)

(cherry picked from commit 89ff976)

# Conflicts:
#	crates/transpiler/src/commutation_checker.rs
#	test/python/circuit/test_commutation_checker.py
@mergify mergify Bot added the conflicts used by mergify when there are conflicts in a port label Apr 15, 2026
@mergify mergify Bot requested a review from a team as a code owner April 15, 2026 10:36
@mergify mergify Bot added the conflicts used by mergify when there are conflicts in a port label Apr 15, 2026
@mergify
Copy link
Copy Markdown
Contributor Author

mergify Bot commented Apr 15, 2026

Cherry-pick of 89ff976 has failed:

On branch mergify/bp/stable/2.4/pr-16023
Your branch is up to date with 'origin/stable/2.4'.

You are currently cherry-picking commit 89ff976e0.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   releasenotes/notes/fix-ppm-commutation-ddcde0bf8b20a9f8.yaml

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   crates/transpiler/src/commutation_checker.rs
	both modified:   test/python/circuit/test_commutation_checker.py

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@qiskit-bot
Copy link
Copy Markdown
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

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

  • @Qiskit/terra-core

@github-actions github-actions Bot added this to the 2.4.0 milestone Apr 15, 2026
@github-actions github-actions Bot added the Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog. label Apr 15, 2026
@coveralls
Copy link
Copy Markdown

Coverage Report for CI Build 24451488591

Coverage increased (+0.01%) to 87.606%

Details

  • Coverage increased (+0.01%) from the base build.
  • Patch coverage: 19 of 19 lines across 1 file are fully covered (100%).
  • 11 coverage regressions across 3 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

11 previously-covered lines in 3 files lost coverage.

File Lines Losing Coverage Coverage
crates/qasm2/src/parse.rs 6 97.15%
crates/qasm2/src/lex.rs 4 91.26%
crates/qasm2/src/expr.rs 1 93.82%

Coverage Stats

Coverage Status
Relevant Lines: 118834
Covered Lines: 104106
Line Coverage: 87.61%
Coverage Strength: 1011381.81 hits per line

💛 - Coveralls

@Cryoris Cryoris added this pull request to the merge queue Apr 15, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 15, 2026
@alexanderivrii alexanderivrii added this pull request to the merge queue Apr 15, 2026
Merged via the queue into stable/2.4 with commit 1736ae3 Apr 15, 2026
26 checks passed
@alexanderivrii alexanderivrii deleted the mergify/bp/stable/2.4/pr-16023 branch April 15, 2026 14:15
@github-project-automation github-project-automation Bot moved this from Ready to Done in Qiskit 2.4 Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog. conflicts used by mergify when there are conflicts in a port

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants