Skip to content

Commit

Permalink
Make (cirq.X, cirq.Y, cirq.Z)**1 returned type as _Pauli{X,Y,Z} inste…
Browse files Browse the repository at this point in the history
…ad of {X,Y,Z}PowGate (#4330)

Fix #4328
  • Loading branch information
bichengying committed Jul 20, 2021
1 parent dc01372 commit b92f379
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cirq-core/cirq/ops/pauli_gates.py
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 _PauliX()

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 _PauliY()

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 _PauliZ()

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
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)

0 comments on commit b92f379

Please sign in to comment.