pub struct StateVector { /* private fields */ }
Expand description

Represent the state vector of a quantum system simulation.

Implementations§

source§

impl StateVector

source

pub fn new(qubit_width: usize) -> Self

Create a new state-vector with of length 2 to the qubit_width power and all the amplitude concentrated in the all-zeroes outcome.

source

pub fn as_complex_bases(&self) -> &[Complex]

Return the amplitudes corresponding to the bases of the system.

source

pub fn qubit_width(&self) -> usize

Return the 2-base logarithm of the number of amplitudes representing the number of qubits in the system.

source

pub fn from_complex_bases(bases: Vec<Complex>) -> Self

Create a new state-vector from a vector of complex numbers representing amplitudes. It does not check the length of the vector is a power of two, not the norm of the vector is 1.

source

pub fn len(&self) -> usize

Get the length of the state-vector.

source

pub fn is_empty(&self) -> bool

Check if the length of statevector is zero.

source

pub fn cnot(&mut self, control: usize, target: usize)

Apply a controlled not operation on qubit target.

source

pub fn u(&mut self, theta: f64, phi: f64, lambda: f64, target: usize)

Apply a general rotation on target qubit, specified as RZ(phi)RY(theta)RZ(lambda).

source

pub fn measure(&mut self, target: usize) -> bool

Perform a measurement on the Z-axis of the quantum state on target qubit.

source

pub fn probabilities(&self) -> Vec<f64>

Return the probabilities associated to the amplitudes in the state-vector.

source

pub fn reset(&mut self)

Reset the state-vector to the state |0⟩.

Trait Implementations§

source§

impl<'a> ApproxEq for &'a StateVector

§

type Margin = F64Margin

This type type defines a margin within which two values are to be considered approximately equal. It must implement Default so that approx_eq() can be called on unknown types.
source§

fn approx_eq<T: Into<Self::Margin>>(self, other: Self, margin: T) -> bool

This method tests that the self and other values are equal within margin of each other.
source§

fn approx_ne<M>(self, other: Self, margin: M) -> bool
where M: Into<Self::Margin>,

This method tests that the self and other values are not within margin of each other.
source§

impl Clone for StateVector

source§

fn clone(&self) -> StateVector

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for StateVector

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromIterator<Complex<f64>> for StateVector

source§

fn from_iter<I: IntoIterator<Item = Complex>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl PartialEq for StateVector

source§

fn eq(&self, other: &StateVector) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for StateVector

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V