# The stabilizer trilogy II — Logical operators

Happy to see you back for the second part of the stabilizer trilogy! In the previous post, we defined stabilizer codes and gave a few examples of codes and constructions. In particular, we studied the Steane code, which can be defined by laying down seven qubits on a triangle with three colored faces, each representing an X$X$ and a Z$Z$ stabilizer. However, we left pending a few important questions: what are the parameters of the code, and in particular the number of logical qubits and the distance? What logical operations can we apply to this code? How does the decoding process work?

In this post, we will get down to the nitty-gritty of logical operations. Those are unitary operators acting on the physical qubits, which allow you to go from one part of the codespace to another. For instance, a logical Hadamard lets you go from the logical zero state \vert 0 \rangle_L$\vert 0 \rangle_L$ to the logical plus state \vert + \rangle_L$\vert + \rangle_L$. An important class of logical operations are the Pauli logicals, whose properties form a crucial component of stabilizer codes, as they allow to derive the distance of the code, the number of logical qubits, and the main formulation of decoding. Formalizing all those ideas rigorously relies on a fair bit of abstraction, using notions such as centralizers, normalizers, equivalence classes, etc. While we won’t shy away from the abstraction, we will also make every notion as concrete as possible using the Steane code as our running example.

We will start by showing how to count the number of logical qubits encoded in a stabilizer code. We will then formalize the notion of logical gates in a stabilizer code, and specialize the definition to the case of Pauli operators. Finally, we will see how to understand logical operators in terms of equivalent classes, which will become very handy when trying to understand decoding and topological constructions.

## Logical qubits

Before exploring logical operations, let’s first understand how to count the logical qubits of a stabilizer code. Remember that the number of logical qubits is given by the logarithm of the dimension of the codespace. Indeed, if the codespace has dimension four, any logical state can be written as

\begin{aligned}
\vert \psi \rangle_L = a_1 \vert a_1\rangle + a_2 \vert a_2\rangle + a_3 \vert a_3\rangle + a_4 \vert a_4\rangle
\end{aligned}

Relabelling \vert a_1\rangle$\vert a_1\rangle$ as \vert 00\rangle_L$\vert 00\rangle_L$, \vert a_2\rangle$\vert a_2\rangle$ as \vert 01\rangle_L$\vert 01\rangle_L$, etc. shows that the space corresponds to a two-qubit space.

So what we really need to compute is the dimension of \mathcal{C}$\mathcal{C}$ for a stabilizer code. Let n$n$ denote the number of physical qubits of our code, and m$m$ the number of generators of the stabilizer group (i.e. there are m$m$ independent elements whose products generate the whole group). The dimension of the physical Hilbert space is 2^n$2^n$, and each constraint S_i \vert \psi \rangle = \vert \psi \rangle$S_i \vert \psi \rangle = \vert \psi \rangle$ divides this dimension by two. Indeed, each S_i$S_i$ has two eigenvalues with the same multiplicity, +1$+1$ and -1$-1$, dividing the physical Hilbert space into two eigenspaces of equal dimension. Therefore, we have

\begin{aligned}
\text{dim}(\mathcal{C})=2^{n-m}
\end{aligned}

and the number of logical qubits is k=n-m$k=n-m$. This should remind you of classical codes, where the same formula applies when m$m$ is the number of independent parity checks.

Let’s apply this formula to the Steane code. As a reminder, the Steane code is a 7$7$-qubit code defined on the following lattice, such that each face (also called plaquette) supports an X$X$ and a Z$Z$ stabilizer generator:

Therefore, the Steane code has six independent stabilizer generators, three X$X$ plaquettes and three Z$Z$ plaquettes, such that m=6$m=6$. Hence we can see that it encodes k=7-6=1$k=7-6=1$ logical qubits.

## Logical gates

