pub struct DensityMatrixN {
pub dim: usize,
pub entries: Vec<Complex>,
/* private fields */
}Expand description
Arbitrary-dimension density matrix (NxN, row-major). Pre-allocated scratch buffers for zero-allocation hot-path operations.
Fields§
§dim: usize§entries: Vec<Complex>Implementations§
Source§impl DensityMatrixN
impl DensityMatrixN
Sourcepub fn maximally_mixed(dim: usize) -> Self
pub fn maximally_mixed(dim: usize) -> Self
Create the maximally mixed state I/N.
Sourcepub fn pure_state(k: usize, dim: usize) -> Self
pub fn pure_state(k: usize, dim: usize) -> Self
Create a pure state |k⟩⟨k|.
Sourcepub fn equal_superposition(dim: usize) -> Self
pub fn equal_superposition(dim: usize) -> Self
Create an equal superposition: |ψ⟩ = (1/√N) Σ|k⟩ → ρ = |ψ⟩⟨ψ|.
Sourcepub fn populations(&self) -> Vec<f32>
pub fn populations(&self) -> Vec<f32>
Diagonal populations (probabilities).
Sourcepub fn coherence_magnitude(&self) -> f32
pub fn coherence_magnitude(&self) -> f32
Sum of off-diagonal magnitudes (coherence).
Sourcepub fn von_neumann_entropy(&self) -> f32
pub fn von_neumann_entropy(&self) -> f32
Von Neumann entropy via eigenvalue decomposition. S = -Σ λ_i ln(λ_i) where λ_i are eigenvalues of ρ. Uses Jacobi rotation solver from dreamwell-math.
Sourcepub fn free_energy(&self, energies: &[f32]) -> f32
pub fn free_energy(&self, energies: &[f32]) -> f32
Helmholtz free energy: F = ⟨H⟩ - T·S. H is given as diagonal energies. Temperature T = 1/(1 + φ·coherence_magnitude) — φ-scaled thermal partition. Higher coherence → lower temperature → free energy dominated by energy (ordered). Lower coherence → higher temperature → free energy dominated by entropy (disordered).
Sourcepub fn couple_dephase(&mut self, other: &DensityMatrixN, strength: f32)
pub fn couple_dephase(&mut self, other: &DensityMatrixN, strength: f32)
Apply shared dephasing with another density matrix (Model 4 coupling).
Sourcepub fn evolve(&mut self, unitary: &[Complex])
pub fn evolve(&mut self, unitary: &[Complex])
Unitary evolution: ρ → UρU†. Adaptive dispatch (Clean Compute: explicit hardware separation): dim < 32: serial cgemm (L1 cache, compiler vectorizes) dim ≥ 32: CPU parallel rows via rayon (no contention, scales with cores)
GPU compute (BA-60) is available via GpuTrainingContext::batched_evolve() for bulk operations where all matrices can be dispatched in a single submission. Per-call GPU dispatch is slower than CPU parallel due to Mutex serialization and buffer mapping overhead (~5ms per round-trip vs ~0.3ms for CPU cgemm_par at dim=86).
Sourcepub fn hamiltonian_unitary(h: &[f32], dim: usize, dt: f32) -> Vec<Complex>
pub fn hamiltonian_unitary(h: &[f32], dim: usize, dt: f32) -> Vec<Complex>
Build unitary U = exp(-iHdt) from a real symmetric Hamiltonian. Uses scaling-and-squaring with Padé approximant (numerically stable at any dim).
Sourcepub fn born_sample(&self, seed: u64) -> usize
pub fn born_sample(&self, seed: u64) -> usize
Born rule measurement: sample a mode index from diagonal populations.
Trait Implementations§
Source§impl Clone for DensityMatrixN
impl Clone for DensityMatrixN
Source§fn clone(&self) -> DensityMatrixN
fn clone(&self) -> DensityMatrixN
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DensityMatrixN
impl RefUnwindSafe for DensityMatrixN
impl Send for DensityMatrixN
impl Sync for DensityMatrixN
impl Unpin for DensityMatrixN
impl UnsafeUnpin for DensityMatrixN
impl UnwindSafe for DensityMatrixN
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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more