Struct quantum::registers::QuantumRegister
[−]
[src]
pub struct QuantumRegister { // some fields omitted }
Represents a register of an arbitrary number of qubits.
The register consists width
qubits, all of which are quantum
entangled. This means we store the state of the register, which
is normally a quantum superposition of the 2width possible
classical states, unless the register is collapsed (see below).
The register must be initialized with a starting (classical) state, and therefore holds valid superposition state from constuction. This state persists through the gates which may be applied to it, up until collapse (or resource destruction).
It is possible to collapse the register once during its lifetime, after which it no longer stores superposition state and therefore cannot provide further useful information.
Collapsing the register yields one of the 2width classical states.
We store the superposition internally as a vector of 2width complex coefficients, known as a ket, with the theoretical condition that the sum of their square moduli equals 1.
This representation should approximately confrm to this condition, subject to floating point imprecision.
See Wikipedia for more information.
Methods
impl QuantumRegister
[src]
fn new(width: usize, initial: &ClassicalRegister) -> QuantumRegister
Construct a new quantum register of given width
and initial state.
Panics
We panic if the initial state register has a different size to width
.
fn apply(&mut self, gate: Gate)
Apply a quantum gate to this register, mutating its state.
fn collapse(&mut self) -> ClassicalRegister
Collapse the register to yield one a classical state.
A register may only be collapsed once, and is invalid thereafter.
fn probabilities(&self) -> Vec<f64>
Compute the probabilities of each state without collapsing.
This function is intended for test purposes.
We return a vector of probabilities mirroring a ket, but without trailing zeroes.