Five and Seven Qubit Codes

5-Qubit code

In Chapter 9 of the text we introduced the 9-qubit Shor code. It  is capable of diagnosing and correcting all single-qubit errors. As the first quantum error correcting code (QECC), the Shor code is of historical significance. But, soon after its introduction, 5-qubit and 7-qubit QECC schemes were introduced. We review them below by applying the stabilizer formalism discussed in the text. First, let’s consider the 5-qubit code.

We posit the set of 5-qubit stabilizer operators

(* Define the Pauli operators, and the single qubit identity *)
Z={{1,0},{0,-1}};
X={{0,1},{1,0}};
Y={{0,-I},{I,0}};
unit={{1,0},{0,1}};
(* Hadamard Gate *)
H=1/Sqrt[2]{{1,1},{1,-1}};

Using these gates we construct the stabilizers

M0=KroneckerProduct[Z,X,X,Z,unit];
M1=KroneckerProduct[X,X,Z,unit,Z];
M2=KroneckerProduct[X,Z,unit,Z,X];
M3=KroneckerProduct[Z,unit,Z,X,X];

Exercise 1. What are the matrix dimensions of these operators ?

Exercise 2. Using the above matrix representations, confirm that the stabilizers are mutually commuting, i.e. [(Subscript[M, i]), (Subscript[M, j])]=0 for all combinations of i,j.

From our discussion in the text of the stabilizer formalism, we know that the logical codewords are eigenstates of the stabilizers with eigenvalue +1, i.e. 

where (Subscript[(Subscript[|0⟩, 5L]), |1⟩, 5L]) are 5-qubit codewords for the binary logical values 0,1 respectively.

Let’s define the following operators

(* Unit is the 5-qubit identity operator *)
Unit=IdentityMatrix[2^5];
projector=1/4(Unit+M0).(Unit+M1).(Unit+M2).(Unit+M3);

Exercise 3. Is operator projector really a projection operator ? (Hint: a projection operator P has the property P·P=P )

We claim that the action of operator projector on the states |00000⟩ and |11111⟩  results in the codewords, (Subscript[(Subscript[|0⟩, 5L]), |1⟩, 5L]) respectively, i.e

Or,

(* define single qubit states *)
ket0={1,0};
ket1={0,1};
codeword0=projector.Flatten[KroneckerProduct[ket0,ket0,ket0,ket0,ket0]]
codeword1=projector.Flatten[KroneckerProduct[ket1,ket1,ket1,ket1,ket1]]

Exercise 4. Re-express the states codeword0, codeword1, as a linear combination of the basis kets  (Subscript[|i⟩, 5]).

Exercise 5. Using the matrix representations for the stabilizers (Subscript[M, i]), and the states codeword0, codeword1, demonstrate that the latter are indeed eigenstates of all (Subscript[M, i]) with eigenvalue +1. Show that these codewords are orthonormal.

5-Qubit Syndrome Circuit

In the figure below we illustrate the series of gates that constitutes the syndrome measurements for this QECC. The first five wires (starting from the bottom of the figure)  represent the 5-qubit register, whereas the upper 4 wires represent the ancillary qubits, initially set to the state |0000⟩.

(* define ancillary qubit register set to state \[RightBracketingBar]0000⟩ *)
ancillary = Flatten[KroneckerProduct[ket0,ket0,ket0,ket0]]

(* gate0 represent the first 4 Hadamard gates acting on the ancillary qubit register, and its direct product with the 5-qubit register *)
gate0=KroneckerProduct[H,H,H,H,unit,unit,unit,unit,unit];

(* gate1 represents the first cluster of control-gates surrounded by the dotted line in the figure *)
gate1=KroneckerProduct[unit,unit,unit,{{1,0},{0,0}},unit,unit,unit,unit,unit]+KroneckerProduct[unit,unit,unit,{{0,0},{0,1}},Z,X,X,Z,unit];

(* gates2, gate3, gate4, correspond to the remaining three cluster of control gates in the figure*)
gate2=KroneckerProduct[unit,unit,{{1,0},{0,0}},unit,unit,unit,unit,unit,unit]+KroneckerProduct[unit,unit,{{0,0},{0,1}},unit,X,X,Z,unit,Z];

gate3=KroneckerProduct[unit,{{1,0},{0,0}},unit,unit,unit,unit,unit,unit,unit]+KroneckerProduct[unit,{{0,0},{0,1}},unit,unit,X,Z,unit,Z,X];

gate4=KroneckerProduct[{{1,0},{0,0}},unit,unit,unit,unit,unit,unit,unit,unit]+KroneckerProduct[{{0,0},{0,1}},unit,unit,unit,Z,unit,Z,X,X];

(* Syndrome circuit *) 
syndrome=gate0.gate4.gate3.gate2.gate1.gate0;

Syndrome Measurements

(* construct total 4+5 qubit state for codewords *)
state0=Flatten[KroneckerProduct[ket0,ket0,ket0,ket0,codeword0]];
state1=Flatten[KroneckerProduct[ket0,ket0,ket0,ket0,codeword1]];

