DEV Community

Cover image for A Bell State in Rust: What Sirraya QuTub Actually Does
Amir Hameed
Amir Hameed

Posted on

A Bell State in Rust: What Sirraya QuTub Actually Does


If you're a Rust developer, quantum computing has mostly happened in someone else's language. The simulators people use for research are built in Python or C++. If you wanted to explore quantum circuits without leaving the Rust ecosystem, your options were thin. Bindings to foreign runtimes. Abandoned crates. Academic code that doesn't compile on stable.
Sirraya QuTub is a full quantum simulation stack in Rust. State vectors. Density matrices. Noise channels calibrated to real hardware. Entanglement measures implemented against the literature. All in one crate. Add it with cargo add sirraya-qutub and you're done.

But the question isn't whether another quantum simulator exists. The question is whether you can read the source, understand what every layer is doing, and extend it yourself - without leaving your language.
This post walks through a single Rust program: creating a Bell state, measuring it, examining its density matrix, quantifying its entanglement, and watching what happens when you lose a qubit. No physics background assumed. Every number in the output gets explained.

The Program

A Bell state is the simplest entangled quantum state: two qubits perfectly correlated. Measure one, and you instantly know the other. It's the "hello world" of quantum computing.

Here's the entire program:

use sirraya_qutub::core::{create_bell_state, DensityMatrix};
fn main() -> Result<(), String> {
let bell = create_bell_state()?;
bell.print_state();
let distribution = bell.get_probability_distribution();
for (state, prob) in &distribution {
println!(" |{}⟩: {:.4}", state, prob);
}
let density = DensityMatrix::from_state_vector(bell.get_state_vector())?;
density.print_density_matrix();
println!(" Purity: {:.4} (1.0 = pure)", density.purity());
println!(" Concurrence: {:.4} (1.0 = max entangled)", density.concurrence()?);
println!(" Negativity: {:.4} (>0 certifies entanglement)", density.negativity(&[1])?);
let reduced = density.partial_trace(&[0])?;
println!(" Reduced purity: {:.4} (0.5 = maximally mixed)", reduced.purity());
println!(" Entropy: {:.4} bits (1.0 = one ebit)", reduced.von_neumann_entropy());
Ok(())
}

That's it. Fifty lines including imports and print statements. Here's what it produces and what every number means.

The Output, Line by Line

State vector:

|00⟩: 0.707107 (probability: 0.500000)
|11⟩: 0.707107 (probability: 0.500000)

0.707107 is 1/√2. The state is an equal superposition of |00⟩ and |11⟩. Both outcomes are equally likely, and you will never see |01⟩ or |10⟩. The two qubits are linked.

Density matrix

0.500000 0.000000 0.000000 0.500000
0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000
0.500000 0.000000 0.000000 0.500000

A state vector tells you amplitudes. A density matrix tells you everything: probabilities on the diagonal, quantum coherence in the off-diagonal entries. Those 0.5 values in the corners are the signature of a coherent superposition - the state is |00⟩ and |11⟩ simultaneously, not a classical coin flip between them.

Entanglement measures:
Purity: 1.0000 (1.0 = pure)
Concurrence: 1.0000 (1.0 = maximally entangled)
Negativity: 0.5000 (>0 certifies entanglement)

Three independent measures, three confirmations. Purity of 1.0 means the state is perfectly known - no noise, no missing information. Concurrence of 1.0 is the theoretical maximum for two-qubit entanglement. Negativity of 0.5 comes from the partial transpose eigenvalues {0.5, 0.5, 0.5, -0.5} - the sum of the negative parts tells you entanglement exists and quantifies it.

After losing qubit 1:

Reduced purity: 0.5000 (0.5 = maximally mixed)
Entropy: 1.0000 bits (1.0 = one ebit of entanglement)

This is the key result. Start with a pure Bell state. Trace out one qubit - physically, lose access to it. The remaining qubit is now maximally mixed. You know nothing about it. It's a perfect 50/50 coin flip with 1.0 bits of entropy - the maximum possible for a single qubit.

A pure entangled state has a mixed reduced state. The whole is definite. The parts are maximally uncertain. The information isn't stored in either qubit. It's stored in the correlations between them. That's quantum entanglement in one sentence.

Why This Matters for a Rust Developer

None of this required understanding the linear algebra underneath. The API exposes physical concepts directly: purity(), concurrence(), negativity(), partial_trace(), von_neumann_entropy(). Each method name matches the literature term. Each returns a number with a clear physical interpretation.

This is the design philosophy: if a quantum operation is being simulated, the implementation should be understandable, inspectable, and reproducible. The simulator is not a black box.

For Rust developers, this means you can explore quantum computing the way you explore any other Rust crate. Read the source. Run the tests. Modify the examples. Extend the gates. Add noise and watch what happens to entanglement. Build a GHZ state and compare it to a W state. Implement a VQE ansatz using the Ising coupling gates. The barrier to entry is cargo add sirraya-qutub and curiosity.

Where This Is Going

The Bell state is tiny. The ideas behind it are not.

What matters with QuTub isn't simply having another simulator. It's having a transparent foundation that developers, researchers, and students can inspect and build on. The crate currently ships with a full state-vector simulator, density-matrix noise simulation with hardware-calibrated channels, entanglement measures with literature-backed implementations, Pauli-string observables for VQE, quantum Fourier transform, quantum reservoir computing, and cross-entropy benchmarking validation.

The next major step is the QuTub transpiler: the layer that decomposes abstract quantum gates into native hardware gate sets, optimizes the resulting circuit, and enables meaningful per-gate noise simulation calibrated to real hardware fidelity figures. That layer is under active development at Sirraya Labs.

We're building this openly, one layer at a time.

Sirraya QuTub is available on crates.io. Full documentation at docs.rs/sirraya-qutub. Licensed under MIT.

Top comments (0)