Struct rusq::simulator::simulator::QuantumSimulator
[−]
[src]
pub struct QuantumSimulator { /* fields omitted */ }
A simulator for a quantum computer
This type represents a quantum computer.
Memory consumption scales 2n 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.
Methods
impl QuantumSimulator
[src]
fn new(n: usize) -> QuantumSimulator
[src]
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
impl QuantumMachine for QuantumSimulator
[src]
fn measure(&mut self, qubit: &Qubit) -> MeasuredResult
[src]
Measures the given qubit. Note that the qubit is expected to be projected to the corresponding state. Read more
fn get_qubits(&self) -> Vec<Qubit>
[src]
Returns all the qubits in the machine.
impl SingleGateApplicator for QuantumSimulator
[src]
fn apply_single(&mut self, matrix: &Array2<Complex<f64>>, qubit: &Qubit)
[src]
fn H(&mut self, qubit: &Qubit)
[src]
fn X(&mut self, qubit: &Qubit)
[src]
fn Y(&mut self, qubit: &Qubit)
[src]
fn Z(&mut self, qubit: &Qubit)
[src]
fn ID(&mut self, qubit: &Qubit)
[src]
fn phase(&mut self, phi: f64, qubit: &Qubit)
[src]
impl DoubleGateApplicator for QuantumSimulator
[src]
fn apply_double(
&mut self,
matrix: &Array2<Complex<f64>>,
qubit1: &Qubit,
qubit2: &Qubit
)
[src]
&mut self,
matrix: &Array2<Complex<f64>>,
qubit1: &Qubit,
qubit2: &Qubit
)