Exercise 6. Is operator syndrome Hermitian ?

Exercise 7. Demonstrate that the codewords, state0, state1, are +1 eigenstates of  syndrome

In order to analyze the action of the syndrome on the codeword, let’s look at a simpler circuit shown by the diagram below

In this figure the shaded area represent stabilizer gate (Subscript[M, 0]) sandwiched by two Hadamard gates. We  included an X-type (i.e. bit flip) error in the wire of the second qubit. So if we focus on the first 5-qubit subspace and assume that the input state is the codeword (Subscript[|0⟩, 5L]), this error gate results in the vector
({{}})
where error gate,


Including the ancillary qubit, initially in state |0⟩,  the circuit results in the following output



where (Subscript[cM, 0]) represents the control gate connecting the ancillary control qubit with the target qubits 1-5. Now using the properties of the Hadamard and control gates we get,

Exercise 8. Prove that  (Subscript[(Subscript[(Subscript[M, 0])(Subscript[EX, 2])|0⟩, 5L])=- (Subscript[EX, 2])|0⟩, 5L]) .

Using this relation we find, that Eq. (3) reduces to

Exercise 9. If instead of the error considered above, the system is subjected to the errors boxes


show that the output of the circuit is

We can now apply this analysis to the full syndrome 5 + 4 qubit circuit shown in Fig. (1).  Because of the identity H H=1, we insert a pair of Hadamard gates between each cluster of stabilizers (Subscript[M, i]). Using the results of the analysis given above for Fig. (2), convince yourself

Exercise 10. That the action of error (Subscript[EX, 2]) in the first cluster of stabilizer (Subscript[M, 0]) (outlined by the dashed line), leads to the following output

As this state evolves, it meets the subsequent stabilizers (Subscript[M, 1]), (Subscript[M, 2]), (Subscript[M, 3]). We repeat this analysis to arrive at the final output of the syndrome circuit

Exercise 11. Show the action of error (Subscript[EX, 2]) leads to the following output in the syndrome circuit shown in 
Fig. (1)

Let’s check this result by simulating the syndrome circuit in Fig. (1). First, we construct the error box for (Subscript[EX, 2]).

(* 4+5 qubit error box *)
EX2=KroneckerProduct[unit,unit,unit,unit,unit,unit,unit,X,unit];

(* subject the codeword state0 to error box, and and pass it through the syndrome *)
output=syndrome.EX2.state0

According to our analysis this state should be the same as  |01010⟩⊗(Subscript[EX, 2]) |0⟩_(5L)

(* note: here EX2 is written as direct product with a unit ancillary qubit operator)*)
guess=EX2.Flatten[KroneckerProduct[ket0,ket1,ket0,ket1,codeword0]]

output==guess

So indeed our simulation is in harmony with the expected answer.

Problem1. Calculate the syndrome assignments of all possible single- (Subscript[X, i]) type errors.

Problem2. Calculate the syndrome assignments of all possible single- (Subscript[Z, i]) type errors.

Problem3. Calculate the syndrome assignments of all possible single- (Subscript[Y, i]) type errors

From the results of Problems 1,2,3 we find that each single-qubit error has a unique syndrome signature stored in the ancillary qubits. In general, the output has the form



where (Subscript[E, i]) is one of the error gates, and index i is the unique tag for that error. If a measurement of the ancillary qubits reveals index k, the subsequent action of gate (Subscript[E, k]), as it is a member of the Pauli group and so (Subscript[E, k])(Subscript[E, k])=1, projects the 5-qubit register into the uncorrupted state (Subscript[|0⟩, 5L]). Convince yourself that the arguments leading to this conclusion are also valid for codeword (Subscript[|1⟩, 5L]).

7-Qubit Code

Though the 5-qubit code requires the least number of qubits for a single-qubit QECC, the seven qubit, or Steane, code has become the code of choice in applications. A diagram for the syndrome circuit of this code is given below.

Problem 4. Identify the six stabilizers in this circuit.

Problem 5. Construct, as in Table 9.3 for the Shor code, a table itemizing all possible syndrome error measurements.

Problem 6. A matrix representation for this syndrome requires  (2^13)× (2^13) matrix elements to implement. Similarly, the circuit for the Shor code requires  matrices containing  (2^17)× (2^17) elements. The sheer size of these matrices makes a simulation of these quantum circuits untenable on desktop computers. Nevertheless, as Table 9.3 in the text and your result to Problem 5 demonstrate, it is not necessary to employ such large matrices in order to arrive at the correct output predictions. In other words, there exists an efficient classical algorithm which emulates the results output by these  quantum circuits. Write such a code. (Note: this feature is a consequence of the Gottesman-Knill Theorem1)

1	Michael A. Nielsen and Isaac L. Chuang, Quantum Computation and Quantum Information, Cambridge U. Press 2nd Ed. (2011).