1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! # 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:
//! - [`circuit::Circuit`] — a builder that sequences operations and runs them,
//! via [`run`](circuit::Circuit::run), [`sample`](circuit::Circuit::sample)
//! or [`run_density`](circuit::Circuit::run_density).
//! - [`state::State`] — the `2^n` complex amplitude vector of an `n`-qubit
//! register.
//! - [`density::DensityMatrix`] — the density-matrix backend, for exact noise.
//! - [`gates`] — unitary matrices for the standard gate set.
//! - [`noise`] — the standard single-qubit channels, as Kraus operators.
//! - [`rng::Rng`] — a seedable RNG, so sampling is reproducible.
//! - [`program`], [`qasm`] and [`qasm3`] — the text, OpenQASM 2 and OpenQASM 3
//! front ends.
//!
//! ```
//! 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);
//! ```
pub use ;
pub use ParseError;
pub use Rng;
pub use State;