-
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
Merge u1, u2 and p gate together if they contain parameters. #7309
Conversation
Pull Request Test Coverage Report for Build 1592690401
💛 - Coveralls |
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.
Thanks for taking this on @rafal-pracht . This looks good so far, a few small comments below.
Co-authored-by: Kevin Krsulich <kevin@krsulich.net>
Thanks @kdk for your feedback, I've made changes. |
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.
This LGTM, thanks for the fast updates and sorry this has fallen through the cracks. The only thing missing here is a release note to document the new feature that the pass will work with unbound parameters on u1, u2, and p gates. You can see a guide on how to do this here: https://github.com/Qiskit/qiskit-terra/blob/main/CONTRIBUTING.md#release-notes once there's a release note here I think this is ready to merge
Closing this as the fork this PR was created from has been deleted so this PR is now effectively read only and we can't make modifications to the PR code anymore. This has been reopened from a new fork by the author at #7579 and we'll continue the review in that PR. |
Summary
Before the fix, the 'Optimize1qGates' transpiler optimization join together the gate only when the parameter was bounded (or when there was no parameter at all). After the fix, the u1, u2, and p gates will be combined even when the parameter is unbounded.
from qiskit import QuantumCircuit
from qiskit.circuit import Parameter
from qiskit.transpiler import PassManager
from qiskit.transpiler.passes import Optimize1qGates, Unroller
phi = Parameter('φ')
alpha = Parameter('α')
qc = QuantumCircuit(1)
qc.u1(2*phi, 0)
qc.u1(alpha, 0)
qc.u1(0.1, 0)
qc.u1(0.2, 0)
qc.draw(output='mpl')
pm = PassManager([Unroller(['u1', 'cx']), Optimize1qGates()])
nqc = pm.run(qc)
nqc.draw(output='mpl')
This change is a part of the advocate project done under @nbronn.