# 6. The Toric Code (part 2)

This is the sixth post in a series on quantum error correction. For other parts, check out the link at the bottom.

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

The little squares are our physical qubits, with values either `0` or `1`. For each big white square we make a measurement. This adds up all the `0`’s and `1`’s around the square and tells us only whether the result is odd or even.

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.

There are four kinds of loop on a torus, all of which are shown on the image above (adapted from the one here).

• Loops that go around the ring (like the one in red).
• Loops that go through the ring (like the one in blue).
• Loops that go around and through the ring (none shown here).
• Loops that go neither around nor through the ring (the purple loop is just a particularly big and fancy example).

The last of these types is called topologically trivial. This is because there is nothing stopping you from continually shrinking it down until it disappears. This is not the case for the other types, where the structure of the torus prevents them being shrunk down to nothing. These are therefore imaginatively referred to as topologically non-trivial.

Measuring Loops

If we look again at our example, we can can see that their differences can be described using these new and horribly mathematical sounding terms. In short, (a) and (b) have no topologically non-trivial loop, but (c) and (d) do. Specifically, they both have a loop that goes around the ring (here’s the image again to save you scrolling).

This loop is nice and straight in (c) and has a little kink in (d), but that’s not a difference that topology cares much about. They both go around the ring, and that’s what matters.

For these examples it’s quite easy to see when we have a loop around the ring and when we don’t. In general, we need to find a way to make the distinction in a more mathematical way. For this we need more loops. But these loops will be different:

• They’ll pass through the blue squares
• They’ll go through the ring

Here are a couple of examples.

Now all we need to do is:

• Pick one of these two loops (or any other one that goes through the blue squares and through the ring);
• Add up all the `0`s and `1`s along it;
• See if the result is odd or even.

So let’s do that on our four examples, which I’ve now overlaid the new loops onto.

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 ring, 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 doughnuts. 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 ring meets one through the ring, they will cross an odd number of times. This is why our measurement didn’t see the little loop of `1`’s in (b), but did see the big ones round the ring in (c) and (d).

One additional thing to note is what happens when you have two loops around the ring. Because our measurement only looks at whether the final sum is odd or even, two of these topologically non-trivial rings will give the same answer as none. So to be precise, our measurement is telling us if there is an even or odd number of loops around the ring.

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 is and even or odd number of loops around the ring. Instead this needs our measurement to involve a whole bunch of physical qubits: enough for a loop through the ring. Otherwise we will leave a gap, and any loops that go through the gap will mess up our measurement.

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 ring. 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 qubit we pass.

For the grids drawn here we need to flip at least four physical qubits 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. 