# ruQu: Quantum Execution Intelligence Engine
A full-stack quantum computing platform in pure Rust: simulate, optimize, execute, correct, and verify quantum workloads across heterogeneous backends.
From circuit construction to hardware dispatch. From noise modeling to error correction. From approximate simulation to auditable science.
Overview • Layers • Modules • Try It • Coherence Gate • Tutorials • ruv.io
--- ## Platform Overview ruQu is not a simulator. It is a **quantum execution intelligence engine** -- a layered operating stack that decides *how*, *where*, and *whether* to run quantum workloads. Most quantum frameworks do one thing: simulate circuits. ruQu does five: | Capability | What It Means | How It Works | |------------|--------------|--------------| | **Simulate** | Run circuits on the right backend | Cost-model planner selects StateVector, Stabilizer, TensorNetwork, or Clifford+T based on circuit structure | | **Optimize** | Compile circuits for real hardware | Transpiler decomposes to native gate sets, routes qubits to physical topology, cancels redundant gates | | **Execute** | Dispatch to IBM, IonQ, Rigetti, Braket | Hardware abstraction layer with automatic fallback to local simulation | | **Correct** | Decode errors in real time | Union-find and subpolynomial partitioned decoders with adaptive code distance | | **Verify** | Prove results are correct | Cross-backend comparison, statistical certification, tamper-evident audit trails | ### What Makes It Different **Hybrid decomposition.** Large circuits are partitioned by entanglement structure -- Clifford-heavy regions run on the stabilizer backend (millions of qubits), low-entanglement regions run on tensor networks, and only the dense entangled core hits the exponential statevector. One 200-qubit circuit becomes three tractable simulations stitched probabilistically. **No mocks.** Every module runs real math. Noise channels apply real Kraus operators. Decoders run real union-find with path compression. The Clifford+T backend performs genuine Bravyi-Gosset stabilizer rank decomposition. The benchmark suite doesn't assert "it works" -- it proves quantitative advantages. **Coherence gating.** ruQu's original innovation: real-time structural health monitoring using boundary-to-boundary min-cut analysis. Before any operation, the system answers: "Is it safe to act?" This turns quantum computers from fragile experiments into self-aware machines. --- ## The Five Layers ``` Layer 5: Proof Suite benchmark.rs | Layer 4: Theory subpoly_decoder.rs, control_theory.rs | Layer 3: QEC Control Plane decoder.rs, qec_scheduler.rs | Layer 2: SOTA Differentiation planner.rs, clifford_t.rs, decomposition.rs | Layer 1: Scientific Instrument noise.rs, mitigation.rs, transpiler.rs, (9 modules) hardware.rs, qasm.rs, replay.rs, witness.rs, confidence.rs, verification.rs | Layer 0: Core Engine circuit.rs, gate.rs, state.rs, backend.rs, (existing) stabilizer.rs, tensor_network.rs, simulator.rs, simd.rs, optimizer.rs, types.rs, error.rs, mixed_precision.rs, circuit_analyzer.rs ``` --- ## Module Reference ### Layer 0: Core Engine (13 modules) The foundation: circuit construction, state evolution, and backend dispatch. | Module | Lines | Description | |--------|------:|-------------| | `circuit.rs` | 185 | Quantum circuit builder with fluent API | | `gate.rs` | 204 | Universal gate set: H, X, Y, Z, S, T, CNOT, CZ, SWAP, Rx, Ry, Rz, arbitrary unitaries | | `state.rs` | 453 | Complex128 statevector with measurement and partial trace | | `backend.rs` | 462 | Backend trait + auto-selector across StateVector, Stabilizer, TensorNetwork | | `stabilizer.rs` | 774 | Gottesman-Knill tableau simulator for Clifford circuits (unlimited qubits) | | `tensor_network.rs` | 863 | MPS-based tensor network with configurable bond dimension | | `simulator.rs` | 221 | Unified execution entry point | | `simd.rs` | 469 | AVX2/NEON vectorized gate kernels | | `optimizer.rs` | 94 | Gate fusion and cancellation passes | | `mixed_precision.rs` | 756 | f32/f64 adaptive precision for memory/speed tradeoff | | `circuit_analyzer.rs` | 446 | Static analysis: gate counts, Clifford fraction, entanglement profile | | `types.rs` | 263 | Shared type definitions | | `error.rs` | -- | Error types | ### Layer 1: Scientific Instrument (9 modules) Everything needed to run quantum circuits as rigorous science. | Module | Lines | Description | |--------|------:|-------------| | `noise.rs` | 1,174 | Kraus channel noise: depolarizing, amplitude damping (T1), phase damping (T2), readout error, thermal relaxation, crosstalk (ZZ coupling) | | `mitigation.rs` | 1,275 | Zero-Noise Extrapolation via gate folding + Richardson extrapolation; measurement error correction via confusion matrix inversion; Clifford Data Regression | | `transpiler.rs` | 1,210 | Basis gate decomposition (IBM/IonQ/Rigetti gate sets), BFS qubit routing on hardware topology, gate cancellation optimization | | `hardware.rs` | 1,764 | Provider trait HAL with adapters for IBM Quantum, IonQ, Rigetti, Amazon Braket + local simulator fallback | | `qasm.rs` | 967 | OpenQASM 3.0 export with ZYZ Euler decomposition for arbitrary single-qubit unitaries | | `replay.rs` | 556 | Deterministic replay engine -- seeded RNG, state checkpoints, circuit hashing for exact reproducibility | | `witness.rs` | 724 | SHA-256 hash-chain witness logging -- tamper-evident audit trail with JSON export and chain verification | | `confidence.rs` | 932 | Wilson score intervals, Clopper-Pearson exact bounds, chi-squared goodness-of-fit, total variation distance, shot budget calculator | | `verification.rs` | 1,190 | Automatic cross-backend comparison with statistical certification (exact/statistical/trend match levels) | ### Layer 2: SOTA Differentiation (3 modules) Where ruQu separates from every other framework. | Module | Lines | Description | |--------|------:|-------------| | `planner.rs` | 1,393 | **Cost-model circuit router** -- predicts memory, runtime, fidelity for each backend. Selects optimal execution plan with verification policy and mitigation strategy. Entanglement budget estimation. | | `clifford_t.rs` | 996 | **Extended stabilizer simulation** via Bravyi-Gosset low-rank decomposition. T-gates double stabilizer terms (2^t scaling). Bridges the gap between Clifford-only (unlimited qubits) and statevector (32 qubits). | | `decomposition.rs` | 1,409 | **Hybrid circuit partitioning** -- builds interaction graph, finds connected components, applies spatial/temporal decomposition. Classifies segments by gate composition. Probabilistic result stitching. | ### Layer 3: QEC Control Plane (2 modules) Real-time quantum error correction infrastructure. | Module | Lines | Description | |--------|------:|-------------| | `decoder.rs` | 1,923 | **Union-find decoder** O(n*alpha(n)) + partitioned tiled decoder for sublinear wall-clock scaling. Adaptive code distance controller. Logical qubit allocator for surface code patches. Built-in benchmarking. | | `qec_scheduler.rs` | 1,443 | Surface code syndrome extraction scheduling, feed-forward optimization (eliminates unnecessary classical dependencies), dependency graph with critical path analysis. | ### Layer 4: Theoretical Foundations (2 modules) Provable complexity results and formal analysis. | Module | Lines | Description | |--------|------:|-------------| | `subpoly_decoder.rs` | 1,207 | **HierarchicalTiledDecoder**: recursive multi-scale tiling achieving O(d^(2-epsilon) * polylog(d)). **RenormalizationDecoder**: coarse-grain syndrome lattice across log(d) scales. **SlidingWindowDecoder**: streaming decode for real-time QEC. **ComplexityAnalyzer**: provable complexity certificates. | | `control_theory.rs` | 433 | QEC as discrete-time control system -- stability conditions, resource optimization, latency budget planning, backlog simulation, scaling laws for classical overhead and logical error suppression. | ### Layer 5: Proof Suite (1 module) Quantitative evidence that the architecture delivers measurable advantages. | Module | Lines | Description | |--------|------:|-------------| | `benchmark.rs` | 790 | **Proof 1**: cost-model routing beats naive and heuristic selectors. **Proof 2**: entanglement budgeting enforced as compiler constraint. **Proof 3**: partitioned decoder shows measurable latency gains vs union-find. **Proof 4**: cross-backend certification with bounded TVD error guarantees. | ### Totals | Metric | Value | |--------|-------| | Total modules | 30 | | Total lines of Rust | 24,676 | | New modules (execution engine) | 20 | | New lines (execution engine) | ~20,000 | | Simulation backends | 5 (StateVector, Stabilizer, TensorNetwork, Clifford+T, Hardware) | | Hardware providers | 4 (IBM Quantum, IonQ, Rigetti, Amazon Braket) | | Noise channels | 6 (depolarizing, amplitude damping, phase damping, readout, thermal, crosstalk) | | Mitigation strategies | 3 (ZNE, MEC, CDR) | | Decoder algorithms | 5 (union-find, tiled, hierarchical, renormalization, sliding-window) | --- ## Coherence Gating ruQu's original capability: a **classical nervous system** for quantum machines. Real-time structural health monitoring that answers one question before every operation: *"Is it safe to act?"* ``` Syndrome Stream --> [Min-Cut Analysis] --> PERMIT / DEFER / DENY | "Is the error pattern structurally safe?" ``` | Decision | Meaning | Action | |----------|---------|--------| | **PERMIT** | Errors scattered, structure healthy | Full-speed operation | | **DEFER** | Borderline, uncertain | Proceed with caution, reduce workload | | **DENY** | Correlated errors, structural collapse risk | Quarantine region, isolate failure | ### Why Coherence Gating Matters **Without ruQu**: Quantum computer runs blind until logical failure -> full reset -> lose all progress. **With ruQu**: Quantum computer detects structural degradation *before* failure -> isolates damaged region -> healthy regions keep running. ### Validated Results | Metric | Result (d=5, p=0.1%) | |--------|---------------------| | Median lead time | 4 cycles before failure | | Recall | 85.7% | | False alarms | 2.0 per 10k cycles | | Actionable (2-cycle mitigation) | 100% | ### Performance | Metric | Target | Measured | |--------|--------|----------| | Tick P99 | <4,000 ns | 468 ns | | Tick Average | <2,000 ns | 260 ns | | Merge P99 | <10,000 ns | 3,133 ns | | Min-cut query | <5,000 ns | 1,026 ns | | Throughput | 1M/sec | 3.8M/sec | | Popcount (1024 bits) | -- | 13 ns (SIMD) | --- ## Try It in 5 Minutes ### Option 1: Add to Your Project ```bash cargo add ruqu --features structural ``` ```rust use ruqu::{QuantumFabric, FabricBuilder, GateDecision}; fn main() -> Result<(), ruqu::RuQuError> { let mut fabric = FabricBuilder::new() .num_tiles(256) .syndrome_buffer_depth(1024) .build()?; let syndrome_data = [0u8; 64]; // From your quantum hardware let decision = fabric.process_cycle(&syndrome_data)?; match decision { GateDecision::Permit => println!("Safe to proceed"), GateDecision::Defer => println!("Proceed with caution"), GateDecision::Deny => println!("Region unsafe"), } Ok(()) } ``` ### Option 2: Run the Interactive Demo ```bash git clone https://github.com/ruvnet/ruvector cd ruvector cargo run -p ruqu --bin ruqu_demo --release -- --distance 5 --rounds 1000 --error-rate 0.01 ``` ### Option 3: Use the Quantum Execution Engine (ruqu-core) ```rust use ruqu_core::circuit::QuantumCircuit; use ruqu_core::planner::{plan_execution, PlannerConfig}; use ruqu_core::decomposition::decompose; // Build a circuit let mut circ = QuantumCircuit::new(10); circ.h(0); for i in 0..9 { circ.cnot(i, i + 1); } // Plan: auto-selects optimal backend let plan = plan_execution(&circ, &PlannerConfig::default()); // Or decompose for multi-backend execution let partition = decompose(&circ, 25); ``` --- ## Feature Flags | Feature | What It Enables | When to Use | |---------|----------------|-------------| | `structural` | Real O(n^{o(1)}) min-cut algorithm | Default -- always recommended | | `decoder` | Fusion-blossom MWPM decoder | Surface code error correction | | `attention` | 50% FLOPs reduction via coherence routing | High-throughput systems | | `simd` | AVX2 vectorized bitmap operations | x86_64 performance | | `full` | All features enabled | Production deployments | --- ## Ecosystem | Crate | Description | |-------|-------------| | [`ruqu`](https://crates.io/crates/ruqu) | Coherence gating + top-level API | | [`ruqu-core`](https://crates.io/crates/ruqu-core) | Quantum execution engine (30 modules, 24K lines) | | [`ruqu-algorithms`](https://crates.io/crates/ruqu-algorithms) | VQE, Grover, QAOA, surface code algorithms | | [`ruqu-exotic`](https://crates.io/crates/ruqu-exotic) | Quantum-classical hybrid algorithms | | [`ruqu-wasm`](https://crates.io/crates/ruqu-wasm) | WebAssembly bindings | --- ## TutorialsruQu -- Quantum execution intelligence in pure Rust.
Built by ruv.io