Category: error-correction | Difficulty: intermediate | Qubits: 3 | Gates: 11 | Depth: 7
The phase-flip code is the dual of the bit-flip code, operating in the X basis. A logical qubit is encoded as α|+++⟩ + β|---⟩ using CNOT + Hadamard. A Z error on any physical qubit flips the X-basis eigenvalue; the syndrome measurement detects and corrects it. This code cannot correct both bit and phase errors — that requires the Shor or Steane codes.
c[0]=0 (logical |+⟩ decoded correctly despite Z error on q[1])
The OpenQASM 2.0 circuit is in circuit.qasm.
OPENQASM 2.0;
include "qelib1.inc";
// Phase-flip code: encode |+> in X basis, correct one Z error
qreg q[3];
creg c[1];
// Prepare logical |+>
h q[0];
// Encode in X basis: spread then Hadamard
cx q[0],q[1];
cx q[0],q[2];
h q[0]; h q[1]; h q[2];
// Simulate a phase-flip error on q[1]
z q[1];
// Decode: reverse encoding
h q[0]; h q[1]; h q[2];
cx q[0],q[1];
cx q[0],q[2];
ccx q[1],q[2],q[0];
h q[0];
measure q[0] -> c[0];
error-correction phase-flip x-basis fault-tolerant
MIT — part of the OpenQC Algorithm Catalog.