-
Notifications
You must be signed in to change notification settings - Fork 72
Controlled GlobalPhase is ZGate #1113
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
Conversation
exponent: float = np.real_if_close(np.log(self.coefficient) / (np.pi * 1.0j)).item() # type: ignore | ||
bloq = ZPowGate(exponent=exponent, eps=self.eps) |
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.
Please handle the case when self.coefficient
is symbolic
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.
Should we also have an override where we return a ZGate
instead of ZPowGate
if exponent
is 1
?
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.
That's a good question, and I think it's part of a broader issue. How do we handle cases where you can express the same "thing" (unitary) via different bloq+attribute combinations? I think the answer is to keep things as non-magical as possible when constructing bloqs and handle overlap in the bloq analysis functions. Happy to discuss more.
For this PR in particular: since ZPowGate(exponent=1)
is a valid bloq, I'll leave as-is.
I'll handle symbolic coefficient
return super().get_ctrl_system(ctrl_spec=ctrl_spec) | ||
|
||
# Otherwise, it's a ZPowGate | ||
exponent: float = np.real_if_close(np.log(self.coefficient) / (np.pi * 1.0j)).item() # type: ignore |
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 wouldn't work when self.coefficient
is symbolic. Maybe we should update this to self.exponent
to match the other rotation gates?
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.
Did you want to change the semantics to just store the exponent directly as the attribute or just change the name?
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.
the former, then we can safely pass self.exponent
to ZPowGate
. But would require updating all call sites. Based on a preliminary scan, most of them are 1j, -1j, -1
and would simplify SU2:
bb.add(GlobalPhase(coefficient=-exp(1j * self.global_shift), eps=self.eps / 4)) |
I'm happy to take this PR if you'd like.
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.
please :)
can be closed: this change was merged #1117 |
Thank you! |
The single-bit control of a global phase is
ZGate
.More basic gates #1109