Extend RemoveIdentityEquivalent and CommutativeOptimization with PauliProductRotations#15810
Conversation
|
One or more of the following people are relevant to this code:
|
| } | ||
|
|
||
| /// Attempts to merge `self` and `other`. | ||
| /// If successful, returns the merged `PauliProductRotation. |
There was a problem hiding this comment.
The quotes are a bit off here and below, also we could use [...] since it's Rust docs, right?
| /// If successful, returns the merged `PauliProductRotation. | |
| /// If successful, returns the merged [PauliProductRotation]. |
| /// For a `PauliProductRotation`` gate with a floating-point angle return a tuple ``(Tr(gate) / dim, dim)``. | ||
| /// Return `None` if the angle is parameterized. |
There was a problem hiding this comment.
| /// 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]) |
There was a problem hiding this comment.
Could you shuffle the indices here to ensure the merging is not dependent on the index order? E.g.
| 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)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Cryoris
left a comment
There was a problem hiding this comment.
LGTM - to double check, does the commutation checker realize that PPMs commute even if their indices are scrambled?
yes! |
Summary
This PR extends the passes
RemoveIdentityEquivalentandCommutativeOptimizationto handlePauliProductRotations.Details and comments
Based on top of the bug-fix PR #15809.