The terminology of 'surface code' is a little bit variable. It might refer to a whole class of things, variants of the Toric code on different lattices, or it might refer to the Planar code, the specific variant on a square lattice with open boundary conditions.

# The Toric Code

I'll summarise some of the basic properties of the Toric code. Imagine a square lattice with periodic boundary conditions, i.e. the top edge is joined to the bottom edge, and the left edge is joined to the right edge. If you try this with a sheet of paper, you'll find you get a doughnut shape, or torus. On this lattice, we place a qubit on each edge of a square.

## Stabilizers

Next, we define a whole bunch of operators. For every square on the lattice (comprising 4 qubits in the middle of each edge), we write
$$
B_p=XXXX,
$$
acting a Pauli-$X$ rotation on each of the 4 qubits. The label $p$ refers to 'plaquette', and is just an index so we can later count over the whole set of plaquettes. On every vertex of the lattice (surrounded by 4 qubits), we define
$$
A_s=ZZZZ.
$$
$s$ refers to the star shape and again, will let us sum over all such terms.

We observe that all of these terms mutually commute. It's trivial for $[A_s,A_{s'}]=[B_p,B_{p'}]=0$ because Pauli operators commute with themselves and $\mathbb{I}$. More care is required with $[A_s,B_p]=0$, bot note that these two terms either have 0 or 2 sites in common, and pairs of different Pauli operators commute, $[XX,ZZ]=0$.

## Codespace

Since all these operators commute, we can define a simultaneous eigenstate of them all, a state $|\psi\rangle$ such that
$$
\forall s:A_s|\psi\rangle=|\psi\rangle\qquad\forall p:B_p|\psi\rangle=|\psi\rangle.
$$
This defines the codespace of the code. We should determine how large it is.

For an $N\times N$ lattice, there are $N^2$ qubits, so the Hilbert space dimension is $2^{N^2}$. There are $N^2$ terms $A_s$ or $B_p$, which we collectively refer to as stabilizers. Each has eigenvalues $\pm 1$ (to see, just note that $A_s^2=B_p^2=\mathbb{I}$) in equal number, and when we combine them, each halves the dimension of the Hilbert space, i.e. we would *think* that this uniquely defines a state.

Now, however, observe that $\prod_sA_s=\prod_pB_p=\mathbb{I}$: each qubit is included in two stars and two plaquettes. This means that one of the $A_s$ and one of the $B_p$ is linearly dependent on all the others, and does not further reduce the size of the Hilbert space. In other words, the stabilizer relations define a Hilbert space of dimension 4; the code can encode two qubits.

## Logical Operators

How do we encode a quantum state in the Toric code? We need to know the logical operators: $X_{1,L}$, $Z_{1,L}$, $X_{2,L}$ and $Z_{2,L}$. All four must commute with all the stabilizers, and be linearly independent from them, and must generate the algebra of two qubits. Commutation of operators on the two different logical qubits:
$$
[X_{1,L},X_{2,L}]=0\quad [X_{1,L},Z_{2,L}]=0 \quad [Z_{1,L},Z_{2,L}]=0\quad [Z_{1,L},X_{2,L}]=0
$$
and anti-commutation of the two on each qubit:
$$
\{X_{1,L},Z_{1,L}\}=0\qquad\{X_{2,L},Z_{2,L}\}=0
$$

There's a couple of different conventions for how to label the different operators. I'll go with my favourite (which is probably the less popular):

Take a horizontal line on the lattice. On every qubit, apply $Z$. This is $Z_{1,L}$. In fact, *any* horizontal line is just as good.

Take a vertical line on the lattice. On every qubit, apply $Z$. This is $X_{2,L}$ (the other convention would label it as $Z_{2,L}$)

Take a horizontal strip of qubits, each of which is in the middle of a vertical edge. On every qubit, apply $X$. This is $Z_{2,L}$.

Take a vertical strip of qubits, each of which is in the middle of a horizontal edge. On every qubit, apply $X$. This is $X_{1,L}$.

You'll see that the operators that are supposed to anti-commute meet at exactly one site, with an $X$ and a $Z$.

Ultimately, we define the logical basis states of the code by
$$
|\psi_{x,y}\rangle: Z_{1,L}|\psi_{x,y}\rangle=(-1)^x|\psi_{x,y}\rangle,\qquad Z_{2,L}|\psi_{x,y}\rangle=(-1)^y|\psi_{x,y}\rangle
$$

The distance of the code is $N$ because the shortest sequence of single-qubit operators that converts between two logical states constitutes $N$ Pauli operators on a loop around the torus.

## Error Detection and Correction

Once you have a code, with some qubits stored in the codespace, you want to keep it there. To achieve this, we need error correction. Each round of error correction comprises measuring the value of every stabilizer. Each $A_s$ and $B_p$ gives an answer $\pm 1$. This is your error syndrome. It is then up to you, depending on what error model you think applies to your system, to determine where you think the errors have occurred, and try to fix them. There's a lot of work going on into fast decoders that can perform this classical computation as efficiently as possible.

One crucial feature of the Toric code is that you do not have to identify exactly where an error has occurred to perfectly correct it; the code is *degenerate*. The only relevant thing is that you get rid of the errors without implementing a logical gate. For example, the green line in the figure is one of the basic errors in the system, called an anyone pair. If the sequence of $X$ rotations depicted had been enacted, than the stabilizers on the two squares with the green blobs in would have given a $-1$ answer, while all others give $+1$. To correct for this, we could apply $X$ along exactly the path where the errors happened, although our error syndrome certainly doesn't give us the path information. There are many other paths of $X$ errors that would give the same syndrome. We can implement *any* of these, and there are two options. Either, the overall sequence of $X$ rotations forms a trivial path, or one that loops around the torus in at least on direction. If it's a trivial path (i.e. one that forms a closed path that does not loop around the torus), then we have successfully corrected the error. This is at the heart of the *topological* nature of the code; many paths are equivalent, and it all comes down to whether or not these loops around the torus have been completed.

## Error Correcting Threshold

While the distance of the code is $N$, it is not the case that every combination of $N$ errors causes a logical error. Indeed, the vast majority of $N$ errors can be corrected. It is only once the errors become of much higher density that error correction fails. There are interesting proofs that make connections to phase transitions or the random bond Ising model, that are very good at pinning down when that is. For example, if you take an error model where $X$ and $Z$ errors occur independently at random on each qubit with probability $p$, the threshold is about $p=0.11$, i.e. $11\%$. It also has a finite fault-tolerant threshold (where you allow for faulty measurements and corrections with some per-qubit error rate)

# The Planar Code

Details are largerly identical to the Toric code, except that the boundary conditions of the lattice are open instead of periodic. This mens that, at the edges, the stabilizers get defined slightly differently. In this case, there is only one logical qubit in the code instead of two.

1

Welcome! To clarify: should answers assume that you have already taken a wikipedia-level look into toric codes and stabilizer codes?

– agaitaarino – 2018-05-19T14:31:13.7872I don't know about toric codes or stabilizer codes :| But I will read about it – Ivanovitch – 2018-05-19T15:05:35.277

1Nice! Then that should be a great start I think. I suggest to perhaps take a quick look at those and put some more details into the question: things that you already think you understand and others that don't make so much sense yet. Once it's answered, this could be a very helpful Q&A for people that come after you: these are important concepts and the terminology is indeed a little confusing. – agaitaarino – 2018-05-19T15:12:33.920

Related: "Quantum Error Correction: Surface code vs. color code" from SE.Physics.

– Nat – 2018-05-19T15:47:27.4404

I don't know about brief, but https://arxiv.org/abs/1208.0928 is where I started learning about the surface code from.

– Craig Gidney – 2018-05-19T16:38:26.780