Skip to content
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

Merged
merged 9 commits into from Jul 20, 2021

Conversation

bichengying
Copy link
Collaborator

Fix #4328

@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Jul 17, 2021
@bichengying bichengying changed the title Make sure (cirq.X, cirq.Y, cirq.Z)**1 should be _Pauli{X,Y,Z} instead of {X,Y,Z}PowGate Make (cirq.X, cirq.Y, cirq.Z)**1 returned type as _Pauli{X,Y,Z} instead of {X,Y,Z}PowGate Jul 17, 2021
@bichengying bichengying marked this pull request as ready for review July 17, 2021 04:51
@bichengying bichengying requested review from cduck, vtomole and a team as code owners July 17, 2021 04:51
Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a 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.

cirq-core/cirq/ops/pauli_gates.py Outdated Show resolved Hide resolved
cirq-core/cirq/ops/pauli_gates.py Outdated Show resolved Hide resolved
cirq-core/cirq/ops/pauli_gates.py Outdated Show resolved Hide resolved
@bichengying
Copy link
Collaborator Author

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.

Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MichaelBroughton MichaelBroughton added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Jul 20, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Jul 20, 2021
@CirqBot CirqBot merged commit b92f379 into quantumlib:master Jul 20, 2021
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Jul 20, 2021
@bichengying bichengying deleted the fix_pauli_pow branch August 13, 2021 06:19
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cirq.X**1 should be _PauliX instead of XPowGate
3 participants