Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BichengYing committed Jul 17, 2021
1 parent 3dbc1c3 commit 213668c
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
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

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

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

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)

0 comments on commit 213668c

Please sign in to comment.