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
impl QuantumSimulator
Sourcepub fn new(n: usize) -> QuantumSimulator
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
impl DoubleGateApplicator for QuantumSimulator
Source§fn apply_double(
&mut self,
matrix: &Array2<Complex<f64>>,
qubit1: &Qubit,
qubit2: &Qubit,
)
fn apply_double( &mut self, matrix: &Array2<Complex<f64>>, qubit1: &Qubit, qubit2: &Qubit, )
An operation for the given unitary matrix
matrix to qubit1 and qubit2fn CNOT(&mut self, qubit1: &Qubit, qubit2: &Qubit)
fn SWAP(&mut self, qubit1: &Qubit, qubit2: &Qubit)
fn SQSWAP(&mut self, qubit1: &Qubit, qubit2: &Qubit)
fn cphase(&mut self, phi: f64, qubit1: &Qubit, qubit2: &Qubit)
Source§impl QuantumMachine for QuantumSimulator
impl QuantumMachine for QuantumSimulator
Source§fn measure(&mut self, qubit: &Qubit) -> MeasuredResult
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>
fn get_qubits(&self) -> Vec<Qubit>
Returns all the qubits in the machine.
Source§impl SingleGateApplicator for QuantumSimulator
impl SingleGateApplicator for QuantumSimulator
Source§fn apply_single(&mut self, matrix: &Array2<Complex<f64>>, qubit: &Qubit)
fn apply_single(&mut self, matrix: &Array2<Complex<f64>>, qubit: &Qubit)
An operation for the given unitary matrix
matrix to qubitfn H(&mut self, qubit: &Qubit)
fn X(&mut self, qubit: &Qubit)
fn Y(&mut self, qubit: &Qubit)
fn Z(&mut self, qubit: &Qubit)
fn ID(&mut self, qubit: &Qubit)
fn phase(&mut self, phi: f64, qubit: &Qubit)
Source§impl TripleGateApplicator for QuantumSimulator
impl TripleGateApplicator for QuantumSimulator
Source§fn apply_triple(
&mut self,
matrix: &Array2<Complex<f64>>,
qubit1: &Qubit,
qubit2: &Qubit,
qubit3: &Qubit,
)
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 qubit3fn CCNOT(&mut self, qubit1: &Qubit, qubit2: &Qubit, qubit3: &Qubit)
fn CSWAP(&mut self, qubit1: &Qubit, qubit2: &Qubit, qubit3: &Qubit)
Auto Trait Implementations§
impl Freeze for QuantumSimulator
impl RefUnwindSafe for QuantumSimulator
impl Send for QuantumSimulator
impl Sync for QuantumSimulator
impl Unpin for QuantumSimulator
impl UnwindSafe for QuantumSimulator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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