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: usized = 2^n_qubits.
Implementations§
Source§impl DensityMatrix
impl DensityMatrix
Sourcepub fn from_entries(m: Vec<Amp>) -> Option<DensityMatrix>
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.
Sourcepub fn expect_pauli(&self, ops: &[(u8, Pauli)]) -> i64
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.
pub fn get(&self, r: usize, c: usize) -> Amp
Sourcepub fn from_pure(sv: &StateVector) -> DensityMatrix
pub fn from_pure(sv: &StateVector) -> DensityMatrix
ρ = |ψ⟩⟨ψ| for a pure state.
Sourcepub fn mixture(parts: &[(i64, DensityMatrix)]) -> Option<DensityMatrix>
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).
Sourcepub fn purity(&self) -> i64
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.
Sourcepub fn partial_trace(&self, keep: &[u8]) -> DensityMatrix
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.
Trait Implementations§
Source§impl Clone for DensityMatrix
impl Clone for DensityMatrix
Source§fn clone(&self) -> DensityMatrix
fn clone(&self) -> DensityMatrix
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 DensityMatrix
impl Debug for DensityMatrix
impl Eq for DensityMatrix
Source§impl PartialEq for DensityMatrix
impl PartialEq for DensityMatrix
impl StructuralPartialEq for DensityMatrix
Auto Trait Implementations§
impl Freeze for DensityMatrix
impl RefUnwindSafe for DensityMatrix
impl Send for DensityMatrix
impl Sync for DensityMatrix
impl Unpin for DensityMatrix
impl UnsafeUnpin for DensityMatrix
impl UnwindSafe for DensityMatrix
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.