ruvector-neural-decoder
Neural Quantum Error Decoder (NQED) - GNN-based quantum error correction with O(d²) Mamba architecture
Overview
ruvector-neural-decoder implements a neural network-based quantum error decoder that combines Graph Neural Networks (GNN) with Mamba state-space models for efficient syndrome decoding on surface codes.
Key Features
- Graph Attention Encoder: Multi-head attention over syndrome graphs with learned positional encodings
- Mamba O(d²) Decoder: Linear-time sequence modeling via selective state spaces (vs O(d⁴) transformers)
- Min-Cut Feature Fusion: Integrates structural coherence signals from
ruvector-mincut - Pure Rust: No external ML frameworks - uses
ndarrayfor tensor operations - WASM Compatible: Designed for browser and edge deployment
Installation
Add to your Cargo.toml:
[]
= "0.1"
Quick Start
use ;
// Create decoder for distance-5 surface code
let config = DecoderConfig ;
let mut decoder = new;
// Decode a syndrome (9 stabilizers for d=5 rotated surface code)
let syndrome = vec!;
let correction = decoder.decode?;
println!;
println!;
Architecture
┌─────────────────────────────────────────────────────────────┐
│ NQED Pipeline │
├─────────────────────────────────────────────────────────────┤
│ │
│ Syndrome ┌──────────────┐ ┌──────────────┐ │
│ Round ────► │ Syndrome→ │───►│ GNN Encoder │ │
│ │ DetectorGraph│ │ (GraphRoPE) │ │
│ └──────────────┘ └──────┬───────┘ │
│ │ │
│ ▼ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ Min-Cut │───►│ Feature │ │
│ │ Engine │ │ Fusion │ │
│ └──────────────┘ └──────┬───────┘ │
│ │ │
│ ▼ │
│ ┌──────────────┐ ┌──────┐│
│ │ Mamba │─►│Corr- ││
│ │ Decoder │ │ection││
│ └──────────────┘ └──────┘│
└─────────────────────────────────────────────────────────────┘
Module Overview
| Module | Description |
|---|---|
graph |
Syndrome → DetectorGraph construction for surface codes |
gnn |
Graph attention encoder with multi-head attention |
mamba |
O(d²) state-space decoder with selective scan |
fusion |
Feature fusion with min-cut structural signals |
error |
Comprehensive error types |
Step 1: Configure the Decoder
use ;
let config = DecoderConfig ;
let mut decoder = new;
Step 2: Build a Detector Graph Manually
use ;
// Create a d=3 surface code graph
let graph = new
.with_distance
.add_node?
.add_node?
.add_node?
.add_node?
.connect_grid? // Auto-connect adjacent stabilizers
.build?;
println!;
Step 3: Process Multiple Syndrome Rounds
// Sequential decoding for time-series syndromes
let syndromes = vec!;
for in syndromes.iter.enumerate
Step 4: Access Intermediate Representations
use GNNEncoder;
let gnn = new;
let graph = from_surface_code
.with_syndrome?
.build?;
// Get node embeddings before Mamba decoding
let embeddings = gnn.encode?;
println!;
// Get attention weights from last layer
let attention_weights = gnn.last_attention_weights;
Enable ruQu Integration
[]
= { = "0.1", = ["ruqu-integration"] }
Use with QuantumFabric
use ;
use NeuralDecoder;
// Create fabric with neural decoder backend
let fabric = new
.with_neural_decoder?;
// Process syndrome cycle with coherence assessment
let syndrome_round = from_measurements?;
let decision = fabric.process_cycle_neural?;
match decision.gate
Benchmark Results (AMD Ryzen 9, 64GB RAM)
| Operation | d=5 | d=7 | d=11 | Target |
|---|---|---|---|---|
| GNN Forward | 2.8μs | 4.8μs | 9.8μs | <100μs |
| Mamba Decode | 1.2μs | 2.1μs | 3.9μs | <50μs |
| Full Pipeline | 4.5μs | 7.2μs | 14.1μs | <150μs |
vs Classical Decoders
| Decoder | d=11 Latency | Accuracy (p=0.005) |
|---|---|---|
| MWPM | 45μs | 98.2% |
| Union-Find | 12μs | 97.8% |
| NQED | 14μs | 98.7%* |
*Projected based on AlphaQubit scaling
Run Benchmarks
Run All Tests
Test Categories
- Unit tests: 61 tests covering all modules
- Property tests: 14 proptest-based invariant checks
- Integration tests: End-to-end pipeline validation
Key Test Coverage
| Module | Tests | Coverage |
|---|---|---|
graph |
18 | Graph construction, adjacency, syndrome mapping |
gnn |
16 | Attention, normalization, forward pass |
mamba |
15 | State updates, sequential decode, reset |
fusion |
12 | Feature fusion, boundary computation |
API Reference
Core Types
/// Decoder configuration
/// Correction output
Error Handling
All operations return Result<T, NeuralDecoderError>:
References
- AlphaQubit: Neural decoders for quantum error correction
- Mamba: Linear-Time Sequence Modeling
- GNNs for Quantum Error Correction
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.