# Why should we measure in X/Z basis for Z/X errors in Steane syndrome extraction?

From the Steane syndrome extraction of quantum error correcting code, we use ancilla qubit prepared in logical X/Z basis to detect logical Z/X errors in the logical data state (The CNOT is transversal).

Every material tell me that it works because X errors will propogate to the left part of ancilla and Z errors will propogate to the right part. However, I'm confused how the measurement works. For example in the left part, even there is no error (Or applying a stabilizer), measuring logical + at Z basis will cause uncertain results, and X error just make thing more complex. Can somebody explain how the measure work and why it can get the syndrome? • Where did you get this circuit from? Apr 27 '20 at 7:41
• arxiv.org/abs/1605.05647v4, there is a lot of other similar cricuit if you search steane syndrome extraction Apr 27 '20 at 10:49

Let me start by clarifying that the aim is not to detect and correct logical errors, but to detect and correct physical errors, i.e. those that occur on single physical qubits rather than the encoded qubit.

At the macro level, the answer is that if you have an $$X$$ error (say), you use a controlled-not to propagate it to another qubit where it appears as an $$X$$ error. Measuring in the $$X$$ basis cannot see that error. For example, if a single qubit state was in $$|+\rangle$$, an $$X$$ error would not change it, and you would be unable to detect the error. On the other hand, if the qubit was initially in $$|0\rangle$$ then the possibility of a flip would put it in either $$|0\rangle$$ or $$|1\rangle$$, which can be detected with a $$Z$$ measurement. (Put another way, $$X$$ errors commute with $$X$$ measurements, so they do not affect each other.)

