Skip to main content

MpsState

Struct MpsState 

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

Matrix Product State quantum simulator.

Represents quantum states as a chain of tensors, enabling efficient simulation of circuits with bounded entanglement. Can handle hundreds to thousands of qubits when bond dimension stays manageable.

Implementations§

Source§

impl MpsState

Source

pub fn new(num_qubits: usize) -> Result<Self>

Initialize the |00…0> product state.

Each tensor has bond dimension 1 and physical dimension 2, with the amplitude concentrated on the |0> basis state.

Source

pub fn new_with_config(num_qubits: usize, config: MpsConfig) -> Result<Self>

Initialize |00…0> with explicit configuration.

Source

pub fn new_with_seed( num_qubits: usize, seed: u64, config: MpsConfig, ) -> Result<Self>

Initialize |00…0> with a deterministic seed for reproducibility.

Source

pub fn num_qubits(&self) -> usize

Source

pub fn max_bond_dimension(&self) -> usize

Current maximum bond dimension across all bonds in the MPS chain.

Source

pub fn truncation_error(&self) -> f64

Accumulated truncation error from bond-dimension truncations.

Source

pub fn measurement_record(&self) -> &[MeasurementOutcome]

Source

pub fn apply_single_qubit_gate( &mut self, qubit: usize, matrix: &[[Complex; 2]; 2], )

Apply a 2x2 unitary to a single qubit.

Contracts the gate matrix with the physical index of tensor[qubit]: new_tensor(l, i’, r) = Sum_i matrix[i’][i] * tensor(l, i, r)

This does not change bond dimensions.

Source

pub fn apply_two_qubit_gate_adjacent( &mut self, q1: usize, q2: usize, matrix: &[[Complex; 4]; 4], ) -> Result<()>

Apply a 4x4 unitary gate to two adjacent qubits.

The algorithm:

  1. Contract tensors at q1 and q2 into a combined 4-index tensor.
  2. Apply the 4x4 gate matrix on the two physical indices.
  3. Reshape into a matrix and perform truncated QR decomposition.
  4. Split back into two MPS tensors, respecting max_bond_dim.
Source

pub fn apply_two_qubit_gate( &mut self, q1: usize, q2: usize, matrix: &[[Complex; 4]; 4], ) -> Result<()>

Apply a 4x4 gate to any pair of qubits.

If the qubits are adjacent, delegates directly. Otherwise, uses SWAP gates to move the qubits next to each other, applies the gate, then swaps back to restore qubit ordering.

Source

pub fn measure(&mut self, qubit: usize) -> Result<MeasurementOutcome>

Measure a single qubit projectively.

  1. Compute the probability of |0> by locally contracting the MPS.
  2. Sample the outcome.
  3. Collapse the tensor at the measured qubit by projecting.
  4. Renormalize.
Source

pub fn apply_gate(&mut self, gate: &Gate) -> Result<Vec<MeasurementOutcome>>

Apply a gate from the Gate enum, returning any measurement outcomes.

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 = 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V