Now that we know the number of encoded qubits, what about the distance? To describe it, we need to introduce the notion of Pauli logical operator, which is a special case of logical gate. A logical gate is a unitary operator L$L$ that maps the codespace to itself, i.e. such that L \vert \psi \rangle \in \mathcal{C}$L \vert \psi \rangle \in \mathcal{C}$ for all \vert \psi \rangle \in \mathcal{C}$\vert \psi \rangle \in \mathcal{C}$. Logical gates therefore include stabilizers, but also operators that map one part of the codespace to another part. For instance, a logical Hadamard maps the logical zero state \vert \overline{0} \rangle$\vert \overline{0} \rangle$ to the logical plus state \vert \overline{+} \rangle=\frac{1}{\sqrt{2}} \left(\vert \overline{0} \rangle + \vert \overline{1} \rangle\right)$\vert \overline{+} \rangle=\frac{1}{\sqrt{2}} \left(\vert \overline{0} \rangle + \vert \overline{1} \rangle\right)$.

Another way to understand logical gates is through their actions on the stabilizer group. Indeed, we can prove the following proposition:

Proposition 1: a unitary L$L$ is a logical gate if and only if it maps the stabilizer group \mathcal{S}$\mathcal{S}$ to itself, i.e. L^{\dagger} SL \in \mathcal{S}$L^{\dagger} SL \in \mathcal{S}$ for all S \in \mathcal{S}$S \in \mathcal{S}$.

Note that this is precisely the definition of the normalizer of the group \mathcal{S}$\mathcal{S}$, denoted \mathcal{N}(\mathcal{S})$\mathcal{N}(\mathcal{S})$, and you will often find logical gates defined in the literature as elements of the normalizer of the stabilizer group. This proposition explains why those two definitions are equivalent, and proving it is a cute little exercise that I encourage you to try on your own before reading the solution at the end of this post.

Exercise 1: Prove Proposition 1 (solution)

Let’s apply this to the Steane code. For instance, let’s consider the operator H_L=H^{\otimes 7}$H_L=H^{\otimes 7}$ consisting of applying a Hadamard gate on all the physical qubits:

I claim that H_L$H_L$ is a logical gate. To show this, let’s use Proposition 1 and show that it maps stabilizers to stabilizers. Let’s pick an X$X$ plaquette, for instance the red one supported on qubits 1,2,3,4$1,2,3,4$, that we will call S^X_r$S^X_r$. Remember that H$H$ turns X$X$ into Z$Z$ and Z$Z$ into X$X$, that is HXH=Z$HXH=Z$ and HZH=X$HZH=X$. Therefore:

\begin{aligned}
H_L S^X_r H_L
&= (H_1 \ldots H_7) X_1 X_2 X_3 X_4 (H_1 \ldots H_7) \\
&= (H_1 X_1 H_1) \ldots (H_4 X_4 H_4) H_5^2 H_6^2 H_7^2 \\
&= Z_1 Z_2 Z_3 Z_4 \\
& = S^Z_r
\end{aligned}

where S^Z_r$S^Z_r$ is the Z$Z$ red plaquette. Therefore, H_L$H_L$ maps the X$X$ red plaquette to the Z$Z$ red plaquette. The same reasoning can be applied to all the other X$X$ and Z$Z$ plaquettes, showing that H_L$H_L$ maps stabilizers to stabilizers and is therefore a logical gate.

Note that we haven’t shown that H_L$H_L$ actually corresponds to a logical Hadamard, i.e. that it maps \vert \overline{0} \rangle$\vert \overline{0} \rangle$ to \vert \overline{+} \rangle$\vert \overline{+} \rangle$ and \vert \overline{1} \rangle$\vert \overline{1} \rangle$ to \vert \overline{-} \rangle$\vert \overline{-} \rangle$. The easiest way to show that is by proving that H_L$H_L$ maps the logical X$X$ operator to the logical Z$Z$ operator, and vice-versa. The next step is therefore to get a grasp of the Pauli logical operators. But before that, feel free to try the following exercise to check your understanding of logical gates:

Exercise 2: Show that S_L=S^{\otimes 7}$S_L=S^{\otimes 7}$ is a logical gate (solution)

## Pauli logicals

