An encoding circuit is the unitary Uenc that maps an unprotected qubit onto a
logical codeword. Every code in this module begins with one. Get the encoder right and the rest of
the pipeline — syndrome extraction, decoding, logical gates — has something well-defined to act on.
What an encoder must do
A code is fixed by its two logical basis states ∣0L⟩ and ∣1L⟩. The encoder is any
unitary satisfying
Uenc∣0⟩∣0⋯0⟩=∣0L⟩,Uenc∣1⟩∣0⋯0⟩=∣1L⟩,
where the data qubit carries the input and the remaining qubits start in ∣0⟩. Because
Uenc is linear, it then automatically encodes any superposition:
Uenc(α∣0⟩+β∣1⟩)∣0⋯0⟩=α∣0L⟩+β∣1L⟩.
This is the whole reason a single fixed circuit protects an unknown state.
The bit-flip encoder
The three-qubit bit-flip code uses
∣0L⟩=∣000⟩,∣1L⟩=∣111⟩.
Its encoder copies the data qubit onto two partners with CNOTs:
cx(0,1);cx(0,2).
Check it on basis inputs: ∣000⟩↦∣000⟩ and ∣100⟩↦∣111⟩.
By linearity α∣000⟩+β∣100⟩↦α∣000⟩+β∣111⟩.
Encoding a non-trivial state
To make the exercise checkable we encode the logical ∣+L⟩. First prepare ∣+⟩ on
the data qubit with a Hadamard, then run the bit-flip encoder:
The two nonzero amplitudes are each 1/2≈0.707. Note this is a genuinely
entangled three-qubit state — measuring any one qubit instantly fixes the other two.
Order matters
Apply the Hadamard before the CNOTs. Doing it after would put the redundancy qubits into
superposition and produce a different (and unprotected) state. An encoder is a specific sequence,
not a bag of gates.
Try it
Build the bit-flip encoder for ∣+L⟩ on three qubits. The grader checks the full
statevector: amplitudes of ∣000⟩ and ∣111⟩ must each be 1/2 and all six
other amplitudes must be zero.
Run your code to see the quantum state.
After running, the statevector panel should show exactly two bars, at indices 0 (000) and 7
(111), each at height ≈0.707.
Sign in on the full site to ask questions and join the discussion.