Skip to content

Commit abe917f

Browse files
authored
Make (cirq.X, cirq.Y, cirq.Z)**1 returned type as _Pauli{X,Y,Z} instead of {X,Y,Z}PowGate (quantumlib#4330)
Fix quantumlib#4328
1 parent 014c289 commit abe917f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

cirq/ops/pauli_gates.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def __init__(self):
108108
common_gates.XPowGate.__init__(self, exponent=1.0)
109109

110110
def __pow__(self: '_PauliX', exponent: 'cirq.TParamVal') -> common_gates.XPowGate:
111-
return common_gates.XPowGate(exponent=exponent)
111+
return common_gates.XPowGate(exponent=exponent) if exponent != 1 else _PauliX()
112112

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

137137
def __pow__(self: '_PauliY', exponent: 'cirq.TParamVal') -> common_gates.YPowGate:
138-
return common_gates.YPowGate(exponent=exponent)
138+
return common_gates.YPowGate(exponent=exponent) if exponent != 1 else _PauliY()
139139

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

164164
def __pow__(self: '_PauliZ', exponent: 'cirq.TParamVal') -> common_gates.ZPowGate:
165-
return common_gates.ZPowGate(exponent=exponent)
165+
return common_gates.ZPowGate(exponent=exponent) if exponent != 1 else _PauliZ()
166166

167167
def _with_exponent(self: '_PauliZ', exponent: 'cirq.TParamVal') -> common_gates.ZPowGate:
168168
return self.__pow__(exponent)

cirq/ops/pauli_gates_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,7 @@ def test_powers():
216216
assert isinstance(cirq.X ** -0.5, cirq.XPowGate)
217217
assert isinstance(cirq.Y ** 0.2, cirq.YPowGate)
218218
assert isinstance(cirq.Z ** 0.5, cirq.ZPowGate)
219+
220+
assert isinstance(cirq.X ** 1, cirq.Pauli)
221+
assert isinstance(cirq.Y ** 1, cirq.Pauli)
222+
assert isinstance(cirq.Z ** 1, cirq.Pauli)

0 commit comments

Comments
 (0)