-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Make (cirq.X, cirq.Y, cirq.Z)**1 returned type as _Pauli{X,Y,Z} instead of {X,Y,Z}PowGate #4330
Conversation
This reverts commit b2d9269.
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.
In the __pow__
method there is a contract to return an instance of XPowGate
. When returning self
, you return a reference to an XPowGate
and not a new object. That means with your code I could do:
assert cirq.X.global_shift == 0.0
a = [cirq.X**1.0, cirq.X**3.0]
a[0]._global_shift = 1.0
assert cirq.X.global_shift == 1.0
assert a[1].global_shift == 0.0
Which isn't great. I think modifying the code so that you are returning new instances in both cases would fix this.
Yeah, that is a good point. Totally agreed that _pow should return a new instance. |
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
…ad of {X,Y,Z}PowGate (quantumlib#4330) Fix quantumlib#4328
…ad of {X,Y,Z}PowGate (quantumlib#4330) Fix quantumlib#4328
Fix #4328