|q⟩ Bad Qubits

advanced · Physics · Stabilizer Formalism & CSS Codes

Encoding Stabilizer Codes

Knowing a code's stabilizers tells us which states are codewords. To actually use a code we need a circuit that takes kk logical qubits' worth of input and maps it onto the nn-qubit codespace: an encoding circuit. For stabilizer codes this circuit is always a Clifford circuit, and there is a systematic recipe to build it.

What encoding must do

An encoder UencU_{\text{enc}} for an [[n,k]][[n,k]] code takes an arbitrary input

ψlogical0(nk)|\psi\rangle_{\text{logical}} \otimes |0\rangle^{\otimes (n-k)}

(the kk logical qubits followed by nkn-k ancillas in 0|0\rangle) to the corresponding codeword. In the Heisenberg picture, it must transform the input's stabilizers into the code's stabilizers:

Because every gig_i, Zˉi\bar Z_i, Xˉi\bar X_i is a Pauli, and the input generators are Paulis, the map between them is a Clifford unitary — built from HH, SS, and CNOT.

The standard-form algorithm

Cleve and Gottesman gave an explicit construction. The idea is to put the check matrix into a standard form by F2\mathbb{F}_2 Gaussian elimination plus qubit permutations, then read the encoding circuit off it:

  1. Row-reduce the check matrix [HXHZ][H_X \mid H_Z] so that HXH_X has the block structure \begin{psmallmatrix} I & A \mid B & C \\ 0 & 0 \mid D & I \end{psmallmatrix} (after possibly permuting qubits). This identifies a set of qubits whose stabilizers can be "seeded" directly.
  2. Seed with Hadamards. For each XX-type generator made independent in the reduction, apply a Hadamard to its pivot qubit, turning a 0|0\rangle (stabilized by ZZ) into a +|+\rangle (stabilized by XX).
  3. Spread with CNOTs (and CZ/S). Apply controlled gates that extend each seed Pauli into the full weight of its generator, following the 11-entries in the reduced check matrix.

The result is an O(n2)O(n^2)-gate Clifford circuit that prepares any codeword. For small codes the circuit is short and intuitive.

Worked intuition: small codes

Fault tolerance caveat

A bare encoding circuit like the ones above is not automatically fault tolerant: a single fault mid-circuit can spread through the CNOTs into a high-weight error that the code cannot correct. Fault-tolerant state preparation instead uses verified ancilla factories, flag qubits, or repeated measurement of the stabilizers to project into the codespace while keeping errors low-weight. The encoding circuit tells you the codewords; making it fault tolerant is a separate, deliberate design step covered in fault-tolerance modules.

The takeaway

Encoding a stabilizer code means applying a Clifford circuit that turns kk logical inputs plus nkn-k ancilla 0|0\rangle's into a codeword, by mapping the trivial ancilla ZZ-stabilizers onto the code's generators. The standard-form algorithm derives such a circuit mechanically from the check matrix in O(n2)O(n^2) gates. The circuit defines the codewords; achieving fault-tolerant preparation requires additional structure beyond the raw encoder.

Sign in on the full site to ask questions and join the discussion.