An important family of logical gates are the Pauli logical operators (often abbreviated logical operators if the context is clear, or even just logicals). As expected, those are the logical gates that belong to the Pauli group. As two given Pauli operators can either commute or anticommute, Pauli logicals could either commute or anticommute with stabilizers. However, if a Pauli logical anticommute with a stabilizer, that is SL=-LS$SL=-LS$, it means that L^{\dagger} S L = -S \notin \mathcal{S}$L^{\dagger} S L = -S \notin \mathcal{S}$, which contradicts the characterization of logical gates that we saw above. Therefore, Pauli logicals can be characterized by the following proposition:

Proposition 2: a Pauli operator P$P$ is a logical operator if and only if it commutes with all the stabilizers

Note that this is precisely the definition of the centralizer of the group \mathcal{S}$\mathcal{S}$ in the Pauli group, denoted \mathcal{C}(\mathcal{S})$\mathcal{C}(\mathcal{S})$. The difference between the normalizer and the centralizer is that if L \in \mathcal{N}(\mathcal{S})$L \in \mathcal{N}(\mathcal{S})$, LS=S'L$LS=S'L$ for S, S'$S, S'$ two stabilizers, while if L \in \mathcal{C}(\mathcal{S})$L \in \mathcal{C}(\mathcal{S})$, LS=SL$LS=SL$. For Pauli operators, \mathcal{N}(\mathcal{S}) = \mathcal{C}(\mathcal{S})$\mathcal{N}(\mathcal{S}) = \mathcal{C}(\mathcal{S})$ and you will often find Pauli logicals defined with either normalizers or centralizers in the literature. Using either this characterization or the original definition, it is easy to show that the set \mathcal{L}$\mathcal{L}$ of all Pauli logicals from a group, that is, the product of two logicals is itself a logical.

Finally, let’s define non-trivial logical operators (also known as logical errors) as elements of \mathcal{C}(\mathcal{S}) \backslash \mathcal{S}$\mathcal{C}(\mathcal{S}) \backslash \mathcal{S}$, or in other words, Pauli operators that commute with all the stabilizers but are not stabilizers themselves. We can now characterize the distance of a stabilizer code as the weight of the smallest logical error:

\begin{aligned}
d = \min_{L \in \mathcal{C}(\mathcal{S}) \backslash \mathcal{S}} |L|
\end{aligned}

As usual, let’s apply what we’ve seen to the Steane code. I claim that the following operators, that we will call X_L$X_L$ and Z_L$Z_L$, are non-trivial logical operators of the code:

Indeed, it is easy to check that they commute with all the stabilizers, as they share either zero or two qubits with every plaquette. Moreover, by trying all the combinations of stabilizers, you can show that they don’t belong the stabilizer group, and are therefore non-trivial. By using a similar brute-force search, you can also show that they are the smallest non-trivial logical operators, thereby proving that the distance of the Steane code is d=3$d=3$. This achieves the proof that the Steane code is a [[7,1,3]]$[[7,1,3]]$ code, as claimed in the previous post.

However, as discussed in the context of the Hadamard gate, we still haven’t shown that X_L$X_L$ and Z_L$Z_L$ actually act as logical X$X$ and Z$Z$ operators on the codespace. For that, we would need to show that X_L$X_L$ corresponds to a logical bit-flip and Z_L$Z_L$ to a logical phase-flip, i.e. that they map respectively \vert 0 \rangle_L$\vert 0 \rangle_L$ into \vert 1 \rangle_L$\vert 1 \rangle_L$ and \vert + \rangle_L$\vert + \rangle_L$ into \vert - \rangle_L$\vert - \rangle_L$. Alternatively, we could show that \vert 0 \rangle_L$\vert 0 \rangle_L$ and \vert 1 \rangle_L$\vert 1 \rangle_L$ are eigenstates of Z_L$Z_L$ while \vert + \rangle_L$\vert + \rangle_L$ and \vert - \rangle_L$\vert - \rangle_L$ are eigenstates of X_L$X_L$.

