-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend CommutativeInverseCancellation
to cancel pairs of gates up-to-phase
#11248
Conversation
One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 7656730918Warning: This coverage report may be inaccurate.We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report.
💛 - Coveralls |
CommutativeInverseCancellation
to cancel pairs of gates up-to-phase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this is a much stronger comparison than just up to global phase: any two adjacent gates that implement the same operation can now be cancelled, whereas before we only cancelled them if they were the same type. It might be worth for the input argument to reflect that.
qiskit/transpiler/passes/optimization/commutative_inverse_cancellation.py
Outdated
Show resolved
Hide resolved
LGTM except I still think this does more than just ignoring global phase. If I define two custom adjacent gates who will cancel each other, this new PR will be able to cancel them -- no matter how these gates are called. This wasn't possible before, was it? If this is correct, how about renaming |
…utativity checker; docs improvements
Thanks @Cryoris, I did the renaming as per review comments and offline conversation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small comments, pretty much looks good to go!
qiskit/transpiler/passes/optimization/commutative_inverse_cancellation.py
Outdated
Show resolved
Hide resolved
qiskit/transpiler/passes/optimization/commutative_inverse_cancellation.py
Outdated
Show resolved
Hide resolved
qiskit/transpiler/passes/optimization/commutative_inverse_cancellation.py
Outdated
Show resolved
Hide resolved
qiskit/transpiler/passes/optimization/commutative_inverse_cancellation.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks for the adjustments!
Summary
Extending
CommutativeInverseCancellation
transpiler pass to cancel pairs of gates that are inverse up to a phase. Updates the global phase of the circuit accordingly.Here is a small example:
The pass is able to cancel the
RZ
andP
gates, adjusting the global phase of the circuit to15 \pi / 8
.Details:
The pass has two new arguments
max_qubits
andupto_phase_optimization
. The new optimization is enabled by settingupto_phase_optimization = True
. Generally this leads to more reductions at the expense of increased runtime. Internally, the check is based on constructing and comparing unitary matrices corresponding to various gates in the circuit. The argumentmax_qubits
limits the number of qubits in matrix-based commutativity and inverse checks.