Skip to main content

Crate qsimulator

Crate qsimulator 

Source
Expand description

§qsimulator

A quantum circuit simulator: gates, mid-circuit measurement and reset, classical feed-forward, and noise.

There are two backends, and they check each other. state::State carries a 2^n state vector, reaching about 30 qubits, and simulates a noise channel by sampling one Kraus operator per shot — so noisy results converge as 1/sqrt(shots). density::DensityMatrix carries the 2^n x 2^n mixture instead, which makes channels, measurement and feed-forward exact at the cost of reaching about half as far.

The crate exposes these main pieces:

use qsimulator::Circuit;

let mut c = Circuit::new(2);
c.h(0).cnot(0, 1); // Bell state
let state = c.run();
assert!((state.probability(0b00) - 0.5).abs() < 1e-12);
assert!((state.probability(0b11) - 0.5).abs() < 1e-12);

The same circuit under noise, exactly rather than sampled:

use qsimulator::Circuit;

let mut c = Circuit::new(2);
c.h(0).cnot(0, 1).depolarizing(0.1, 0);
let rho = c.run_density().unwrap();

// Still normalized, but no longer a pure state.
assert!((rho.trace() - 1.0).abs() < 1e-12);
assert!(rho.purity() < 1.0);

Re-exports§

pub use circuit::Circuit;
pub use circuit::DensityError;
pub use circuit::ExportError;
pub use error::ParseError;
pub use rng::Rng;
pub use state::State;

Modules§

circuit
Circuit builder and executor.
density
Density-matrix representation, for exact noise.
error
Error types for the text and OpenQASM front ends.
gates
Standard single-qubit gate matrices.
noise
Single-qubit noise channels, as sets of Kraus operators.
program
A tiny line-based program format for describing circuits as text, so the CLI can run a circuit without recompiling.
qasm
A small OpenQASM 2.0 subset importer.
qasm3
OpenQASM 3 support, by normalizing into the OpenQASM 2 subset.
rng
A tiny, seedable, dependency-free pseudo-random number generator.
state
State-vector representation of an n-qubit register.