Skip to main content

DensityMatrix

Struct DensityMatrix 

Source
pub struct DensityMatrix {
    pub n_qubits: u8,
    pub d: usize,
    /* private fields */
}
Expand description

A density matrix, row-major d × d over the same fixed point as the simulator.

Fields§

§n_qubits: u8§d: usize

d = 2^n_qubits.

Implementations§

Source§

impl DensityMatrix

Source

pub fn from_entries(m: Vec<Amp>) -> Option<DensityMatrix>

Build a density matrix from raw row-major entries. m.len() must be d² for a power-of-two d; nothing here checks that the result is a physical state, so callers that construct one by hand own that.

Source

pub fn expect_pauli(&self, ops: &[(u8, Pauli)]) -> i64

Tr(ρ P) for a Pauli string — the mixed-state counterpart of expect_pauli, and what a tomographer actually measures.

Source

pub fn get(&self, r: usize, c: usize) -> Amp

Source

pub fn from_pure(sv: &StateVector) -> DensityMatrix

ρ = |ψ⟩⟨ψ| for a pure state.

Source

pub fn mixture(parts: &[(i64, DensityMatrix)]) -> Option<DensityMatrix>

A classical mixture Σ wᵢ ρᵢ, weights in fixed point (they should sum to ONE; nothing here silently renormalises them).

Source

pub fn trace(&self) -> Amp

Tr ρ, which is ONE for any state.

Source

pub fn purity(&self) -> i64

Tr ρ² — one for a pure state, 1/d for the maximally mixed one. The cheapest honest answer to “how mixed is this?”, and unlike the entropy it needs no eigenvalues, so it stays exactly in the fixed point.

Source

pub fn partial_trace(&self, keep: &[u8]) -> DensityMatrix

Trace out every qubit not in keep, leaving the reduced state of the rest.

This is the operation that makes mixed states unavoidable: the reduced state of half a Bell pair is maximally mixed, and no state vector can say that.

Source

pub fn hash(&self) -> [u8; 32]

Portable identity of the mixture itself.

Trait Implementations§

Source§

impl Clone for DensityMatrix

Source§

fn clone(&self) -> DensityMatrix

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 DensityMatrix

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for DensityMatrix

Source§

impl PartialEq for DensityMatrix

Source§

fn eq(&self, other: &DensityMatrix) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DensityMatrix

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Same for T

Source§

type Output = T

Should always be Self
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 = !

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.