As it happens, this is just a matter of convention. There is no preferred \vert 0 \rangle_L$\vert 0 \rangle_L$ state in the codespace, we have the freedom to pick any of the states and decide that it is going to be the zero state. For instance, for the repetition code, we decided that \vert 0 \rangle_L=\vert 000 \rangle$\vert 0 \rangle_L=\vert 000 \rangle$, but we could have very much taken \vert 0 \rangle_L=\vert 111 \rangle$\vert 0 \rangle_L=\vert 111 \rangle$ or even \vert 0 \rangle_L=\frac{1}{\sqrt{2}} \left(\vert 000 \rangle+\vert 111 \rangle\right)$\vert 0 \rangle_L=\frac{1}{\sqrt{2}} \left(\vert 000 \rangle+\vert 111 \rangle\right)$, as long as we keep track of it during the computation and when analyzing the measurements.

Therefore, as it is usually done with stabilizer codes, let’s define \vert 0 \rangle_L$\vert 0 \rangle_L$ and \vert 1 \rangle_L$\vert 1 \rangle_L$ as the two eigenstates of Z_L$Z_L$, and \vert + \rangle_L$\vert + \rangle_L$ and \vert - \rangle_L$\vert - \rangle_L$ as the two eigenstates of X_L$X_L$. This is a valid choice since X_L$X_L$ and Z_L$Z_L$ anticommute, and this also fixes the logical Y$Y$ operator as Y_L=X_LZ_L$Y_L=X_LZ_L$. All the other logical gates are also fixed by how they transform those Pauli operators. For instance, you are now ready to prove that the logical gate H_L$H_L$ actually acts as a logical Hadamard gate.

Exercise 3: Show that H_L=H^{\otimes 7}$H_L=H^{\otimes 7}$ acts as a logical Hadamard gate (solution)
(Hint: show that H_L X_L H_L=Z_L$H_L X_L H_L=Z_L$ and H_L Z_L H_L=X_L$H_L Z_L H_L=X_L$)

## Logical cosets

In the previous example, we saw one instance of logical X$X$ and Z$Z$ operators. However, there will often be multiple logical operators that act as a given Pauli. Indeed, take a logical operator L \in \mathcal{L}$L \in \mathcal{L}$ and a stabilizer S \in \mathcal{S}$S \in \mathcal{S}$. Then SL=LS$SL=LS$ is also a logical operator acting in the same way on the codespace:

\begin{aligned}
L S \vert \psi \rangle = L \vert \psi \rangle
\end{aligned}

In other words, applying a stabilizer to a logical doesn’t change the way it acts on the codespace. We say that two logicals L$L$ and L'$L'$ are equivalent if they only differ by a stabilizer, that is, if there exists S \in \mathcal{S}$S \in \mathcal{S}$ such that SL=L'$SL=L'$. For instance, we have the following three equivalent logical X$X$ operators in the Steane code:

To go from the first one to the second one, we apply a green X$X$ plaquette. To go from the second one to the last one, we apply a red X$X$ plaquette.

Since all the equivalent logicals act in the same way on the codespace, it makes sense to group them together in some ways. The notion of equivalence classes is exactly what we need to formalize this idea.

An equivalence class, or coset, is a set of the form

\begin{aligned}
\bar{L}=L\mathcal{S}=\{ LS : S \in \mathcal{S} \}
\end{aligned}

where L \in \mathcal{L}$L \in \mathcal{L}$ is any logical operator. In other words, a coset is a set of equivalent logicals. Any element P \in \bar{L}$P \in \bar{L}$ is called a representative of the coset \bar{L}$\bar{L}$. For instance, any of the three X$X$ logicals of the figure above are representative of the coset \bar{X}$\bar{X}$ of X$X$ logicals. Note that since the Steane code has only one qubit, all the X$X$ logicals are equivalent and there is only one coset of X$X$ logicals.

Let’s remember a few important properties of equivalence classes. First of all, they partition the set of logical operators, that is, they are all disjoint (i.e. have an empty intersection) and their union is the whole set. In the case of the Steane code, this can be written1:

