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— then-qubit Greenberger–Horne–Zeilinger state(|0…0⟩ + |1…1⟩)/√2, built from one Hadamard plus a CNOT ladder.prepare_w— then-qubit W state, the equal superposition of all single-excitation basis vectorsΣ_i |0…1_i…0⟩ / √n, built from a cascade of controlledY-rotations.
§3-qubit repetition codes
bit_flip_encode/bit_flip_correct— protect against a singleXerror by majority vote over the syndrome{Z₀Z₁, Z₁Z₂}.phase_flip_encode/phase_flip_correct— the Hadamard-conjugated code protecting against a singleZerror.
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 (
Noneif no error detected). - bit_
flip_ encode - Encode a single logical qubit (state
α|0⟩ + β|1⟩on physical qubit0) 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.