Some common codes#
We should know some more quantum error-correcting codes, in order to deepen our understanding. We will define them here, via their generator matrix.
In stac, you can create any code for which you know the generator matrix. An example for the repetition code for phase flips is given below.
import stac
import numpy as np
# generator matrix
gm = np.array([[1, 1, 0, 0, 0, 0],
[0, 1, 1, 0, 0, 0]])
cd_rep = stac.Code(gm)
# n
print(f'n = {cd_rep.num_data_qubits}')
# k
print(f'k = {cd_rep.num_logical_qubits}')
# m = n-k
print(f'm = {cd_rep.num_generators}')
stac.print_paulis(cd_rep.generator_matrix)
n = 3 k = 1 m = 2
There are several codes whose generator matrix is stored inside stac. These are given below.
The five qubit code, $[[5,1,3]]$#
In this code, one qubit is encoded into the state of $n=5$ qubits. This code is unique because it is the smallest code (i.e. smallest $n$), which can correct any single-qubit error.
The code has generators as follows.
cd513 = stac.CommonCodes.generate_code('[[5,1,3]]')
stac.print_matrix(cd513.generator_matrix, augmented=True)
stac.print_paulis(cd513.generator_matrix)
Another feature of this code is that it has generators that have both $X$ and $Z$ operators in them. This is unlike any of the previous codes you have seen.
# stac has information stored about codes
print(cd513.num_generators)
print(cd513.num_data_qubits)
print(cd513.num_logical_qubits)
4 5 1
The Steane code, $[[7,1,3]]$#
The Steane code is often studied because it has a number of nice properties. It encoded one qubit into seven qubits and is able to correct any single qubit error. Interestingly, it is made out of the classical Hamming code, that we saw earlier.
You will see in the generator matrix below that the top left submatrix (which defines three $X$-type generators) is the matrix of the classical Hamming code. Similarly, the bottom right (which defines three $Z$-type generators is also the same Hamming code matrix.
cd713 = stac.CommonCodes.generate_code('[[7,1,3]]')
stac.print_matrix(cd713.generator_matrix, augmented=True)
stac.print_paulis(cd713.generator_matrix)
The $[[4,2,2]]$ code#
Up till now, you have seen codes that encode one qubit into many. This is unlike, say the classical Hamming code, which encoded three qubits into seven. The $$[4,2,2]]$$ is encodes two qubits into four qubits. However, this means that it can't correct all single-qubit errors.
cd422 = stac.CommonCodes.generate_code('[[4,2,2]]')
stac.print_matrix(cd422.generator_matrix, augmented=True)
stac.print_paulis(cd422.generator_matrix)
Now you are seeing a code which has $Y$ operators within its generators.
The $[[8,3,3]]$ code#
This code encodes three qubits into the state of eight qubits and can correct any single-qubit error.
cd833 = stac.CommonCodes.generate_code('[[8,3,3]]')
stac.print_matrix(cd833.generator_matrix, augmented=True)
stac.print_paulis(cd833.generator_matrix)