Skip to content

lukkyye/qubit-rep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

qubit-rep

Fast representation of single qubit.

With some gates implemented like: Hadamard, Pauli-X, Pauli-Y, Pauli-Z and Phase shift

Usage

Clone the repo and run with cargo

  git clone https://github.com/lukkyye/qubit-rep.git
  cargo run

Example

Using as lib

Initialize a qubit undetermined state:

  let qbit1: Qubit<PolarComplex<f32>> = Qubit::init();

Note that, you can especify the float and type as f32 or f64 (recommended f32) Also, two complex types are implemented (PolarComplex and CartesianComplex) where T: Float

Otherwise, you can initialize with a basis state determined like |0⟩ or |1⟩

  let qbit1: Qubit<PolarComplex<f64>> = Qubit::init0();
  // or
  let qbit2: Qubit<PolarComplex<f64>> = Qubit::init1();

Hadamard gate

  let mut qbit1: Qubit<PolarComplex<f64>> = Qubit::init();
  qbit1.hadamard()

Note that qbit1 is mutable, because hadamard gate transform qubit state into another one

Pauli gates (X, Y, Z)

  let mut qbit1: Qubit<CartesianComplex<f64>> = Qubit::init();
  qbit1.px(); qbit1.py(); qbit1.pz();

Print

  let qbit1: Qubit<PolarComplex<f32>> = Qubit::init();
  qbit1.print();

Example output: " |φ⟩=0.9716602e^(-2.9490366i)|0⟩+0.2363819e^(2.7047591i)|1⟩ "

Measure

  let qbit1: Qubit<CartesianComplex<f32>> = Qubit::init();
  qbit1.measure()

Example output: "P(|0⟩)= 0.9597898, P(|1⟩)= 0.040210187"

About

Single qubit simulator

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages