From b92f379ff80abd43fd1069b8a88a0bbeecf62a36 Mon Sep 17 00:00:00 2001 From: Bicheng Ying Date: Tue, 20 Jul 2021 09:36:26 -0700 Subject: [PATCH] Make (cirq.X, cirq.Y, cirq.Z)**1 returned type as _Pauli{X,Y,Z} instead of {X,Y,Z}PowGate (#4330) Fix #4328 --- cirq-core/cirq/ops/pauli_gates.py | 6 +++--- cirq-core/cirq/ops/pauli_gates_test.py | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cirq-core/cirq/ops/pauli_gates.py b/cirq-core/cirq/ops/pauli_gates.py index 85f3b881bca..4465697d2dc 100644 --- a/cirq-core/cirq/ops/pauli_gates.py +++ b/cirq-core/cirq/ops/pauli_gates.py @@ -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) @@ -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) @@ -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) diff --git a/cirq-core/cirq/ops/pauli_gates_test.py b/cirq-core/cirq/ops/pauli_gates_test.py index b4e375f41e0..81753b5f019 100644 --- a/cirq-core/cirq/ops/pauli_gates_test.py +++ b/cirq-core/cirq/ops/pauli_gates_test.py @@ -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)