Skip to main content

Crate tpt_sci_quantum

Crate tpt_sci_quantum 

Source
Expand description

§tpt-sci-quantum

A from-scratch qubit state-vector simulator for the tpt-science pillar.

The simulator represents an n-qubit pure state as a length-2^n vector of complex amplitudes (in the computational basis |0...0> … |1...1>). Gates are applied in place by iterating over the relevant pairs of basis states, and measurement samples a basis index from the Born rule distribution.

No external quantum-simulation crates are used: the linear algebra is just complex scalars and explicit index arithmetic over the amplitude vector.

§Examples

Build the Bell state |Φ+⟩ = (|00⟩ + |11⟩)/√2 and check its marginals:

use tpt_sci_quantum::State;

let mut state = State::new(2).unwrap();
state.h(0).unwrap();
state.cnot(0, 1).unwrap();

let p = state.probabilities();
assert!((p[0] - 0.5).abs() < 1e-9);
assert!((p[3] - 0.5).abs() < 1e-9);

Re-exports§

pub use tensor::Circuit;
pub use tensor::embed_gate_2x2;
pub use tensor::kron;
pub use density::DensityMatrix;
pub use density::Matrix;
pub use error::StateError;

Modules§

density
Density-matrix representation and Kraus-channel noise application. Density-matrix representation and Kraus-channel noise application.
error
Errors produced by state construction and gate application. Errors produced by state construction and gate application.
tensor
Tensor-product (Kronecker) circuit formulation built on tpt-math-linalg. Tensor-product (Kronecker) formulation of qubit circuits.

Structs§

State
A pure n-qubit state stored as a length-2^n amplitude vector.

Constants§

H
Hadamard gate H = (1/√2)·[[1,1],[1,-1]].
S
Phase gate S = [[1,0],[0,i]].
T
π/4 (T) gate T = [[1,0],[0,e^{iπ/4}]].
X
Pauli-X (bit-flip) gate X = [[0,1],[1,0]].
Y
Pauli-Y gate Y = [[0,-i],[i,0]].
Z
Pauli-Z (phase-flip) gate Z = [[1,0],[0,-1]].