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
68
69
70
//! A Rust library for building and running quantum circuit simulations.
//!
//! This crate provides the tools to build, simulate, and measure quantum circuits.
//! The primary entry point is the [`QuantumSimulator`], which manages the state
//! and execution of a [`Circuit`]. Circuits themselves are constructed from the
//! fundamental building blocks defined in the [`Gate`] enum.
//!
//! The simulator's behavior is rigorously tested against Qiskit to ensure correctness.
//!
//! ## Getting Started
//!
//! Here is a quick example that creates a 3-qubit GHZ state (`(|000⟩ + |111⟩)/√2`),
//! a classic example of quantum entanglement.
//!
//! ```rust
//! use rand::{rngs::SmallRng, SeedableRng};
//!
//! use qvass::{QuantumSimulator, Gate, QubitError};
//!
//! fn main() -> Result<(), QubitError> {
//! // 1. Create a simulator for a 3-qubit system.
//! let mut sim = QuantumSimulator::new(3);
//!
//! // 2. Build the circuit to create the GHZ state.
//! sim.add_gate(Gate::hadamard(), [0])?;
//! sim.add_gate(Gate::cnot(), [0, 1])?;
//! sim.add_gate(Gate::cnot(), [0, 2])?;
//!
//! // 3. Create a seeded RNG for reproducible measurements.
//! // For a real simulation, you might seed this from the system time.
//! let mut rng = SmallRng::seed_from_u64(123);
//!
//! // 4. Start from the |000⟩ state, run the simulation, and measure.
//! sim.init_state(0);
//! sim.run();
//! let outcome = sim.measure(&mut rng);
//!
//! // After measurement, the state will be either |000⟩ (index 0)
//! // or |111⟩ (index 7), with a 50/50 chance for each.
//! println!("Measured state: |{}>", outcome);
//! assert!(outcome == 0 || outcome == 7);
//!
//! Ok(())
//! }
//! ```
extern crate alloc;
extern crate std;
pub use ;
pub use Gate;
pub use QuantumSimulator;
// To run doc tests on examples from README.md and verify their correctness
;