This example demonstrates quantum error correction via "time-travel debugging" - rewinding quantum state history to fix bit-flip errors.
cargo run -p physics_examples --example quantum_counterfactualQuantum error correction is essential for:
- Fault-tolerant Quantum Computing: Qubits are fragile and need protection
- Quantum Memory: Long-term storage requires error mitigation
- Debugging Quantum Algorithms: Understanding where errors occur
This example shows how monadic state threading enables "debugging" by inspecting and rewinding history.
[t=1] Apply Gate → Simulate bit-flip error (|0⟩ → |1⟩)
↓
[t=2] Measure Syndrome → Detect P(|1⟩) > 0.9 → ERROR!
↓
[t=3] Rewind History → Pop bad state from history
↓
[t=4] Apply Correction → Apply X gate to restore |0⟩
↓
[VERIFY] Final State → P(|0⟩) = 0.98 → SUCCESS
The CausalEffectPropagationProcess carries a QuantumHistory state through the chain:
struct QuantumHistory {
states: Vec<HilbertState>, // History of quantum states
}Syndrome measurement checks if the qubit has flipped:
let prob_1 = current_state.as_inner().data()[1].norm_sqr();
if prob_1 > 0.9 {
// Error detected!
}"Time travel" by popping the corrupted state and applying correction:
hist.states.pop(); // Rewind
hist.states.push(corrected_state); // Apply fix- Multi-qubit systems: Extend
HilbertStateto more dimensions - Different error types: Simulate phase-flip or depolarizing errors
- Error correction codes: Implement Shor, Steane, or surface codes
- Continuous monitoring: Add periodic syndrome checks
CausalEffectPropagationProcess::with_state()- Thread state through computationHilbertState- Quantum state vector with complex amplitudes.bind()- Monadic composition of quantum operations