3-Qubit Phase-Flip Code
Overview
The 3-qubit phase-flip code protects against single Z (phase-flip) errors by encoding one logical qubit into three physical qubits in the Hadamard basis. It is the exact dual of the bit-flip code: where the bit-flip code protects |0>/|1> against X errors, the phase-flip code protects |+>/|-> against Z errors.
Duality with Bit-Flip Code
The phase-flip code is obtained by conjugating the entire bit-flip code with Hadamard gates. This duality is one of the most elegant ideas in quantum error correction:
| Property | Bit-Flip Code | Phase-Flip Code |
|---|---|---|
| Protects against | X errors (bit-flip) | Z errors (phase-flip) |
| Encoding basis | Computational (Z) | Hadamard (X) |
| |0>_L | |000> | |+++> |
| |1>_L | |111> | |---> |
| Syndrome checks | Z-basis parity | X-basis parity |
| Correction gate | X | Z |
| Transform | Identity | H before/after syndrome |
Key insight: A Z error flips |+> to |-> (and vice versa), which is exactly a "bit-flip in the X basis." So we apply H to all qubits, use the standard parity check, then apply H again.
Encoding
| Logical State | Physical State |
|---|---|
| |0>_L | |+++> = ((|0>+|1>)/sqrt(2))^3 |
| |1>_L | |---> = ((|0>-|1>)/sqrt(2))^3 |
Encoding Circuit
CODE┌───┐ ┌───┐ q_0: ┤ X ├──■────■──┤ H ├ └───┘┌─┴─┐ │ ├───┤ q_1: ─────┤ X ├──┼──┤ H ├ └───┘┌─┴─┐├───┤ q_2: ──────────┤ X ├┤ H ├ └───┘└───┘
- Prepare logical state on qubit 0 (X gate for |1>)
- Spread via CX gates (creates GHZ state in Z basis)
- Apply H to all qubits (rotates to X basis)
The Hadamard Trick
The syndrome extraction works by temporarily converting back to the computational basis:
CODE┌───┐ ┌───┐ d0: ┤ H ├──■─────────────────┤ H ├ (data qubits) ├───┤ │ ├───┤ d1: ┤ H ├──┼────■────■───────┤ H ├ ├───┤ │ │ │ ├───┤ d2: ┤ H ├──┼────┼────┼────■──┤ H ├ └───┘┌─┴─┐┌─┴─┐ │ │ └───┘ s0: ─────┤ X ├┤ X ├──┼────┼─────── (syndrome ancillae) └───┘└───┘┌─┴─┐┌─┴─┐ s1: ───────────────┤ X ├┤ X ├───── └───┘└───┘
This is the same parity check as the bit-flip code, sandwiched between H gates: s0 measures the parity of d0 and d1, and s1 measures the parity of d1 and d2 (each in the Hadamard basis).
Syndrome Table
Syndrome bits are shown in Qiskit's printed order (s1 s0), as on the bit-flip page.
| Syndrome | Error Location | Correction |
|---|---|---|
| 00 | No error | None |
| 01 | Qubit 0 | Z on q0 |
| 10 | Qubit 2 | Z on q2 |
| 11 | Qubit 1 | Z on q1 |
Running the Circuit
PYTHONfrom circuit import run_circuit, verify_phase_flip_code # No error result = run_circuit(error_qubit=None) print(f"Success: {result['success_rate']:.2%}") # Inject Z error on qubit 1 result = run_circuit(error_qubit=1) print(f"Corrected: {result['success_rate']:.2%}") # Full verification v = verify_phase_flip_code() for check in v["checks"]: print(f"[{'PASS' if check['passed'] else 'FAIL'}] {check['name']}")
Expected Output
| Scenario | Success Rate |
|---|---|
| No error | ~100% |
| Single Z error | ~100% (corrected) |
| Two Z errors | ~0% (uncorrectable) |
| Single X error | ~100% in this test, but only because it encodes |0>_L or |1>_L: the X error is not detected (syndrome 00) and acts as a logical phase flip, so an encoded superposition such as |+>_L becomes |->_L |
Limitations
- Only corrects Z errors: X (bit-flip) errors are not corrected
- Single error only: Two or more Z errors cause failure
- Not universal: Need combined code (Shor code) for both X and Z
Building to Shor Code
The Shor code combines bit-flip and phase-flip codes:
- Inner code: 3-qubit bit-flip code (protects each block against X)
- Outer code: 3-qubit phase-flip code (protects across blocks against Z)
- Result: 9-qubit code protecting against any single-qubit error