Support commutation check between Pauli-based gates and standard gates (After reverting #15488)#15925
Conversation
|
One or more of the following people are relevant to this code:
|
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.
…timize gate generators
…or or matrix paths
- 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
alexanderivrii
left a comment
There was a problem hiding this comment.
Thanks Julien and Debasmita for further improvements. Overall this looks ok to me now, but I had a few comments and suggestions.
| vec![0, 1, 0, 1], | ||
| vec![0, 2, 4], | ||
| ), | ||
| _ => unreachable!(), |
There was a problem hiding this comment.
Is this line really unreachable? Otherwise, it would panic for parametric beta.
There was a problem hiding this comment.
It's unreachable: we first match on XXPlusYY | XXMinusYY so we know the only two cases are these two
| ) | ||
| @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.""" |
There was a problem hiding this comment.
Can you please comment which of the gates do not have generators?
There was a problem hiding this comment.
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
- reword exponent docs - cleanup CC tests - typos And rm LightCone runtime warning which no longer applies
| 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, []) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
That's right, and that should remain since we don't want to have the matrix checks enabled per default
alexanderivrii
left a comment
There was a problem hiding this comment.
Thanks Debasmita and Julien for finalizing this PR! It looks good to me now (including properly attributing LLM usage).
Summary
Details and comments
AI Attribution : Portions of the
test_clifford_gates_have_generators,test_lightcone.py, andstandard_geenrators.rsare developed with assistance from GitHub Copilot integrated in VS Code. The underlying model : Claude Haiku 4.5.