|q⟩ Bad Qubits

advanced · Programming · Implementing Error-Correcting Codes

Logical Operations on Encoded Qubits

Error correction would be pointless if we had to decode a logical qubit every time we wanted to compute with it — decoding exposes it to noise. The goal is to manipulate the encoded qubit while it stays protected. The operators that do this are the logical gates, and they live in the same multi-qubit space as the codewords.

What makes an operator "logical"

A logical operator Pˉ\bar{P} must satisfy two conditions:

  1. It maps the code space to itself — codewords go to codewords. Equivalently, it commutes with every stabilizer, so it never changes the syndrome.
  2. It acts as the intended single-qubit gate on the logical labels: Xˉ0L=1L\bar{X}|0_L\rangle = |1_L\rangle, Zˉ0L=0L\bar{Z}|0_L\rangle = |0_L\rangle, Zˉ1L=1L\bar{Z}|1_L\rangle = -|1_L\rangle.

A physical XX on one qubit fails condition 1: X0000=100X_0|000\rangle = |100\rangle is outside the code space (it has a nonzero syndrome). We need an operator built so the net effect lands back inside the code.

Logical X and Z for the bit-flip code

For 0L=000|0_L\rangle = |000\rangle, 1L=111|1_L\rangle = |111\rangle:

Xˉ=X0X1X2,Zˉ=Z0  (or Z1, or Z2).\bar{X} = X_0 X_1 X_2, \qquad \bar{Z} = Z_0 \;(\text{or } Z_1, \text{ or } Z_2).

Check Xˉ\bar X: X3000=111X^{\otimes 3}|000\rangle = |111\rangle and X3111=000X^{\otimes 3}|111\rangle = |000\rangle — it swaps the two codewords, the logical bit flip. It commutes with Z0Z1Z_0Z_1 and Z1Z2Z_1Z_2 (each XX anticommutes with two ZZ's, an even number), so the syndrome is untouched.

Check Zˉ=Z0\bar Z = Z_0: Z0000=000Z_0|000\rangle = |000\rangle and Z0111=111Z_0|111\rangle = -|111\rangle — it applies the logical phase. A single ZZ suffices here because all three qubits carry the same logical bit; any one of them reads it out.

Logical operators are not unique

Because Zˉ=Z0\bar Z = Z_0 and Zˉ=Z0(Z0Z1)=Z1\bar Z' = Z_0 (Z_0 Z_1) = Z_1 differ only by a stabilizer, they act identically on the code space. In general a logical operator is defined only up to multiplication by stabilizers — any representative in the same coset is equally valid. We usually pick the lowest-weight one; its weight is the code distance, here 3 for Xˉ\bar X and 1 for Zˉ\bar Z (the bit-flip code is asymmetric: strong against XX, weak against ZZ).

Try it

Encode 0L|0_L\rangle, then apply the logical XX to flip it to 1L=111|1_L\rangle = |111\rangle. The grader checks the statevector: the only nonzero amplitude must sit at index 7 (111).

Run your code to see the quantum state.

After running, the statevector panel shows a single bar at 111 with amplitude 1 — the encoded qubit has been flipped from logical 0 to logical 1 without ever leaving the protected code space.

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