diff --git a/cirq-core/cirq/ops/clifford_gate.py b/cirq-core/cirq/ops/clifford_gate.py index 92d6bc65c20..bf7b5ed752c 100644 --- a/cirq-core/cirq/ops/clifford_gate.py +++ b/cirq-core/cirq/ops/clifford_gate.py @@ -743,16 +743,21 @@ def _to_phased_xz_gate(self) -> phased_x_z_gate.PhasedXZGate: return phased_x_z_gate.PhasedXZGate(x_exponent=x, z_exponent=z, axis_phase_exponent=a) def __pow__(self, exponent: Union[float, int]) -> 'SingleQubitCliffordGate': - # First to check if we can get the sqrt and negative sqrt Clifford. - if self._get_sqrt_map().get(exponent, None): - pow_gate = self._get_sqrt_map()[exponent].get(self, None) + if int(exponent) == exponent: + # The single qubit Clifford gates are a group of size 24 + ret_gate = super().__pow__(int(exponent) % 24) + return SingleQubitCliffordGate.from_clifford_tableau(ret_gate.clifford_tableau) + elif int(2 * exponent) == 2 * exponent: + # If exponent = k/2 for integer k, then we compute the k-th power of the square root + if exponent < 0: + sqrt_exp = -0.5 + else: + sqrt_exp = 0.5 + pow_gate = self._get_sqrt_map()[sqrt_exp].get(self, None) if pow_gate: - return pow_gate - # If not, we try the Clifford Tableau based method. - ret_gate = super().__pow__(exponent) - if ret_gate is NotImplemented: - return NotImplemented - return SingleQubitCliffordGate.from_clifford_tableau(ret_gate.clifford_tableau) + return pow_gate ** (abs(2 * exponent)) + + return NotImplemented def _act_on_( self, diff --git a/cirq-core/cirq/ops/clifford_gate_test.py b/cirq-core/cirq/ops/clifford_gate_test.py index f3a86b1f321..db0542fee9c 100644 --- a/cirq-core/cirq/ops/clifford_gate_test.py +++ b/cirq-core/cirq/ops/clifford_gate_test.py @@ -219,6 +219,8 @@ def test_pow(): assert cirq.SingleQubitCliffordGate.Y_nsqrt == cirq.SingleQubitCliffordGate.Y**-0.5 assert cirq.SingleQubitCliffordGate.Z_nsqrt == cirq.SingleQubitCliffordGate.Z**-0.5 assert cirq.SingleQubitCliffordGate.X_sqrt**-1 == cirq.SingleQubitCliffordGate.X_nsqrt + assert cirq.SingleQubitCliffordGate.X_sqrt**3 == cirq.SingleQubitCliffordGate.X**1.5 + assert cirq.SingleQubitCliffordGate.Z**2.0 == cirq.SingleQubitCliffordGate.I assert cirq.inverse(cirq.SingleQubitCliffordGate.X_nsqrt) == ( cirq.SingleQubitCliffordGate.X_sqrt )