Skip to content

Commit e1c721c

Browse files
Build clifford tableau just once during SingleQubitCliffordGate to PhasedXZGate conversion (quantumlib#6325)
1 parent d081edc commit e1c721c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

cirq/ops/clifford_gate.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -683,33 +683,34 @@ def to_phased_xz_gate(self) -> phased_x_z_gate.PhasedXZGate:
683683
flip_index = int(z_to_flip) * 2 + x_to_flip
684684
a, x, z = 0.0, 0.0, 0.0
685685

686-
if np.array_equal(self.clifford_tableau.matrix(), [[1, 0], [0, 1]]):
686+
matrix = self.clifford_tableau.matrix()
687+
if np.array_equal(matrix, [[1, 0], [0, 1]]):
687688
# I, Z, X, Y cases
688689
to_phased_xz = [(0.0, 0.0, 0.0), (0.0, 0.0, 1.0), (0.0, 1.0, 0.0), (0.5, 1.0, 0.0)]
689690
a, x, z = to_phased_xz[flip_index]
690-
elif np.array_equal(self.clifford_tableau.matrix(), [[1, 0], [1, 1]]):
691+
elif np.array_equal(matrix, [[1, 0], [1, 1]]):
691692
# +/- X_sqrt, 2 Hadamard-like gates acting on the YZ plane
692693
a = 0.0
693694
x = 0.5 if x_to_flip ^ z_to_flip else -0.5
694695
z = 1.0 if x_to_flip else 0.0
695-
elif np.array_equal(self.clifford_tableau.matrix(), [[0, 1], [1, 0]]):
696+
elif np.array_equal(matrix, [[0, 1], [1, 0]]):
696697
# +/- Y_sqrt, 2 Hadamard-like gates acting on the XZ plane
697698
a = 0.5
698699
x = 0.5 if x_to_flip else -0.5
699700
z = 0.0 if x_to_flip ^ z_to_flip else 1.0
700-
elif np.array_equal(self.clifford_tableau.matrix(), [[1, 1], [0, 1]]):
701+
elif np.array_equal(matrix, [[1, 1], [0, 1]]):
701702
# +/- Z_sqrt, 2 Hadamard-like gates acting on the XY plane
702703
to_phased_xz = [(0.0, 0.0, 0.5), (0.0, 0.0, -0.5), (0.25, 1.0, 0.0), (-0.25, 1.0, 0.0)]
703704
a, x, z = to_phased_xz[flip_index]
704-
elif np.array_equal(self.clifford_tableau.matrix(), [[0, 1], [1, 1]]):
705+
elif np.array_equal(matrix, [[0, 1], [1, 1]]):
705706
# axis swapping rotation -- (312) permutation
706707
a = 0.5
707708
x = 0.5 if x_to_flip else -0.5
708709
z = 0.5 if x_to_flip ^ z_to_flip else -0.5
709710
else:
710711
# axis swapping rotation -- (231) permutation.
711712
# This should be the only cases left.
712-
assert np.array_equal(self.clifford_tableau.matrix(), [[1, 1], [1, 0]])
713+
assert np.array_equal(matrix, [[1, 1], [1, 0]])
713714
a = 0.0
714715
x = -0.5 if x_to_flip ^ z_to_flip else 0.5
715716
z = -0.5 if x_to_flip else 0.5

0 commit comments

Comments
 (0)