QuantumSimulator

Struct QuantumSimulator 

Source
pub struct QuantumSimulator { /* private fields */ }
Expand description

A simulator for a quantum computer

This type represents a quantum computer.

Memory consumption scales 2^n with a given qubits number n. Thus, usually quantum machines up to around 30 qubits can be simulated although internal implementation is usize.

§Examples

An example to set the given qubit state to the desired one;

use rusq::prelude::*;

fn set(sim: &mut QuantumSimulator, qubit: &Qubit, r: MeasuredResult) {
    if sim.measure(qubit) != r {
        sim.X(qubit);
    }
}

let mut sim = QuantumSimulator::new(1);
let qubit = &sim.get_qubits()[0];
set(&mut sim, qubit, MeasuredResult::Zero);

assert_eq!(sim.measure(qubit), MeasuredResult::Zero);

As is discussed in new method, the initial values of the qubits are not definite (although in the code one can find some value). Thus, one needs to initialize qubits in this way. This behavior is because not the wavefunction itself but the ray corresponds to the physical state.

Implementations§

Source§

impl QuantumSimulator

Source

pub fn new(n: usize) -> QuantumSimulator

Creates a new instance with a given number of qubits. Note that the initial states of the qubits are not guaranteed to be a definite value.

§Examples
use rusq::prelude::*;

// A simulator with 3 qubits.
let sim = QuantumSimulator::new(3);

Trait Implementations§

Source§

impl DoubleGateApplicator for QuantumSimulator

Source§

fn apply_double( &mut self, matrix: &Array2<Complex<f64>>, qubit1: &Qubit, qubit2: &Qubit, )

An operation for the given unitary matrix matrix to qubit1 and qubit2
Source§

fn CNOT(&mut self, qubit1: &Qubit, qubit2: &Qubit)

Source§

fn SWAP(&mut self, qubit1: &Qubit, qubit2: &Qubit)

Source§

fn SQSWAP(&mut self, qubit1: &Qubit, qubit2: &Qubit)

Source§

fn cphase(&mut self, phi: f64, qubit1: &Qubit, qubit2: &Qubit)

Source§

impl QuantumMachine for QuantumSimulator

Source§

fn measure(&mut self, qubit: &Qubit) -> MeasuredResult

Measures the given qubit. Note that the qubit is expected to be projected to the corresponding state.
Source§

fn get_qubits(&self) -> Vec<Qubit>

Returns all the qubits in the machine.
Source§

impl SingleGateApplicator for QuantumSimulator

Source§

fn apply_single(&mut self, matrix: &Array2<Complex<f64>>, qubit: &Qubit)

An operation for the given unitary matrix matrix to qubit
Source§

fn H(&mut self, qubit: &Qubit)

Source§

fn X(&mut self, qubit: &Qubit)

Source§

fn Y(&mut self, qubit: &Qubit)

Source§

fn Z(&mut self, qubit: &Qubit)

Source§

fn ID(&mut self, qubit: &Qubit)

Source§

fn phase(&mut self, phi: f64, qubit: &Qubit)

Source§

impl TripleGateApplicator for QuantumSimulator

Source§

fn apply_triple( &mut self, matrix: &Array2<Complex<f64>>, qubit1: &Qubit, qubit2: &Qubit, qubit3: &Qubit, )

An operation for the given unitary matrix matrix to qubit1, qubit2 and qubit3
Source§

fn CCNOT(&mut self, qubit1: &Qubit, qubit2: &Qubit, qubit3: &Qubit)

Source§

fn CSWAP(&mut self, qubit1: &Qubit, qubit2: &Qubit, qubit3: &Qubit)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.