Skip to main content

MatrixProductState

Struct MatrixProductState 

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

Matrix Product State representation of an n-qubit pure state.

Implementations§

Source§

impl MatrixProductState

Source

pub fn new_zero_state(config: MpsConfig) -> QuantumResult<Self>

Build the product state |0…0⟩ with all bond dimensions equal to 1.

Source

pub fn n_qubits(&self) -> usize

Number of qubits / sites.

Source

pub fn config(&self) -> MpsConfig

The active configuration.

Source

pub fn bond_dims(&self) -> Vec<usize>

The right-bond dimension of each site (one entry per site).

bond_dims()[k] is the dimension of the bond between site k and site k+1; the final entry is the right boundary bond (always 1).

Source

pub fn apply_1q( &mut self, gate: &[[Complex<f32>; 2]; 2], qubit: usize, ) -> QuantumResult<()>

Apply a 1-qubit gate to qubit, contracting it into the physical index.

This leaves both bond dimensions unchanged.

Source

pub fn apply_2q( &mut self, gate: &[[Complex<f32>; 4]; 4], q: usize, q_plus_1: usize, ) -> QuantumResult<()>

Apply a 4×4 two-qubit gate to adjacent qubits q and q+1.

The gate is indexed in the basis |q, q+1⟩ with q the more-significant of the two physical indices, i.e. the matrix row/column index is 2 * bit(q) + bit(q+1) — matching apply_2q_inplace.

§Errors

Returns an error if the qubits are not adjacent with q_plus_1 == q + 1, or if either index is out of range.

Source

pub fn to_statevector(&self) -> QuantumResult<StateVector>

Contract the whole chain into a dense 2^n StateVector.

Intended for verification on small systems; cost is exponential in n.

Source

pub fn norm_sq(&self) -> f32

Squared norm ⟨ψ|ψ⟩ of the represented state.

Source

pub fn norm(&self) -> f32

Euclidean norm ‖ψ‖.

Source

pub fn normalize(&mut self)

Normalize the state in place (scales the first site tensor).

Source

pub fn expectation_z(&self, qubit: usize) -> QuantumResult<f32>

Expectation value ⟨ψ| Z_qubit |ψ⟩.

Trait Implementations§

Source§

impl Clone for MatrixProductState

Source§

fn clone(&self) -> MatrixProductState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for MatrixProductState

Source§

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

Formats the value using the given formatter. Read more

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

Source§

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

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.