# How to interpret the circuit that measures stabilizers in the 5-qubit error correcting code

I would like to understand the exact role of the following circuit (By Vtomole - Own work, CC BY-SA 4.0) in the 5-qubit QECC.

The image attached (from Wikipedia) is captioned "Quantum Circuit that Measures Stabilizers in the Five Qubit Error Correcting Code".

Background According to Nielsen and Chuang, "the five qubit code has the generators $$g_{1} = XZZXI$$ $$g_{2} = IXZZX$$ $$g_{3} = XIXZZ$$ $$g_{4} = ZXIXZ$$ and it has the logical $$Z$$ and logical $$X$$ operators $$\bar{Z} = ZZZZZ$$ $$\bar{X} = XXXXX$$ However, their textbook does not give explicit detail as to how this code works.

My interpretation of the circuit

My understanding is the the codewords are logical 0 and logical 1 qubits

$$|0\rangle _{5L} = \frac{1}{4} (I + g_{1})(I +g_{2})(I + g_{3})(I + g_{4})|0\rangle \otimes |0\rangle \otimes |0\rangle \otimes |0\rangle \otimes |0\rangle$$

and the same idea for

$$|1\rangle_{5L} = \frac{1}{4} (I + g_{1})(I +g_{2})(I + g_{3})(I + g_{4})|1\rangle \otimes |1\rangle \otimes |1\rangle \otimes |1\rangle \otimes |1\rangle$$ .

So these are the possible starting states of the 5-qubit state $$|\psi\rangle$$.

First question: Why do we do this to obtain the codewords?

We go through the circuit and eventually measure the 4 ancillary qubits to output four pieces of information, (I assume these bits will correspond to the error that we may have in our codeword. For example, if there was an $$X$$ error on the first ancillary qubit then we will output $$0001$$ from the circuit?

My question(s)

But then where do the $$\bar{X}$$ and $$\bar{Z}$$ operators come in? Is this even a correct interpretation of the circuit? How does the circuit fit into the overall QECC?

The circuit image from wikipedia is quite mangled, and I am not quite sure if correct. Here is a nicely laid out syndrome measurement circuit for the $$[[5,1,3]]$$ code. Here, the top five qubits are the data qubits, while the bottom four are the syndrome measurement qubits. MR is the measurement operation.

You can see that there are four chunks to the circuit, corresponding to each of the stabilizers $$g_1$$ to $$g_4$$ as you specified. For instance, the four first controlled operations record the value of $$g_1 = XZZXI$$ in qubit 5.

So suppose, you prepare an arbitrary encoded state $$|\bar\psi\rangle = \alpha|0\rangle_{5L} + \beta|1\rangle_{5L}$$ of the code using the encoding circuit of the $$[[5,1,3]]$$ code. Then you suspect that this state has encountered an error, so you pass it through the syndrome measurement circuit above, to identify if any error has occurred.

Suppose, there was an $$X$$ error on the $$0$$-th qubit. Then, because $$X$$ and $$Z$$ don't commute, the last stabilizer $$g_4$$'s measurement will yield a 1. This is because the $$CZ_{80}$$ operation. Your measurement bits will be $$0001$$ 1

If instead, there was an $$Z$$ error on the $$0$$-th operation, then because of the $$CX_{50}$$ and $$CX_{70}$$, both $$g_1$$ and $$g_3$$ will trigger, leading to the measurement outcome $$1010$$. In this way, you can go through all possible one-qubit errors and see that they will yield a unique measurement outcome, hence perfectly identifying the location of the error.

But then where do the $$\bar{X}$$ and $$\bar{Z}$$ operators come in?

These the logical operators of the code. They are used to do actual computation on your encoded qubit, without having to decode it. Meaning, if Encoding($$|\psi\rangle$$) = $$|\bar\psi\rangle$$ (where $$|\psi\rangle$$ is an arbitrary one-qubit state), then Encoding($$X|\psi\rangle$$) = $$\bar{X}|\bar\psi\rangle$$.

You can take any quantum gate such as $$X,Y,Z,S,T,CX,CZ$$ and construct a logical version of it for a particular code, allowing you to do a direct quantum computation on the encoded qubit. The only problem is besides the Paulis the logical implementation of other quantum gates can be quite complex.

1 If $$c_i$$ is the outcome of measuring qubit $$i$$, then we have $$c_5c_6c_7c_8=0001$$.