More specifically, let's start by thinking about what happens if there is no error. In that case, $$|+\rangle$$ is the eigenstate of controlled-not, so it never changes. This is what initially threw me trying to think about a $$Z$$ measurement on this. But of course, it's not logical $$Z$$ measurement, but physical. So, basically, you'll get a single answer corresponding to one of the basis states used in either to 0 or 1 logical state, with no control over which. Let's call that answer $$x$$. What we do know is that $$H\cdot x=0$$, where $$H$$ is the parity-check matrix of the code (I'm being a bit loose about which of the two it is).

Now, what happens if there was a single physical $$X$$ error somewhere on the logical qubit. Controlled-nots (and we should think about the individual physical ones here, not the logical ones) propagate $$X$$ rotations from control to target. So, instead of getting an answer $$x$$, we'd get an answer $$x\oplus e$$ where $$e$$ is a vector representing the single qubit that had the error. So, now, if you apply the parity-check matrix, you get $$H\cdot(x\oplus e)=(H\cdot x)\oplus(H\cdot e)=H\cdot e.$$ The whole point of the parity-check matrices is that they can let you identify any single-qubit $$e$$. Hence, you know what correction to provide.

I'd like to add some details to DaftWullie's answer. The key point is that while the logical $$X$$ operator, which I'll write as $$X_L$$, must, by definition, satisfy

$$X_L \left|+\right>_L = \left.|+\right>_L, \quad X_L \left|-\right>_L = -\left|-\right>_L$$

the analogous equation does not hold when $$X_L$$ is replaced with an $$X$$ operator acting on a single qubit. The $$\oplus$$ on the bottom wire in the diagram, connected to its control on the top wire, indicates a controlled $$X$$ operator on each qubit. (CNOT pairing up wires, not a logical $$X_L$$.) In general this combination of CNOTs does not leave $$\left|+\right>$$ invariant.

Preliminaries on CSS codes. For simplicity, we suppose that the input codeword, on the top 'wire' (inverted commas since this indicates multiple wires) in the diagram in the question is zero logical, $$\left|0\right>_L$$. For Steane extraction we are working in a CSS code with $$k$$ logical qubits: let $$P$$ and $$Q$$ be the relevant matrices so

$$\left|0\right>_L = \sum_{u \in \langle P \rangle} \left|u\right>$$

where $$\langle P \rangle$$ is the row-space of $$P$$, and, by a MacWilliams' type calculation,

$$\left|+\right>_L = \frac{1}{2^{m/2}} \sum_{v \in \langle Q^\perp \rangle} \left|v\right>$$

where $$m$$ is the dimension of $$\langle Q^\perp \rangle$$.

Example. In the Steane $$[[7,1,3]]$$ code, using the parity check matrix from the Wikipedia article we have $$P = Q = \left( \begin{matrix} 1 & 0 & 0 & 1 & 0 & 1 & 1 \\ 0 & 1 &0 & 1 & 1 & 0 & 1 \\ 0 & 0 & 1 & 0 & 1 & 1 & 1 \end{matrix} \right)$$ and $$\langle Q^\perp \rangle = \langle P \rangle \oplus \langle 1111111 \rangle$$, where $$\oplus$$ is the direct sum of vector spaces, so $$\left|0\right>_L = \sum_{u \in \langle P \rangle} \left|u\right>$$ and $$\left|+\right>_L = \frac{1}{\sqrt{2}} \sum_{u \in \langle P \rangle} \left|u\right> + \frac{1}{\sqrt{2}} \sum_{u \in \langle P \rangle} \left| u + 1111111\right> = \frac{1}{\sqrt{2}} \left|0\right>_L + \frac{1}{\sqrt{2}} \left|1\right>_L.$$ In general for an $$[[n,k,d]]$$ quantum code, $$\left|+\right>_L$$ is a sum of $$2^k$$ basis states in the $$Z$$-logical basis.

Diagrams. The diagram below shows the action of the CNOT pairing up each wire when the input qubit is a basis state in the $$Z$$-basis

|u> -------*---- |u>
|
|w> -------+---- |u+w>


Observe that flipping a bit in $$u$$ means that we get a corresponding bit flip in $$u+w$$. Thus we can deduce the second diagram below shows how a single qubit $$X$$ error, gets copied down' onto the ancilla.

 ---X---*------            ------*---X---
|           =            |
-------+------            ------+---X---
`

Calculation. We can now calculate the effect of a single qubit error, say in position $$1$$. On the input wires we have $$X^1 \left|0\right>_L$$ and $$\left|+\right>_L$$. On the output wires, by the second diagram, we have $$X^1 \left|0\right>_L$$ and

$$\frac{1}{2^{k/2}} \sum_{v \in \langle Q^\perp \rangle} X^1 \left|v\right>.$$

This expresses the output on the bottom 'wire' in the $$Z$$-basis. When we measure we get a random state $$X^1 \left| v \right>$$ where $$v \in \langle Q^\perp \rangle$$. This tells us $$\overline{v_1} v_2 \ldots v_n$$ where $$v_1 v_2 \ldots v_n$$ is a codeword in the code with generator matrix $$Q^\perp$$ and parity check matrix $$Q$$. We can now take the syndrome of this word and discover (provided this code is $$1$$-error correcting) that there was an error in the first position.

Example concluded. For the Steane [[7,4,1]]-code, we measure $$\overline{v_1}v_2 \ldots v_n$$ where $$v_1v_2\ldots v_n$$ is a codeword in the Hamming $$[7,4,3]$$-code with parity check matrix $$P$$. For instance, one codeword is $$1110001$$, so we might measure $$0110001$$. We now calculate the syndrome by left-multiplying the column vector by $$P$$, to get

$$\left( \begin{matrix} 1 & 0 & 0 & 1 & 0 & 1 & 1 \\ 0 & 1 &0 & 1 & 1 & 0 & 1 \\ 0 & 0 & 1 & 0 & 1 & 1 & 1 \end{matrix} \right) \left( \begin{matrix} 0 \\ 1 \\ 1 \\ 0 \\ 0 \\ 0 \\ 1 \end{matrix} \right) = \left( \begin{matrix} 1 \\ 0 \\ 0 \end{matrix} \right).$$

Since this is the first column of $$P$$, we conclude that there was an $$X$$ error in the first position.