Struct qasmsim::statevector::StateVector
source · pub struct StateVector { /* private fields */ }
Expand description
Represent the state vector of a quantum system simulation.
Implementations§
source§impl StateVector
impl StateVector
sourcepub fn new(qubit_width: usize) -> Self
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.
sourcepub fn as_complex_bases(&self) -> &[Complex]
pub fn as_complex_bases(&self) -> &[Complex]
Return the amplitudes corresponding to the bases of the system.
sourcepub fn qubit_width(&self) -> usize
pub fn qubit_width(&self) -> usize
Return the 2-base logarithm of the number of amplitudes representing the number of qubits in the system.
sourcepub fn from_complex_bases(bases: Vec<Complex>) -> Self
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.
sourcepub fn cnot(&mut self, control: usize, target: usize)
pub fn cnot(&mut self, control: usize, target: usize)
Apply a controlled not operation on qubit target
.
sourcepub fn u(&mut self, theta: f64, phi: f64, lambda: f64, target: usize)
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
).
sourcepub fn measure(&mut self, target: usize) -> bool
pub fn measure(&mut self, target: usize) -> bool
Perform a measurement on the Z-axis of the quantum state on target
qubit.
sourcepub fn probabilities(&self) -> Vec<f64>
pub fn probabilities(&self) -> Vec<f64>
Return the probabilities associated to the amplitudes in the state-vector.
Trait Implementations§
source§impl<'a> ApproxEq for &'a StateVector
impl<'a> ApproxEq for &'a StateVector
§type Margin = F64Margin
type Margin = F64Margin
Default
so that
approx_eq()
can be called on unknown types.source§impl Clone for StateVector
impl Clone for StateVector
source§fn clone(&self) -> StateVector
fn clone(&self) -> StateVector
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for StateVector
impl Debug for StateVector
source§impl FromIterator<Complex<f64>> for StateVector
impl FromIterator<Complex<f64>> for StateVector
source§impl PartialEq for StateVector
impl PartialEq for StateVector
source§fn eq(&self, other: &StateVector) -> bool
fn eq(&self, other: &StateVector) -> bool
self
and other
values to be equal, and is used
by ==
.