pub struct Register<const N: usize> { /* private fields */ }Expand description
A quantum register that holds the state of N qubits
Implementations§
Source§impl<const N: usize> Register<N>
impl<const N: usize> Register<N>
Sourcepub fn with_amplitudes(amplitudes: Vec<Complex64>) -> QuantRS2Result<Self>
pub fn with_amplitudes(amplitudes: Vec<Complex64>) -> QuantRS2Result<Self>
Create a register with custom initial amplitudes
§Errors
Returns an error if the provided amplitudes vector doesn’t have the correct dimension (2^N) or if the vector isn’t properly normalized.
Sourcepub const fn num_qubits(&self) -> usize
pub const fn num_qubits(&self) -> usize
Get the number of qubits in this register
Sourcepub fn amplitudes(&self) -> &[Complex64] ⓘ
pub fn amplitudes(&self) -> &[Complex64] ⓘ
Get access to the raw amplitudes vector
Sourcepub fn amplitudes_mut(&mut self) -> &mut [Complex64] ⓘ
pub fn amplitudes_mut(&mut self) -> &mut [Complex64] ⓘ
Get mutable access to the raw amplitudes vector
Sourcepub fn amplitude(&self, bits: &[u8]) -> QuantRS2Result<Complex64>
pub fn amplitude(&self, bits: &[u8]) -> QuantRS2Result<Complex64>
Get the amplitude for a specific basis state
The bits parameter must be a slice of length N, where each element is either 0 or 1 representing the computational basis state.
§Errors
Returns an error if the bits slice has incorrect length or contains values other than 0 or 1.
Sourcepub fn probability(&self, bits: &[u8]) -> QuantRS2Result<f64>
pub fn probability(&self, bits: &[u8]) -> QuantRS2Result<f64>
Calculate the probability of measuring a specific basis state
The bits parameter must be a slice of length N, where each element is either 0 or 1 representing the computational basis state.
§Errors
Returns an error if the bits slice has incorrect length or contains values other than 0 or 1.
Sourcepub fn probabilities(&self) -> Vec<f64>
pub fn probabilities(&self) -> Vec<f64>
Calculate the probabilities of measuring each basis state
Sourcepub fn expectation_z(&self, qubit: impl Into<QubitId>) -> QuantRS2Result<f64>
pub fn expectation_z(&self, qubit: impl Into<QubitId>) -> QuantRS2Result<f64>
Calculate the expectation value of a single-qubit Pauli operator
Trait Implementations§
Auto Trait Implementations§
impl<const N: usize> Freeze for Register<N>
impl<const N: usize> RefUnwindSafe for Register<N>
impl<const N: usize> Send for Register<N>
impl<const N: usize> Sync for Register<N>
impl<const N: usize> Unpin for Register<N>
impl<const N: usize> UnwindSafe for Register<N>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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