Skip to content

Support commutation check between Pauli-based gates and standard gates (After reverting #15488)#15925

Merged
alexanderivrii merged 62 commits intoQiskit:mainfrom
debasmita2102:lightcone-fix
Apr 2, 2026
Merged

Support commutation check between Pauli-based gates and standard gates (After reverting #15488)#15925
alexanderivrii merged 62 commits intoQiskit:mainfrom
debasmita2102:lightcone-fix

Conversation

@debasmita2102
Copy link
Copy Markdown
Contributor

Summary

Details and comments

AI Attribution : Portions of the test_clifford_gates_have_generators , test_lightcone.py, and standard_geenrators.rs are developed with assistance from GitHub Copilot integrated in VS Code. The underlying model : Claude Haiku 4.5.

@debasmita2102 debasmita2102 requested a review from a team as a code owner March 31, 2026 16:49
@qiskit-bot
Copy link
Copy Markdown
Collaborator

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

  • @Qiskit/terra-core

debasmita2102 and others added 28 commits March 31, 2026 22:34
This PR adds exact Pauli generator expansions for the following gates:
- single-qubit: H (X+Z)
- 2-qubit: CX, CY, CZ, ECR, Swap, iSwap, CSX, CS, CSdg
- parametric: CRX, CRY, CRZ, CPhase, RXX, RYY, RZZ, RZX, XXPlusYY, XXMinusYY
- 3-qubit: CCX, CSwap

This enables high-performance bitwise commutation checks in the LightCone
pass, avoiding slow matrix-multiplication fallbacks. Parametric gates are
scaled dynamically in Rust using the input parameters.

Co-authored-by: Shelly Garion <shelly.garion@ibm.com>
Co-authored-by: Alexander Ivrii <alexander.ivrii@ibm.com>
Following feedback from Alexander Ivrii, this commit exposes the Rust
generator_observable function and the StandardGate enum to Python under
the qiskit._accelerate.standard_generators submodule.

This allows developers to verify the mathematical generators directly from
Python and reuse the logic for other purposes like PauliEvolutionGate
verification. The Rust-internal API is maintained via a dedicated
generator_observable function that accepts slices.
Comment thread crates/transpiler/src/commutation_checker.rs Outdated
@Cryoris Cryoris self-assigned this Apr 1, 2026
Cryoris added 2 commits April 1, 2026 13:59
- Test all standard gate matrices
- Enable the existing LightCone pass instead of adding a new one
- Removed LLM-supported tests in commutation checker in favor of human-only ones
- Rename to standard gate exponent
- Simplify match statements
- Rm duplicate function definitions and complex number crate
- Use local consts over pub consts
- Reword reno
Comment thread crates/transpiler/src/commutation_checker.rs Outdated
Comment thread crates/transpiler/src/commutation_checker.rs
Copy link
Copy Markdown
Member

@alexanderivrii alexanderivrii left a comment

Choose a reason for hiding this comment

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

Thanks Julien and Debasmita for further improvements. Overall this looks ok to me now, but I had a few comments and suggestions.

Comment thread crates/circuit/src/standard_gate/standard_generators.rs
Comment thread crates/quantum_info/src/standard_generators.rs Outdated
Comment thread crates/quantum_info/src/standard_generators.rs Outdated
Comment thread crates/quantum_info/src/standard_generators.rs Outdated
Comment thread crates/quantum_info/src/standard_generators.rs Outdated
vec![0, 1, 0, 1],
vec![0, 2, 4],
),
_ => unreachable!(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this line really unreachable? Otherwise, it would panic for parametric beta.

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.

It's unreachable: we first match on XXPlusYY | XXMinusYY so we know the only two cases are these two

Comment thread releasenotes/notes/pauli-evolution-commutation-8f7caab8.yaml Outdated
)
@unpack
def test_unsupported_gates_commute_fallback(self, gate1, q1, gate2, q2, expected):
"""Verify that gates without Rust generators still commute correctly via matrix fallback."""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you please comment which of the gates do not have generators?

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.

Well all gates that don't have generators should be covered in the test (XX+YY with beta nonzero is actually not yet tested). I would prefer just having all there instead of listing them in a comment that is prone to get out of date

Comment thread test/python/circuit/test_commutation_checker.py Outdated
Comment thread test/python/circuit/test_commutation_checker.py
Cryoris added 2 commits April 2, 2026 11:16
- reword exponent docs
- cleanup CC tests
- typos

And rm LightCone runtime warning which no longer applies
Comment on lines -121 to +113
commute_bool = scc.commute(
op[0], op[1], [], node.op, node.qargs, [], max_num_qubits=max_num_qubits
)
commute_bool = scc.commute(op[0], op[1], [], node.op, node.qargs, [])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed, we should not limit max_num_qubits anymore and remove the warning above. The matrix_max_num_qubits didn't change, correct? - it's still defaulted to 3 if I remember correctly.

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.

That's right, and that should remain since we don't want to have the matrix checks enabled per default

Comment thread test/python/circuit/test_commutation_checker.py Outdated
Copy link
Copy Markdown
Member

@alexanderivrii alexanderivrii left a comment

Choose a reason for hiding this comment

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

Thanks Debasmita and Julien for finalizing this PR! It looks good to me now (including properly attributing LLM usage).

@alexanderivrii alexanderivrii added this pull request to the merge queue Apr 2, 2026
Merged via the queue into Qiskit:main with commit 09bcf15 Apr 2, 2026
26 checks passed
@ShellyGarion ShellyGarion added Changelog: Added Add an "Added" entry in the GitHub Release changelog. Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog. labels Apr 25, 2026
@github-project-automation github-project-automation Bot moved this from Ready to Done in Qiskit 2.5 Apr 25, 2026
@ShellyGarion ShellyGarion added this to the 2.5.0 milestone Apr 25, 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. Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

LightCone pass gives index errors unexpectedly

5 participants