Skip to main content

Module error_correction

Module error_correction 

Source
Expand description

Multi-qubit entangled-state preparation and 3-qubit quantum error correction.

This module collects two closely related primitives that underpin fault-tolerant quantum computing demos:

§Entangled state preparation

  • prepare_ghz — the n-qubit Greenberger–Horne–Zeilinger state (|0…0⟩ + |1…1⟩)/√2, built from one Hadamard plus a CNOT ladder.
  • prepare_w — the n-qubit W state, the equal superposition of all single-excitation basis vectors Σ_i |0…1_i…0⟩ / √n, built from a cascade of controlled Y-rotations.

§3-qubit repetition codes

All routines act on this crate’s little-endian StateVector (qubit i ↦ bit i), so the logical qubit is encoded across physical qubits 0, 1, 2.

Functions§

bit_flip_correct
Correct a single bit-flip error using the syndrome majority vote and return the index of the qubit that was corrected (None if no error detected).
bit_flip_encode
Encode a single logical qubit (state α|0⟩ + β|1⟩ on physical qubit 0) into the 3-qubit bit-flip repetition code α|000⟩ + β|111⟩.
phase_flip_correct
Correct a single phase-flip error by rotating back to the computational basis, running the bit-flip decoder, and returning to the ± basis.
phase_flip_encode
Encode a single logical qubit into the 3-qubit phase-flip repetition code α|+++⟩ + β|−−−⟩.
prepare_ghz
Prepare the n-qubit GHZ state (|0…0⟩ + |1…1⟩)/√2.
prepare_w
Prepare the n-qubit W state Σ_{i} |0…1_i…0⟩ / √n.