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
6 changes: 3 additions & 3 deletions cirq-core/cirq/ops/pauli_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __init__(self):
common_gates.XPowGate.__init__(self, exponent=1.0)

def __pow__(self: '_PauliX', exponent: 'cirq.TParamVal') -> common_gates.XPowGate:
return common_gates.XPowGate(exponent=exponent)
return common_gates.XPowGate(exponent=exponent) if exponent != 1 else self
bichengying marked this conversation as resolved.
Show resolved Hide resolved

def _with_exponent(self: '_PauliX', exponent: 'cirq.TParamVal') -> common_gates.XPowGate:
return self.__pow__(exponent)
Expand All @@ -135,7 +135,7 @@ def __init__(self):
common_gates.YPowGate.__init__(self, exponent=1.0)

def __pow__(self: '_PauliY', exponent: 'cirq.TParamVal') -> common_gates.YPowGate:
return common_gates.YPowGate(exponent=exponent)
return common_gates.YPowGate(exponent=exponent) if exponent != 1 else self
bichengying marked this conversation as resolved.
Show resolved Hide resolved

def _with_exponent(self: '_PauliY', exponent: 'cirq.TParamVal') -> common_gates.YPowGate:
return self.__pow__(exponent)
Expand All @@ -162,7 +162,7 @@ def __init__(self):
common_gates.ZPowGate.__init__(self, exponent=1.0)

def __pow__(self: '_PauliZ', exponent: 'cirq.TParamVal') -> common_gates.ZPowGate:
return common_gates.ZPowGate(exponent=exponent)
return common_gates.ZPowGate(exponent=exponent) if exponent != 1 else self
bichengying marked this conversation as resolved.
Show resolved Hide resolved

def _with_exponent(self: '_PauliZ', exponent: 'cirq.TParamVal') -> common_gates.ZPowGate:
return self.__pow__(exponent)
Expand Down
4 changes: 4 additions & 0 deletions cirq-core/cirq/ops/pauli_gates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,7 @@ def test_powers():
assert isinstance(cirq.X ** -0.5, cirq.XPowGate)
assert isinstance(cirq.Y ** 0.2, cirq.YPowGate)
assert isinstance(cirq.Z ** 0.5, cirq.ZPowGate)

assert isinstance(cirq.X ** 1, cirq.Pauli)
assert isinstance(cirq.Y ** 1, cirq.Pauli)
assert isinstance(cirq.Z ** 1, cirq.Pauli)