| Crates.io | qnect |
| lib.rs | qnect |
| version | 0.3.0 |
| created_at | 2025-07-31 19:38:08.469367+00 |
| updated_at | 2025-09-02 21:13:17.09106+00 |
| description | ā Quantum computing in Rust: from Bell pairs to distributed quantum networks. |
| homepage | https://github.com/theis-maker/qnect-rs |
| repository | https://github.com/theis-maker/qnect-rs |
| max_upload_size | |
| id | 1775592 |
| size | 553,497 |
Quantum computing in Rust: from Bell pairs to distributed quantum networks.
No config files. No magic. Just quantum.
Build quantum circuits, simulate massive systems, and create quantum networks - all with one powerful framework:
use qnect::{create, builder::BackendType};
use qnect::network::{QuantumNetwork, NetworkBuilder, Topology};
// Start simple...
let mut q = create().with_qubits(2).build()?;
q.h(0).await?;
q.cnot(0, 1).await?;
// ...or scale to 5000 qubits?
let mut q = create()
.with_backend(BackendType::Stabilizer)
.with_qubits(5000)
.build()?;
// ...or build quantum networks!
let mut network = QuantumNetwork::new_distributed();
network.add_node("Alice", 4);
network.add_node("Bob", 4);
// ...or use quantum hubs for routing!
let mut network = NetworkBuilder::new()
.with_topology(Topology::Star { hub_name: "Hub".into(), hub_capacity: 100 })
.add_hub("Hub", 100)
.add_endpoint("Alice", 10)
.add_endpoint("Bob", 10)
.build()?;
// Distribute entanglement through the hub
let (q1, q2) = network
.create_epr_pair_through_hub("Alice", "Bob", "Hub")
.await?;
cargo run[dependencies]
qnect = "0.3.0"
tokio = { version = "1", features = ["full"] }
use qnect::create;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut q = create().with_qubits(2).build()?;
q.h(0).await?; // Superposition
q.cnot(0, 1).await?; // Entanglement
let (m0, m1) = (q.measure(0).await?, q.measure(1).await?);
println!("Bell pair: |{}{}ā©", m0, m1); // Always 00 or 11
Ok(())
}
# See quantum mechanics in action
cargo run --example 03_simple_bell_pair
cargo run --example 00_quantum_verification # Verify Bell inequalities!
use qnect::create;
use std::f64::consts::PI;
let mut q = create().with_qubits(3).build()?;
// Alice's qubit to teleport
q.ry(0, PI/3.0).await?;
// Shared Bell pair
q.h(1).await?;
q.cnot(1, 2).await?;
// Teleportation protocol
q.cnot(0, 1).await?;
q.h(0).await?;
let (m0, m1) = (q.measure(0).await?, q.measure(1).await?);
// Bob's corrections
if m1 == 1 { q.x(2).await?; }
if m0 == 1 { q.z(2).await?; }
// State transferred to qubit 2!
use qnect::{create, builder::BackendType};
// Switch backends, same API
let mut q = create()
.with_backend(BackendType::Stabilizer)
.with_qubits(5000)
.build()?;
// Create massive GHZ state
q.h(0).await?;
for i in 1..5000 {
q.cnot(0, i).await?;
}
// |00000...ā© + |11111...ā© with only 12MB RAM!
use qnect::network::{NetworkBuilder, Topology, LinkType};
// Build a quantum data center in 3 lines
let mut network = NetworkBuilder::new()
.with_topology(Topology::Star {
hub_name: "DataCenter".into(),
hub_capacity: 100
})
.add_hub("DataCenter", 100)
.add_endpoint("Server1", 10)
.add_endpoint("Server2", 10)
.build()?;
// Servers can share entanglement through the hub
let (q1, q2) = network
.create_epr_pair_through_hub("Server1", "Server2", "DataCenter")
.await?;
use qnect::network::QuantumNetwork;
use qnect::network::LinkType;
use qnect::builder::BackendType;
// Build transcontinental quantum network with repeaters
let mut network = QuantumNetwork::new_distributed();
// Add cities as endpoints
network.add_distributed_node("London", 10, BackendType::Stabilizer)?;
network.add_distributed_node("Paris", 10, BackendType::Stabilizer)?;
network.add_distributed_node("Berlin", 10, BackendType::Stabilizer)?;
// Connect with quantum repeaters for long distances
network.add_quantum_link("London", "Paris",
LinkType::Fiber { length_km: 350.0, loss_db_per_km: 0.2 },
0.85, 100.0)?;
network.add_quantum_link("Paris", "Berlin",
LinkType::Fiber { length_km: 850.0, loss_db_per_km: 0.2 },
0.85, 100.0)?;
// Establish end-to-end entanglement through repeater
let (q1, q2) = network
.establish_end_to_end_entanglement("London", "Berlin")
.await?;
// Entanglement swapping at Paris enables London ā Berlin connection!
use qnect::{create, builder::{BackendType, NoiseModel}};
// Add realistic quantum errors
let mut q = create()
.with_backend(BackendType::StateVector)
.with_qubits(5)
.with_noise(NoiseModel {
depolarizing_rate: 0.01, // 1% gate error
measurement_error: 0.001 // 0.1% measurement error
})
.build()?;
Build a quantum chat application with QKD (Quantum Key Distribution):
// Terminal 1: Start quantum service
let service = QuantumService::new().await?;
service.run(6666).await?;
// Terminal 2: Run Paris repeater
let repeater = QuantumChatNode::new("Paris", NodeType::Repeater,
(48.8566, 2.3522)).await?;
repeater.listen(7001).await?;
// Terminal 3: Alice in London
let mut alice = QuantumChatNode::new("Alice", NodeType::Endpoint,
(51.5074, -0.1278)).await?;
alice.connect_to("Paris", "127.0.0.1:7001").await?;
let key = alice.run_bb84_alice("Bob", 128).await?; // QKD protocol!
alice.run_chat("Bob", key).await?; // Quantum-secured chat
// Terminal 4: Bob in Berlin
let mut bob = QuantumChatNode::new("Bob", NodeType::Endpoint,
(52.5200, 13.4050)).await?;
bob.connect_to("Paris", "127.0.0.1:7001").await?;
let key = bob.run_bb84_bob("Alice").await?;
bob.run_chat("Alice", key).await?;
This creates a quantum network where:
Based on Christandl & Wehner 2004 - impossible classically!
use qnect::network::{QuantumNetwork, LinkType};
// Create network with all participants
let participants = vec!["Alice", "Bob", "Charlie", "David", "Eve"];
let mut network = QuantumNetwork::new_distributed();
// Add all nodes (works with either mode)
for p in &participants {
network.add_node(p, 8);
}
// Create full mesh connectivity
network.add_multiparty_link(
participants.to_vec(),
LinkType::Fiber { length_km: 0.1, loss_db_per_km: 0.1 },
0.99, 10000.0
)?;
// Anonymous bit transmission
let parity = network
.anonymous_transmission("Alice", participants.to_vec(), 1)
.await?;
// Everyone knows bit 1 was sent, but not that Alice sent it!
// Anonymous entanglement
let (q1, q2) = network
.anonymous_entanglement("Alice", "Bob", participants.to_vec())
.await?;
// Alice and Bob share entanglement, untraceable by others
// Client delegates computation without revealing data
let pattern = BlindComputationPattern {
computation_graph: vec![(0, 1), (1, 2)],
measurement_angles: vec![0.5, 1.0, 1.5], // Encrypted
flow: vec![0, 1, 2],
};
let results = network
.blind_computation_ubqc("Client", "Server", pattern)
.await?;
// Server performed computation but learned nothing!
Build complex quantum networks with one line:
// Star - Quantum Data Centers
NetworkBuilder::new().with_topology(Topology::Star { hub_name: "DC".into(), hub_capacity: 100 })
// Ring - Metropolitan Networks
NetworkBuilder::new().with_topology(Topology::Ring)
// Mesh - Research Testbeds
NetworkBuilder::new().with_topology(Topology::Mesh { link_fidelity: 0.99 })
// Hierarchical - Internet Scale
NetworkBuilder::new().with_topology(Topology::Hierarchical {
central_hub: "Core".into(),
regional_hubs: vec!["NA".into(), "EU".into(), "APAC".into()],
})
// Unified backend trait - same for local and distributed
#[async_trait]
pub trait QuantumBackend: Send + Sync {
async fn apply_single_gate(&mut self, qubit: usize, gate: Gate1) -> Result<()>;
async fn apply_two_gate(&mut self, q1: usize, q2: usize, gate: Gate2) -> Result<()>;
async fn measure(&mut self, qubit: usize) -> Result<u8>;
}
Available Backends:
StateVector - Exact simulation (ā¤30 qubits)Stabilizer - Clifford circuits (5000+ qubits, O(n²) memory)MockQnpu - Hardware API testingNoisy - Wraps any backend with realistic errors# š Start Here
cargo run --example 03_simple_bell_pair # Your first quantum program
cargo run --example 00_quantum_verification # See Bell inequality violation
# š Learn Quantum
cargo run --example 04_quantum_teleportation
cargo run --example 17_grovers_search # Grover's algorithm
cargo run --example 18_stabilizer_demo # 5000 qubits!
cargo run --example 15_noise_models # Realistic quantum noise
# š Quantum Networks
cargo run --example quantum_hub_demo # Hub-based routing
cargo run --example network_builder_demo # Build topologies
cargo run --example quantum_topologies # All 5 topology types
cargo run --example quantum_qkd_chat # Secure chat with QKD
cargo run --example 22_quantum_anonymous_transmission # Anonymous protocols
# š Production Ready
cargo run --example 21_hardware_ready # NetQASM generation demo
cargo run --example 16_qasm_import # OpenQASM 2.0/3.0 support
| Backend | Max Qubits | Memory | Speed | Use Case |
|---|---|---|---|---|
| StateVector | ~30 | O(2āæ) | Exact | Research, small circuits |
| Stabilizer | 5000+ | O(n²) | 135k gates/sec | Error correction, large circuits |
| Noisy | Same as wrapped | Same as wrapped | ~5% overhead | Error modeling, noisy simulation |
| MockQnpu | Hardware | Minimal | Network-limited | Hardware testing |
For Beginners:
For Researchers:
For Production:
ā Released (v0.3.0)
š§ In Progress
š® Planned
We welcome contributions! Key areas:
MIT OR Apache-2.0
In quantum computing, the hardest part shouldn't be the framework.