This is almost done but requires some discussion around how to handle global phases. The Python implementation of CommutativeCancellation sets the global phase of the DAGCircuit depending on the cancelled commutations without considering the previous global phase of the DAGCircuit:
I think this line should instead be:
dag.global_phase += total_phase - new_op_phase
I changed the tests accordingly in this PR. This PR depends on #12995 and #12870.
The following is still missing:
[x] Replace the Python class CommutativeCancellation with this Rust implementation everywhere (and run thorough tests)
[ ] test_callback_with_pass_requires now fails because CommutativeCancellation does not run the CommutationAnalysis through the pass manager anymore (instead there are internal Rust calls).
[ ] Apart from this, only tests with control flow operations fail
[ ] Process circuits with control flow operations correctly
[x] Discuss how to handle global phase
[ ] Discuss whether we wanted to extend the pass to work better on circuits with an arbitary basis gate set. Currently, we are quite restrictive in what we analyse and what we cancel, e.g. we consider t gates but no tdg gates. More importantly we only support a subset of two-qubit gates and no gates with a larger number of qubits. This might have quite an impact in some situations especially considering we are performing this pass before routing...
Summary
fixes #12270
Details and comments
This is almost done but requires some discussion around how to handle global phases. The Python implementation of
CommutativeCancellation
sets the global phase of theDAGCircuit
depending on the cancelled commutations without considering the previous global phase of theDAGCircuit
:https://github.com/Qiskit/qiskit/blob/f4ca088644b4461b856b4b49c33e23b04a995019/qiskit/transpiler/passes/optimization/commutative_cancellation.py#L195
I think this line should instead be:
dag.global_phase += total_phase - new_op_phase
I changed the tests accordingly in this PR. This PR depends on #12995 and #12870.The following is still missing:
CommutativeCancellation
with this Rust implementation everywhere (and run thorough tests)test_callback_with_pass_requires
now fails becauseCommutativeCancellation
does not run theCommutationAnalysis
through the pass manager anymore (instead there are internal Rust calls).t
gates but notdg
gates. More importantly we only support a subset of two-qubit gates and no gates with a larger number of qubits. This might have quite an impact in some situations especially considering we are performing this pass before routing...