-
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
Do not unroll gates in basis in add_control
#13475
base: main
Are you sure you want to change the base?
Conversation
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 11962255098Details
💛 - Coveralls |
if operation.name in basis: | ||
apply_basic_controlled_gate(controlled_circ, operation, q_control, q_target[0]) | ||
|
||
# TODO: double check if this is necessary |
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.
Is this todo completed? if not, how could we check if this is necessary?
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.
Not yet: I was wondering whether this was necessary because here we don't decompose the gate which we want to control and shouldn't be able to accumulate any global phase. I left it for the first version since the previous code had it, but I'll try removing and see if everything passes 🙂
|
||
print(self.ugu1) | ||
print(cgate) |
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.
sneaky prints!
print(self.ugu1) | |
print(cgate) |
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.
heh classic -- sorry about this one, I think I should add a pre-commit hook to check for these 😂
@@ -1577,7 +1581,7 @@ def test_single_controlled_rotation_gates(self, gate, cgate): | |||
elif gate.name == "rz": | |||
self.assertLessEqual(uqc.size(), 43, f"\n{uqc}") | |||
else: | |||
self.assertLessEqual(uqc.size(), 20, f"\n{uqc}") | |||
self.assertLessEqual(uqc.size(), 23, f"\n{uqc}") |
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.
Why does the size increase in this test? shouldn't the decomposition be more efficient? (I admit I haven't looked in depth so I might be missing something)
Summary
The
add_control
mechanism currently does some redundant unrolling and re-wrapping of gates that are already in the basis of gates we know how to control. This has knock-on effects and causes #13473, by translating an RZ operation (already supported) to a Phase gate.This PR avoids this unrolling. As discussed with @alexanderivrii, in the longer term we should consider rewriting this logic entirely and have a controlled gate plugin, which also allows users to supply their own control mechanism.
Details and comments
U(0,0,0)
gates.