\begin{aligned}
\mathcal{L}=\bar{I} \cup \bar{X} \cup \bar{Y} \cup \bar{Z}
\end{aligned}

If we had multiple logical qubits, we would have three different cosets \bar{X_i}$\bar{X_i}$, \bar{Y_i}$\bar{Y_i}$, \bar{Z_i}$\bar{Z_i}$ for each logical qubit.

Secondly, the set of all the cosets form a group, which is called the quotient group of \mathcal{L}$\mathcal{L}$ by \mathcal{S}$\mathcal{S}$, and denoted \mathcal{L} / \mathcal{S}$\mathcal{L} / \mathcal{S}$. In this group, the multiplication between two cosets \bar{L}_1=L_1 \mathcal{S}$\bar{L}_1=L_1 \mathcal{S}$ and \bar{L}_2=L_2 \mathcal{S}$\bar{L}_2=L_2 \mathcal{S}$ is defined as L_1 L_2 \mathcal{S}$L_1 L_2 \mathcal{S}$, where L_1$L_1$ and L_2$L_2$ are two arbitrary representatives of \bar{L}_1$\bar{L}_1$ and \bar{L}_2$\bar{L}_2$. It is a nice exercise to check that the result does not depend on the choice of the two representatives. Moreover, you can check that the identity element of the group is \bar{I}=\mathcal{S}$\bar{I}=\mathcal{S}$.

Finally, the quotient group can be generated by all the \bar{X}_i, \bar{Z}_i$\bar{X}_i, \bar{Z}_i$. This means that the number of logical qubits is exactly half the number of generators of \mathcal{L}/\mathcal{S}$\mathcal{L}/\mathcal{S}$. This simple fact gives us a different way to count the number of logical qubits of a given stabilizer code, which will become extremely important when discussing topological quantum error correction in future posts.

## Conclusion

In this post, we have introduced many crucial concepts to understand stabilizer codes. We have defined logical gates as operators that preserve the codespace, or equivalently, the stabilizer space. Those corresponds to elements of the normalizer of \mathcal{S}$\mathcal{S}$. In the specialize case of Pauli operators, we have seen that they correspond to elements of the centralizer, that is, elements that commute with all the stabilizers. We have seen that logical operations are highly degenerate in stabilizer codes, as multiplying a logical operator by a stabilizer gives the same operation on the codespace. We have therefore shown how to group equivalent logicals together within equivalent classes. We have learned how to compute the number of logical qubits in two different ways: either by counting the number m$m$ of generators of \mathcal{S}$\mathcal{S}$ and using k=n-m$k=n-m$, or by counting the number of generators of \mathcal{L} / \mathcal{S}$\mathcal{L} / \mathcal{S}$ and dividing by two. Finally, we have seen that the distance can be obtained by finding the minimum-weight logical operator. All those ideas have been illustrated using the Steane code, which we have proven to be a [[7,1,3]]$[[7,1,3]]$-code.

In the next and last part of this trilogy, we will see how to formulate the stabilizer formalism in a more concrete way, using parity-check matrices in the binary symplectic format. This format, widely used in numerical implementations of quantum codes, will allow us to switch from group theory to linear algebra. We will express stabilizers and logicals as binary vectors, with commutation relations corresponding to a linear operation on those vectors. Using the notion of logical cosets that we have learned in this post, we will finally be able to formalize the decoding problem for quantum codes.

## Solution of the exercises

Exercise 1: Prove that a unitary L$L$ is a logical gate if and only if it maps the stabilizer group \mathcal{S}$\mathcal{S}$ to itself, i.e. L^{\dagger} SL \in \mathcal{S}$L^{\dagger} SL \in \mathcal{S}$ for all S \in \mathcal{S}$S \in \mathcal{S}$.

