# Getting non-Clifford after performing several Clifford gates in qiskit

I'm trying to test Clifford gates in qiskit according to the table in Fault-tolerant SQ, page 101. I tried 4 Cliffords in the test $$-X/2 - X -X/2,Y/2,X/2 - -X/2,Y/2,-X/2$$

using the following code

import numpy as np
from qiskit import QuantumCircuit, Aer, execute
from qiskit.quantum_info import Operator

qc = QuantumCircuit(1)

qc.rx(-np.pi/2, 0)
qc.rx(np.pi, 0)
qc.rx(-np.pi/2, 0)
qc.ry(np.pi/2, 0)
qc.rx(np.pi/2, 0)

# 4th
qc.rx(-np.pi/2, 0)
qc.ry(np.pi/2, 0)
qc.rx(-np.pi/2, 0)

print('Final matrix:', Operator(qc).data)

qc.draw('mpl')


which gives me the output:

Final matrix: [[ 0.   +0.707j -0.707+0.j   ]
[ 0.707+0.j     0.   -0.707j]]


next, I found the inverse of this:

np.linalg.inv(Operator(qc).data)


which gives me:

[[ 0.   -0.707j  0.707+0.j   ]
[-0.707+0.j    -0.   +0.707j]]


and didn't find the corresponding Clifford in the table as I was expeccting.

What do I do wrong in my calculations in qiskit?

• What matrix did you find? Code is helpful, but you should show the output, too! Oct 6, 2021 at 16:13
• @jecado, sorry for this, I edited the post and added outputs. Oct 6, 2021 at 17:30
• Thank you! The table on p. 101 of your reference confuses me; isn't Z a Clifford gate? But it does not appear in the table. Oct 6, 2021 at 17:52
• @jecado, Z-gate is here, it is $$-X/2, Y/2, X/2$$ (actually, it is just Z/2) Oct 6, 2021 at 18:07

The matrix

$$M = \frac{1}{\sqrt{2}}\begin{bmatrix}-i & 1\\-1 & i\end{bmatrix}$$

resembles

$$X/2 = \frac{1}{\sqrt{2}}\begin{bmatrix}1 & -i\\-i & 1\end{bmatrix}\tag1$$

where we follow the notation $$\pm X/2$$ for the $$\pm\frac{\pi}{2}$$ rotation around the $$X$$ axis as used in the table B.6 on page 101 in Julian Kelly's PhD thesis. We can make the similarity more apparent by multiplying $$M$$ by the imaginary unit. We get

$$M\equiv iM = \frac{1}{\sqrt{2}}\begin{bmatrix}1 & i\\-i & -1\end{bmatrix}\tag2$$

where $$\equiv$$ signifies equality up to global phase.

Comparing $$(1)$$ and $$(2)$$, we see that up to global phase $$M$$ differs from $$X/2$$ only by the relative phase of $$\pi$$ between the two columns. We can introduce this phase difference using right-multiplication by $$Z$$. We have

\begin{align} M &\equiv (X/2) Z \\ M &\equiv (X/2) XY \\ M &\equiv (-X/2) Y \\ M &\equiv Y (X/2) \end{align}

where we used the identity $$(X/2)X\equiv(-X/2)$$ which follows from $$X^2=I$$ and $$(-X/2)Y=Y(X/2)$$ which follows from the fact that $$X$$ and $$Y$$ anti-commute.

Finally, we find $$M\equiv Y(X/2)$$ in the third row of the "Hadamard-like" section of the table B.6 and conclude that $$M$$ is a Clifford gate as expected.

• $$Y(X/2)=\begin{bmatrix}&-i\\i&\end{bmatrix} \frac{1}{\sqrt{2}} \begin{bmatrix}1&-i\\-i&1\end{bmatrix}=\frac{1}{\sqrt{2}}\begin{bmatrix}-1&-i\\ i&1\end{bmatrix}=-iM\equiv M$$ where we ignore the unobservable global phase $-i$. Similarly, $Z=-iXY\equiv XY$. Oct 7, 2021 at 17:05
• Regarding a mathematical technique: Instead of comparing $M$ against a list, you can instead verify that conjugation by $M$ maps the Pauli group to the Pauli group. This is a little less daunting than it sounds because you only need to examine the action on the generators. In particular, in the single-qubit case, you can compute $MXM^\dagger$ and $MZM^\dagger$ and verify that the two results together with $i=MiM^\dagger$ generate the Pauli group. Oct 7, 2021 at 17:12
• 1) I could have used $RY$ (with angle $\pi$) for $Y$, just as I used $RX$ (with angle $\frac{\pi}{2}$) for $X$. They're the same up to global phase. Specifically, $RY(\pi)=\begin{bmatrix}&-1\\ 1&\end{bmatrix}$. 2) In linear algebra, when you apply $AB$ to a vector you first apply $B$ and then $A$. In quantum circuits, you first write the gate corresponding to $B$ and then the one corresponding $A$, i.e. the convention is opposite. In software packages for describing quantum circuits the latter convention is more common. Oct 7, 2021 at 20:42
• You can do either: you can check that $M$ preserves the Pauli group under conjugation or you can compare $M$ against a full list of Cliffords (remembering to ignore the global phase). It is up to you, but note that the number of Cliffords grows quickly with the number of qubits. Oct 7, 2021 at 20:47
• On second look, I think the table B.6 may be using the convention where gates are applied from left to right like in quantum circuits and not from right to left like in linear algebra. This is suggested by the heading which says the Cliffords are "written in terms of the physical microwave gates applied in time". If this is the case, then $M$ is in the fourth (rather than the third) row of the Hadamard-like section, as is clear from the calculations in my answer. Oct 8, 2021 at 16:22