# Encoding circuit for $[\![6, 4, 2]\!]$ code

For the famous $$[\![4, 2, 2]\!]$$ code, there is a circuit to encode two physical states into the logical state (from Roffe's work):

As $$[\![m, m-2, 2]\!]$$ is a class of error-detection code, I am wondering if there is a known similar encoding circuit for $$[\![6, 4, 2]\!]$$ code. Mathematically, the unitary always exists. But I failed to find any similar explicit circuit from the existing literature.

This can easily be done using stac. More explanations of the process for generating the encoding circuit is explained in a previous answer. But, since, this question is specifically asking for $$[[2m, 2m-2, 2]]$$ codes, here is how to do it.

import stac
import numpy as np
m = 3
generator_matrix = np.zeros((2*2*m, 2), dtype=int)
generator_matrix[0, :2*m] = np.ones((2*m,))
generator_matrix[1, 2*m:] = np.ones((2*m,))
stac.print_matrix(generator_matrix, augmented=True)


code = stac.Code(generator_matrix)
code.construct_encoding_circuit()
code.encoding_circuit

0 CX (0, 0, 2) (0, 0, 1)
1 CX (0, 0, 3) (0, 0, 1)
2 CX (0, 0, 4) (0, 0, 1)
3 CX (0, 0, 5) (0, 0, 1)
H (0, 0, 0)
4 CX (0, 0, 0) (0, 0, 1)
5 CX (0, 0, 0) (0, 0, 2)
6 CX (0, 0, 0) (0, 0, 3)
7 CX (0, 0, 0) (0, 0, 4)
8 CX (0, 0, 0) (0, 0, 5)

code.encoding_circuit.draw()


Here the input state is inserted onto the bottom $$2m-2$$ qubits.

• Nice answer! Thank you Abdullah for providing the beautiful figure! Commented Sep 23, 2023 at 14:49
• I'm confused. The code should be a $[[6,4,2]]$ code so I expect to see 4 stabilizers; your generator matrix only has 2 rows. Commented Sep 23, 2023 at 16:06
• @unknown Codes are labelled as $[[n,k,d]]$ indicating that $k$ physical logical qubits are encoded into $n$ data qubits. This is done by using $n-k$ stabilizers generators. Here, $n=6$ and $k=4$ leaving behind $2$ stabilizer generators. The reason why codes are labelled like this: Remember that stabilizer techniques is only one way of creating codes. There are others where there is no notion of stabilizer generators. What is usually more important is what the code does (encode $k$ qubits into $n$) and not how it does it. Commented Sep 23, 2023 at 18:23
• @AbdullahKhalid yes of course you're right...i don't know what i was thinking Commented Sep 23, 2023 at 19:10

We can obtain an encoding circuit for the $$[\![m,m-2,2]\!]$$ code for any even $$m$$ by generalizing the circuit displayed in the question. More precisely, for every new qubit we prepend a CNOT gate with the new qubit as the control and the second from the bottom qubit as the target and append a CNOT gate with the bottom qubit as the control and the new qubit as the target.

We can verify that the circuit is correct by propagating $$I^{\otimes m-2}\otimes Z\otimes I$$ and $$I^{\otimes m-2}\otimes I\otimes Z$$ through the circuit and checking that we obtain the appropriate stabilizer generators $$Z^{\otimes m}$$ and $$X^{\otimes m}$$.