Correction: For the first direction, let’s suppose that L$L$ is a logical gate, i.e. L$L$ maps the codespace to itself. For S \in \mathcal{S}$S \in \mathcal{S}$, let’s show that LSL^{\dagger} \in \mathcal{S}$LSL^{\dagger} \in \mathcal{S}$, that is, LSL^{\dagger} \vert \psi \rangle = \vert \psi \rangle$LSL^{\dagger} \vert \psi \rangle = \vert \psi \rangle$ for all \vert \psi \rangle \in \mathcal{C}$\vert \psi \rangle \in \mathcal{C}$. For \vert \psi \rangle \in \mathcal{C}$\vert \psi \rangle \in \mathcal{C}$, L\vert \psi \rangle \in \mathcal{C}$L\vert \psi \rangle \in \mathcal{C}$ by assumption, so SL\vert \psi \rangle = L \vert \psi \rangle$SL\vert \psi \rangle = L \vert \psi \rangle$ and L^{\dagger} S L \vert \psi \rangle = L^{\dagger} L \vert \psi \rangle = \vert \psi \rangle$L^{\dagger} S L \vert \psi \rangle = L^{\dagger} L \vert \psi \rangle = \vert \psi \rangle$. For the other direction, let’s suppose that L \in \mathcal{N}(\mathcal{S})$L \in \mathcal{N}(\mathcal{S})$, and let’s show that for a state \vert \psi \rangle \in \mathcal{C}$\vert \psi \rangle \in \mathcal{C}$, L \vert \psi \rangle \in \mathcal{C}$L \vert \psi \rangle \in \mathcal{C}$. It comes down to showing SL \vert \psi \rangle = L \vert \psi \rangle$SL \vert \psi \rangle = L \vert \psi \rangle$ for S \in \mathcal{S}$S \in \mathcal{S}$. Since L^{\dagger} S L \in \mathcal{S}$L^{\dagger} S L \in \mathcal{S}$ by assumption, there exists S' \in \mathcal{S}$S' \in \mathcal{S}$ such that L^{\dagger} S L = S'$L^{\dagger} S L = S'$, or equivalently, SL = LS'$SL = LS'$. Therefore, SL\vert \psi \rangle = LS'\vert \psi \rangle = L \vert \psi \rangle$SL\vert \psi \rangle = LS'\vert \psi \rangle = L \vert \psi \rangle$.
(Back to section)

Exercise 2: Show that S_L=S^{\otimes 7}$S_L=S^{\otimes 7}$ is a logical gate

Correction: Remember that the S$S$ gate turns X$X$ into Z$Z$ and Z$Z$ into itself. Let’s pick any X$X$ plaquette. Applying S_L$S_L$ turns X^{\otimes 4}$X^{\otimes 4}$ into Y^{\otimes 4}$Y^{\otimes 4}$. Since Y^{\otimes 4}=X^{\otimes 4} Z^{\otimes 4}$Y^{\otimes 4}=X^{\otimes 4} Z^{\otimes 4}$ (up to a phase), it is a product of stabilizers and therefore a stabilizer itself. Moreover, S_L$S_L$ leaves Z$Z$ plaquettes unchanged. Thus, S_L$S_L$ maps stabilizers to stabilizers and forms a logical gate.
(Back to section)

Exercise 3: Show that H_L=H^{\otimes 7}$H_L=H^{\otimes 7}$ acts as a logical Hadamard gate
(Hint: show that H_L X_L H_L=Z_L$H_L X_L H_L=Z_L$ and H_L Z_L H_L=X_L$H_L Z_L H_L=X_L$)

Correction: Consider the logical X$X$ operator X_L=X^{\otimes 3}$X_L=X^{\otimes 3}$ acting on qubits 5,6,7$5,6,7$. We get H_L X_L H_L = Z^{\otimes 3}=Z_L$H_L X_L H_L = Z^{\otimes 3}=Z_L$. Using a similar reasoning, we can show that H_L Z_L H_L =X_L$H_L Z_L H_L =X_L$. Thus, H_L$H_L$ acts as a logical Hadamard on the codespace.
(Back to section)

1. For simplicity, I have chosen to ignore phases here. A more exact decomposition would need to include the cosets -\bar{X}$-\bar{X}$, i\bar{X}$i\bar{X}$, -i\bar{X}$-i\bar{X}$, etc. ↩︎