File tree Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -743,16 +743,21 @@ def _to_phased_xz_gate(self) -> phased_x_z_gate.PhasedXZGate:
743743 return phased_x_z_gate .PhasedXZGate (x_exponent = x , z_exponent = z , axis_phase_exponent = a )
744744
745745 def __pow__ (self , exponent : Union [float , int ]) -> 'SingleQubitCliffordGate' :
746- # First to check if we can get the sqrt and negative sqrt Clifford.
747- if self ._get_sqrt_map ().get (exponent , None ):
748- pow_gate = self ._get_sqrt_map ()[exponent ].get (self , None )
746+ if int (exponent ) == exponent :
747+ # The single qubit Clifford gates are a group of size 24
748+ ret_gate = super ().__pow__ (int (exponent ) % 24 )
749+ return SingleQubitCliffordGate .from_clifford_tableau (ret_gate .clifford_tableau )
750+ elif int (2 * exponent ) == 2 * exponent :
751+ # If exponent = k/2 for integer k, then we compute the k-th power of the square root
752+ if exponent < 0 :
753+ sqrt_exp = - 0.5
754+ else :
755+ sqrt_exp = 0.5
756+ pow_gate = self ._get_sqrt_map ()[sqrt_exp ].get (self , None )
749757 if pow_gate :
750- return pow_gate
751- # If not, we try the Clifford Tableau based method.
752- ret_gate = super ().__pow__ (exponent )
753- if ret_gate is NotImplemented :
754- return NotImplemented
755- return SingleQubitCliffordGate .from_clifford_tableau (ret_gate .clifford_tableau )
758+ return pow_gate ** (abs (2 * exponent ))
759+
760+ return NotImplemented
756761
757762 def _act_on_ (
758763 self ,
Original file line number Diff line number Diff line change @@ -219,6 +219,8 @@ def test_pow():
219219 assert cirq .SingleQubitCliffordGate .Y_nsqrt == cirq .SingleQubitCliffordGate .Y ** - 0.5
220220 assert cirq .SingleQubitCliffordGate .Z_nsqrt == cirq .SingleQubitCliffordGate .Z ** - 0.5
221221 assert cirq .SingleQubitCliffordGate .X_sqrt ** - 1 == cirq .SingleQubitCliffordGate .X_nsqrt
222+ assert cirq .SingleQubitCliffordGate .X_sqrt ** 3 == cirq .SingleQubitCliffordGate .X ** 1.5
223+ assert cirq .SingleQubitCliffordGate .Z ** 2.0 == cirq .SingleQubitCliffordGate .I
222224 assert cirq .inverse (cirq .SingleQubitCliffordGate .X_nsqrt ) == (
223225 cirq .SingleQubitCliffordGate .X_sqrt
224226 )
You can’t perform that action at this time.
0 commit comments