The Quantum Exact Simulation Toolkit is a high performance simulator of universal quantum circuits, state-vectors and density matrices. QuEST is written in C, hybridises OpenMP and MPI, and can run on a GPU. Needing only compilation, QuEST is easy to run both on laptops and supercomputers (in both C and C++), where it can take advantage of multicore, GPU-accelerated and networked machines to quickly simulate circuits on many qubits.
This library provides a safe wrapper around QuEST with an idiomatic Rust API.
To use quest-rs in your Rust codebase, first run:
bash
cargo add quest-rs
or add quest-rs
manually to your Cargo.toml
.
The API is simple: ```rust use quest_rs::{QuestEnv, QuReg};
let env = QuestEnv::new(); let mut qubits = QuReg::new(2, &env); qubits.initplusstate().hadamard(0).controllednot(0, 1); println!( "Probability amplitude of |11> *before* measurement is: {}", qubits.probabilityamplitude(0b11) ); qubits.measure(1); println!( "Probability amplitude of |11> after measurement is: {}", qubits.probability_amplitude(0b11) ); ```
The fluent API makes more complicated circuits easy to create: ```rust use quest_rs::{Complex, ComplexMatrix2, ComplexMatrixN, QReal, QuReg, QuestEnv, Vector};
let env = QuestEnv::new();
let mut qubits = QuReg::new(3, &env); qubits.initzerostate();
println!("Out environment is:"); qubits.report_params(); env.report();
// Set up the circuitry
let unitaryalpha = Complex::new(0.5, 0.5); let unitarybeta = Complex::new(0.5, -0.5);
let unitary_matrix = ComplexMatrix2 { real: [[0.5, 0.5], [0.5, 0.5]], imag: [[0.5, -0.5], [-0.5, 0.5]], };
let mut toffoligate = ComplexMatrixN::new(3); for i in 0..6 { toffoligate.setreal(i, i, 1.0); } toffoligate.setreal(6, 7, 1.0); toffoligate.set_real(7, 6, 1.0);
qubits .hadamard(0) .controllednot(0, 1) .rotatey(2, 0.1) .multicontrolledphaseflip(vec![0, 1, 2]) .unitary(0, unitarymatrix) .compactunitary(1, unitaryalpha, unitarybeta) .rotatearoundaxis(2, (3.14 / 2.0) as QReal, Vector::new(1.0, 0.0, 0.0)) .controlledcompactunitary(0, 1, unitaryalpha, unitarybeta) .multicontrolledunitary(vec![0, 1], 2, unitarymatrix) .multiqubitunitary(vec![0, 1, 2], toffoli_gate);
// Study the output
println!("Circuit output:"); println!("---------------"); println!("Probability amplitude of |111> is: {}", qubits.probabilityamplitude(0b111)); println!( "Probability of qubit 2 being in state 1: {}", qubits.calculateprobabilityofoutcome(2, 1) ); println!("Qubit 0 was measured in state: {}", qubits.measure(0)); let (outcome, outcomeprobability) = qubits.measurewithstats(2); println!( "Qubit 2 collapsed to {} with probability {}", outcome, outcomeprobability ); ```
For a starter template to get going with an executable project that uses this wrapper, see: https://github.com/drewsilcock/quest-rs-template.
The C QuEST library has several compile-option flags which should be supported using cargo features. These are: - what precision to operate in (single, double or quad) - whether to enable OpenMP, MPI, OpenMP+MPI or GPU
The documentation should also be expanded to include all the relevant info from the QuEST documentation.