*This is part of a project to get people involved with quantum error correction. See here for more info.*

Last time we introduced the toric code, which is a way of making many noisy qubits (which we called

*physical qubits*) into one with hardly any noise at all (the

*logical qubit*). We have only covered some introductory stuff so far. Today we will look at exactly how the logical qubit is stored.

For this, we again need our picture

In all the examples above, each square has an even number of 1's. This is because the 1's always form loops. To understand the loops in (c) and (d), we need to remember that the code is wrapped around a torus, which is the shape of a ring doughnut.

**Measuring Loops**

There is obviously quite a bit difference between examples (a) and (b), and examples (c) and (d). In (c) and (d) there are loops around the doughnut, but in (a) and (b) there isn't. Is there a way we can quantify this more mathematically?

Look at the qubits shown in blue above. These are also in a loop. This loop goes through the blue squares, instead of the white ones. It also goes around the torus the other way: through the doughnut. We will use the blue qubits to make a measurement: we add up all their 0's and 1's and see if the result is odd or even.*

For example (a) we have no 1's, so the result of the measurement is obviously even. For example (b) the blue qubits will cross the small loop of 1's. They cross once when they enter and then again when they leave. This means they see two 1's. The sum of everything is then 2, so the result of the measurement is again even.

In (c) there is a loop around the doughnut, and the blue qubits will only cross it once. They see a single 1, and so the sum will be 1. The result of the measurement is odd. The same is true for (d).

This happens because of the magic of dougnuts. Usually if we have a couple of loops, either in a quantum code or in real life, they will cross each other an even number of times. Just draw a bunch of crazy overlapping loops on a piece of paper and you'll soon see it's true.

If you are drawing on a doughnut (with icing, I guess), that's not always true. When a loop round the doughnut meets one through the doughnut, they will cross an odd number of times. This is why our measurement through the doughnut didn't see the little loop of 1's in (b), but did see the big ones round the doughnut in (c) and (d).

Now we know this, we know exactly what the measurement of the blue qubits is telling us. When it says 'even', it's telling us that there's an even number of loops around the doughnut. When it says 'odd', it's telling us there is an odd number.

You probably noticed that there is a bunch of green qubits on the same picture. This is in a different place and a bit wiggly, but it still passes through blue squares and loops through the doughnut. Doing the same measurement on this will give the same results as for the blue qubits. In fact, we could use any loop through the doughnut (that passes through blue squares). They will always tell us the same information about the loops of bit flips around the doughnut (that pass through white squares).

**Storing a qubit**

We've been having so much fun with the toric code, we almost forgot that we need to store a logical qubit with it. This is just some information, 0 or 1, that we want to store with as few errors as possible. And we want to store it so that any quantum superposition of 0 and 1 doesn't get messed up.

For this we need to pick some sets of 0's and 1's for the physical qubits (the small squares in the toric code) that we associate with the 0 of the logical qubit, and some that we associate with the 1 of the logical qubit. For the repetition code we just picked 00000... on the physical qubits to be the logical 0, and 11111... to be logical 1 (see this post for a summary). But the toric code is a but more complicated.

In the last post we had a little wishlist of things we wanted when storing a logical qubit. One was that we shouldn't be able to measure whether it is 0 or 1 by looking at just one physical qubit.

In the toric code there is something that we cannot measure with just one physical qubit: whether there are an odd or even number of loops around the doughnut. For this we need our measurement to involve a whole bunch of physical qubits. We need enough for a loop through the doughnut, otherwise we will leave a gap. Any loops that go through the gap will mess up our measurement. So it is useless unless it goes all the way around.

For the grids drawn here we need at least four physical qubits for a loop through the doughnut. If we use bigger grids, we will need even more. The bigger the grid, the more this information gets hidden.

This is perfect for our logical qubit. If we want our logical qubit to be 0, let's use a bunch of physical qubits with an even number of loops around the doughnut. So we could set the physical bits to the values in (a) or (b), as well as loads of other possibilities. If we want our logical qubit to be 1, let's use an odd number of loops around the doughnut. We could use (c) or (d) or many others.

Now our logical bit value has been stored, and we cannot see whether it is 0 or 1 without measuring a whole bunch of physical qubits. Just as we wanted. But we have another wish to be fulfilled. We want it to be hard to turn a logical 0 into a logical 1, and vice-versa.

The toric code grants this wish too! To turn 0 into 1 we need to go from an even number of loops around the doughnut into an odd number. The only way to do this is to add one (or remove one). This means going along a loop around the doughnut and flipping every physical bit we pass.

For the grids drawn here we need to flip at least four physical bits for a loop around the doughnut. If we use bigger grids, we will need even more. The bigger the grid, the effort it takes to flip logical 0 to logical 1, and the same for 1 to 0.

The toric code grants all our wishes! It is a pretty good code for quantum information.

**Correcting Errors**

You may wonder if this is all quite true. You may be thinking of loopholes that could mess everything up without needing to do flips on loads of physical qubits. At the moment, loopholes do exist. But they will be closed next time when we start looking at how we can detect and correct errors.

* You might notice that this is exactly what we do when we measure the white squares. The qubits we measure in that case also form a loop that passes through blue squares. The only difference is that they are little loops, rather than big ones through the doughnut.