Skip to main content

StatePreparation

Struct StatePreparation 

Source
pub struct StatePreparation { /* private fields */ }
Expand description

A state-preparation unitary A on m qubits, supplied as the closure that applies A to a StateVector. The last qubit (m − 1) is the flag.

The dense matrix of A is extracted once (by applying A to each computational basis state) and reused to build A† and the amplitude operator Q.

Implementations§

Source§

impl StatePreparation

Source

pub fn from_apply<F>(m: usize, apply: F) -> QuantumResult<Self>
where F: FnMut(&mut StateVector) -> QuantumResult<()>,

Build from a closure that applies A in place to an m-qubit state.

The closure is invoked 2^m times (once per basis column) to extract the dense matrix; it must implement a genuine unitary or downstream unitarity checks will fail.

§Errors
  • QuantumError::InvalidQubitCount if m == 0 or m > 12 (the dense 2^m × 2^m matrix would be impractical beyond that).
  • Propagates any error from the supplied apply closure.
Source

pub fn m(&self) -> usize

Number of qubits m (system + flag).

Source

pub fn good_probability(&self) -> f64

The “good” probability a = ⟨0…0| A† Π_1 A |0…0⟩, computed exactly from the dense matrix: it is the total |amplitude|² of A|0…0⟩ over basis states whose flag bit (qubit m − 1) is set.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.