Skip to content

Commit

Permalink
Build clifford tableau just once during SingleQubitCliffordGate to Ph…
Browse files Browse the repository at this point in the history
…asedXZGate conversion (#6325)
  • Loading branch information
NoureldinYosri authored Oct 25, 2023
1 parent ec84a05 commit 455f50b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions cirq-core/cirq/ops/clifford_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,33 +683,34 @@ def to_phased_xz_gate(self) -> phased_x_z_gate.PhasedXZGate:
flip_index = int(z_to_flip) * 2 + x_to_flip
a, x, z = 0.0, 0.0, 0.0

if np.array_equal(self.clifford_tableau.matrix(), [[1, 0], [0, 1]]):
matrix = self.clifford_tableau.matrix()
if np.array_equal(matrix, [[1, 0], [0, 1]]):
# I, Z, X, Y cases
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)]
a, x, z = to_phased_xz[flip_index]
elif np.array_equal(self.clifford_tableau.matrix(), [[1, 0], [1, 1]]):
elif np.array_equal(matrix, [[1, 0], [1, 1]]):
# +/- X_sqrt, 2 Hadamard-like gates acting on the YZ plane
a = 0.0
x = 0.5 if x_to_flip ^ z_to_flip else -0.5
z = 1.0 if x_to_flip else 0.0
elif np.array_equal(self.clifford_tableau.matrix(), [[0, 1], [1, 0]]):
elif np.array_equal(matrix, [[0, 1], [1, 0]]):
# +/- Y_sqrt, 2 Hadamard-like gates acting on the XZ plane
a = 0.5
x = 0.5 if x_to_flip else -0.5
z = 0.0 if x_to_flip ^ z_to_flip else 1.0
elif np.array_equal(self.clifford_tableau.matrix(), [[1, 1], [0, 1]]):
elif np.array_equal(matrix, [[1, 1], [0, 1]]):
# +/- Z_sqrt, 2 Hadamard-like gates acting on the XY plane
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)]
a, x, z = to_phased_xz[flip_index]
elif np.array_equal(self.clifford_tableau.matrix(), [[0, 1], [1, 1]]):
elif np.array_equal(matrix, [[0, 1], [1, 1]]):
# axis swapping rotation -- (312) permutation
a = 0.5
x = 0.5 if x_to_flip else -0.5
z = 0.5 if x_to_flip ^ z_to_flip else -0.5
else:
# axis swapping rotation -- (231) permutation.
# This should be the only cases left.
assert np.array_equal(self.clifford_tableau.matrix(), [[1, 1], [1, 0]])
assert np.array_equal(matrix, [[1, 1], [1, 0]])
a = 0.0
x = -0.5 if x_to_flip ^ z_to_flip else 0.5
z = -0.5 if x_to_flip else 0.5
Expand Down

0 comments on commit 455f50b

Please sign in to comment.