pub struct QubitRegister { /* private fields */ }Expand description
An n-qubit quantum register stored as a 2^n-dimensional statevector.
The state is always kept normalised. Amplitudes are ordered by the binary representation of the basis index with qubit 0 as the least-significant bit.
Implementations§
Source§impl QubitRegister
impl QubitRegister
Sourcepub fn new(
n_qubits: usize,
amplitudes: Vec<Complex<f64>>,
) -> QuantumResult<Self>
pub fn new( n_qubits: usize, amplitudes: Vec<Complex<f64>>, ) -> QuantumResult<Self>
Create a register from a raw amplitude vector.
n_qubits must satisfy amplitudes.len() == 2^n_qubits.
The vector is automatically re-normalised.
Sourcepub fn from_qubit(q: &Qubit) -> Self
pub fn from_qubit(q: &Qubit) -> Self
Wrap a single Qubit as a 1-qubit register.
Sourcepub fn new_zero_state(n_qubits: usize) -> QuantumResult<Self>
pub fn new_zero_state(n_qubits: usize) -> QuantumResult<Self>
All-zeros state |0…0⟩.
Sourcepub fn new_uniform_superposition(n_qubits: usize) -> QuantumResult<Self>
pub fn new_uniform_superposition(n_qubits: usize) -> QuantumResult<Self>
Equal superposition (Hadamard applied to all qubits of |0…0⟩).
Each amplitude has magnitude 1/√(2^n).
Sourcepub fn new_basis_state(n_qubits: usize, k: usize) -> QuantumResult<Self>
pub fn new_basis_state(n_qubits: usize, k: usize) -> QuantumResult<Self>
Computational basis state |k⟩ for a given integer k < 2^n.
Sourcepub fn amplitudes(&self) -> &[Complex<f64>]
pub fn amplitudes(&self) -> &[Complex<f64>]
Slice over all amplitudes.
Sourcepub fn amplitudes_mut(&mut self) -> &mut Vec<Complex<f64>>
pub fn amplitudes_mut(&mut self) -> &mut Vec<Complex<f64>>
Mutable slice over all amplitudes (use with care — normalisation is not automatically maintained).
Sourcepub fn probability(&self, k: usize) -> QuantumResult<f64>
pub fn probability(&self, k: usize) -> QuantumResult<f64>
Probability of measuring basis state k.
Sourcepub fn probabilities(&self) -> Vec<f64>
pub fn probabilities(&self) -> Vec<f64>
All measurement probabilities |ψ_k|² in basis order.
Sourcepub fn normalise(&mut self) -> QuantumResult<()>
pub fn normalise(&mut self) -> QuantumResult<()>
Re-normalise the statevector in place.
Sourcepub fn is_normalised(&self, tol: f64) -> bool
pub fn is_normalised(&self, tol: f64) -> bool
Check that the statevector is normalised within tol.
Sourcepub fn tensor_product(a: &QubitRegister, b: &QubitRegister) -> QubitRegister
pub fn tensor_product(a: &QubitRegister, b: &QubitRegister) -> QubitRegister
Tensor product (Kronecker product) of two registers: result = a ⊗ b.
If a has n₁ qubits and b has n₂ qubits, the result has n₁+n₂ qubits.
Qubit ordering: qubits of a are the more significant bits.
Sourcepub fn measure_qubit<R: Rng>(
&self,
qubit_idx: usize,
rng: &mut R,
) -> QuantumResult<(u8, QubitRegister)>
pub fn measure_qubit<R: Rng>( &self, qubit_idx: usize, rng: &mut R, ) -> QuantumResult<(u8, QubitRegister)>
Measure a single qubit at index qubit_idx and return (outcome, collapsed_state).
The returned register has the same number of qubits; amplitudes inconsistent with the measurement outcome are zeroed and the result is renormalised.
Sourcepub fn measure_all<R: Rng>(&self, rng: &mut R) -> Vec<u8> ⓘ
pub fn measure_all<R: Rng>(&self, rng: &mut R) -> Vec<u8> ⓘ
Measure all qubits and return a bit-string outcome (qubit 0 first).
Samples once from the Born-rule distribution.
Sourcepub fn inner_product(
&self,
other: &QubitRegister,
) -> QuantumResult<Complex<f64>>
pub fn inner_product( &self, other: &QubitRegister, ) -> QuantumResult<Complex<f64>>
Inner product ⟨other|self⟩.
Sourcepub fn fidelity(&self, other: &QubitRegister) -> QuantumResult<f64>
pub fn fidelity(&self, other: &QubitRegister) -> QuantumResult<f64>
Fidelity |⟨other|self⟩|² with another register.
Trait Implementations§
Source§impl Clone for QubitRegister
impl Clone for QubitRegister
Source§fn clone(&self) -> QubitRegister
fn clone(&self) -> QubitRegister
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for QubitRegister
impl Debug for QubitRegister
Source§impl Default for QubitRegister
impl Default for QubitRegister
Source§impl Display for QubitRegister
impl Display for QubitRegister
Source§impl PartialEq for QubitRegister
impl PartialEq for QubitRegister
impl StructuralPartialEq for QubitRegister
Auto Trait Implementations§
impl Freeze for QubitRegister
impl RefUnwindSafe for QubitRegister
impl Send for QubitRegister
impl Sync for QubitRegister
impl Unpin for QubitRegister
impl UnsafeUnpin for QubitRegister
impl UnwindSafe for QubitRegister
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
Source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
Source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
impl<T> Scalar for T
Source§impl<T> StrictAs for T
impl<T> StrictAs for T
Source§fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
Source§impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
Source§fn strict_cast_from(src: Src) -> Dst
fn strict_cast_from(src: Src) -> Dst
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.