Skip to content

Latest commit

History

19 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

rquant

rustc (with version)crate.rs (with version)docs.rs (with version)

A quantum computing library written entirely in rust.

It allows for qubit measurement and basic quantum logic in complex vector space. Gates can be applied to qubits in complex vector space, then those qubits can be measured to observe the outcome.

Getting Started

  1. Download the repo
  2. Open a terminal and navigate to the repo root
  3. Run cargo run to see the output of the (very simple) main function
  4. Run cargo test to run all the tests
  5. Run cargo doc --no-deps to generate the docs

Examples

Creating a qubit

You can create a qubit by using one of the premade qubits, or using a premade quantum position:

use rquant::{
log_info,
quantum::types::{quantum_position::QuantumPosition, qubit::Qubit},};fnmain(){// create a zero qubit: |0>let zero_qubit = Qubit::zero();log_info!("Zero qubit: {zero_qubit}");// create an identity qubit: |1>let identity_qubit = Qubit::one();log_info!("Zero qubit: {identity_qubit}");// create a custom qubit using a quantum position:// 0+1i|0>let custom_qubit = Qubit::new(QuantumPosition::QUARTER_TURN);log_info!("Custom qubit: {custom_qubit}");}

This example will produce the following output:

A screenshot of console output from qubit creation using the rquant rust crate

Applying gates to qubits

You can apply a gate to a single qubit:

use rquant::{
log_info,
quantum::types::{quantum_gate::QuantumGate, qubit::Qubit},};fnmain(){// use the '!' operator to apply the FLIP gatelet flipped_zero_qubit = !Qubit::zero();log_info!("Flipped zero qubit: {flipped_zero_qubit}");// use premade quantum gates to modify a qubitlet rotated_qubit = Qubit::one().apply_gate(&QuantumGate::PHASE).apply_gate(&QuantumGate::ROTATE);log_info!("Rotated identity qubit: {rotated_qubit}");}

This example will produce the following output:

A screenshot of console output from applying a gate to a qubit using the rquant rust crate

Create multiple associated qubits

You can create a collection of many qubits using a qubit register:

use rquant::{
log_info,
quantum::types::{quantum_gate::QuantumGate, qubit_register::QubitRegister},};fnmain(){// create a register of 100 qubits with the |0> statelet qubit_register = QubitRegister::new(10);log_info!("Qubit register:\n{qubit_register}");// get the amount of qubits in the qubit registerlet qubit_count = qubit_register.len();log_info!("There are {qubit_count} qubits in the register.");// get a (zero-indexed) qubit from the registerlet fifth_qubit = qubit_register
.get(4).expect("There was no fifth qubit in the register.");log_info!("The fifth qubit in the register: {fifth_qubit}");// modify the fifth qubit by applying the PHASE gatelet phased_fifth_qubit = fifth_qubit.apply_gate(&QuantumGate::ROTATE);log_info!("Phased fifth qubit: {phased_fifth_qubit}\n");}

This example will produce the following output:

A screenshot of console output from creating a qubit register using the rquant rust crate

Run simulations on qubits

You can simulate and report on behavior on any amount of qubits:

use rquant::{
quantum::types::qubit::Qubit,
simulation::types::{simulation::Simulation, simulation_report::SimulationReport},};fnmain(){// create 1,000,000 superpositioned qubits, and observe// their measurements using the report function.Qubit::one().simulate_superposition(1000000).report(Qubit::one());}

This example will produce the following output:

A screenshot of console output from qubit simulation using the rquant rust crate

Dependencies

CratePurpose
rand v0.9.1Used to measure qubit position
num-complex v0.4Used as the basis of quantum positions for qubits

About

A quantum computing library written entirely in rust.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Used by

Contributors

Languages