torch_vn_algebra.states¶
Source: torch_vn_algebra/states.py. Signatures and docstrings as in the source.
Module documentation¶
States (density matrices) on M = (+)_c M_{k_c} and information-theoretic quantities.
A state is a normal positive normalised functional on M. It is represented by its density
rho = (+)_c rho_c with respect to the blunt trace: omega(A) = Tr_blunt(rho A), rho >= 0 and
sum_c Tr rho_c = 1, so p_c = Tr rho_c is the classical probability of sector c (the restriction
of the state to the centre of M). Densities with respect to Tr_norm or tau_vN differ by the
weights k_c and C k_c; see DensityMatrix.density and DensityMatrix.from_density.
All functions are batched over the leading dimension.
trace_of_product¶
def trace_of_product(A: Operator, B: Operator) -> torch.Tensor
Tr_blunt(A B) = sum_ij A_ij B_ji in O(k^2) per block, without forming A B.
DensityMatrix¶
class DensityMatrix(algebra: TypeIAlgebra, generator=None, matrix: Optional[torch.Tensor]=None, validate: bool=True)
State on M, stored as its density with respect to Tr_blunt (positive, unit blunt trace).
Generic algebra operations (rho @ A, rho - sigma, ...) return plain Operators; operations
that map states to states (trace-preserving channels, Hamiltonian and Lindblad evolution,
mix, condition_on) return DensityMatrix again. With validate=True positivity and the
normalisation are checked once, when the matrix is materialised.
DensityMatrix.density¶
def density(self, trace: str='blunt') -> torch.Tensor
Matrix d of the same state with respect to `trace`: omega(A) = trace(d A).
DensityMatrix.from_density¶
@classmethod
def from_density(cls, algebra: TypeIAlgebra, d: torch.Tensor, trace: str='blunt', normalize: bool=False) -> 'DensityMatrix'
State whose density with respect to `trace` is d (shape (batch, C, k_max, k_max)).
DensityMatrix.expectation¶
def expectation(self, A: Operator) -> torch.Tensor
<A> = Tr(rho A), real for self-adjoint A.
DensityMatrix.sector_probabilities¶
def sector_probabilities(self) -> torch.Tensor
DensityMatrix.von_neumann_entropy¶
def von_neumann_entropy(self, eps: float=1e-12) -> torch.Tensor
DensityMatrix.purity¶
def purity(self) -> torch.Tensor
DensityMatrix.fidelity¶
def fidelity(self, other: 'DensityMatrix') -> torch.Tensor
DensityMatrix.trace_distance¶
def trace_distance(self, other: 'DensityMatrix') -> torch.Tensor
DensityMatrix.relative_entropy¶
def relative_entropy(self, other: 'DensityMatrix', eps: float=1e-12) -> torch.Tensor
DensityMatrix.mix¶
def mix(self, other: 'DensityMatrix', p) -> 'DensityMatrix'
(1 - p) rho + p sigma for p in [0, 1]; p is a number or a tensor (batch,) with one weight per sample.
DensityMatrix.condition_on¶
def condition_on(self, P: Operator, eps: float=1e-12) -> Tuple['DensityMatrix', torch.Tensor]
Lueders rule: (P rho P / Tr(P rho P), Tr(rho P)).
random_density_matrix¶
def random_density_matrix(alg: TypeIAlgebra, batch_size: int=1, rank: Optional[int]=None, measure: str='hs') -> DensityMatrix
Random state on M.
measure='hs': rho = G G^* / Tr(G G^*) with G = (+)_c G_c, G_c a k_c x rank Ginibre matrix
(by default k_c x k_c, and k_c x (k_c + 1) in a real algebra: the Hilbert-Schmidt
measure within each block; an explicit rank r gives the induced measure with an ancilla
of dimension r).
measure='bures': rho ~ (1 + U) G G^* (1 + U)^* with U Haar unitary in M (the Bures measure; complex
algebras only: with a Haar orthogonal U, 1 + U is singular whenever det U = -1).
The sector weights p_c = Tr rho_c are then random as well (proportional to the squared
Frobenius norms of the blocks).
maximally_mixed_state¶
def maximally_mixed_state(alg: TypeIAlgebra, batch_size: int=1) -> DensityMatrix
rho = 1 / sum_c k_c (the normalised trace of the full matrix algebra on H).
tracial_state¶
def tracial_state(alg: TypeIAlgebra, batch_size: int=1) -> DensityMatrix
Density of tau_vN with respect to Tr_blunt: rho = (+)_c 1_c / (C k_c).
gibbs_state¶
def gibbs_state(H: Operator, beta: float) -> DensityMatrix
rho = exp(-beta H) / Z for self-adjoint H (exponents shifted by their maximum, for any sign of beta).
partition_function¶
def partition_function(H: Operator, beta: float) -> torch.Tensor
Z = Tr exp(-beta H) (blunt trace), computed from the spectrum (as exp(log Z), without overflow of the
terms; Z itself may still overflow, see log_partition_function).
log_partition_function¶
def log_partition_function(H: Operator, beta: float) -> torch.Tensor
log Z = log Tr exp(-beta H), by logsumexp over the spectrum.
sector_probabilities¶
def sector_probabilities(rho: Operator) -> torch.Tensor
p_c = Tr rho_c, shape (batch, C): the classical distribution over superselection sectors.
expectation¶
def expectation(rho: Operator, A: Operator) -> torch.Tensor
<A>_rho = Tr(rho A) (blunt trace).
born_probabilities¶
def born_probabilities(rho: Operator, effects: Sequence[Operator]) -> torch.Tensor
Probabilities Tr(rho E_j) of a POVM {E_j}, shape (batch, len(effects)).
lueders_update¶
def lueders_update(rho: Operator, P: Operator, eps: float=1e-12) -> Tuple[DensityMatrix, torch.Tensor]
Conditional state after observing the outcome of projection P (Lueders rule):
rho | P = P rho P / Tr(P rho P), together with the probability Tr(rho P).
Samples with probability below eps are returned as zero operators.
von_neumann_entropy¶
def von_neumann_entropy(rho: Operator, eps: float=1e-12) -> torch.Tensor
S(rho) = -Tr rho log rho (natural logarithm).
relative_entropy¶
def relative_entropy(rho: Operator, sigma: Operator, eps: float=1e-12) -> torch.Tensor
Umegaki relative entropy D(rho || sigma) = Tr rho (log rho - log sigma).
Eigenvalues of sigma are clamped to eps, so a support mismatch gives a large finite value
of order -log(eps) instead of +inf.
fidelity¶
def fidelity(rho: Operator, sigma: Operator) -> torch.Tensor
Uhlmann fidelity F = (Tr |sqrt(rho) sqrt(sigma)|)^2 (singular values of sqrt(rho) sqrt(sigma): accurate
also for nearly pure states, unlike the eigenvalues of sqrt(rho) sigma sqrt(rho)).
trace_distance¶
def trace_distance(rho: Operator, sigma: Operator) -> torch.Tensor
T = (1/2) ||rho - sigma||_1.
purity¶
def purity(rho: Operator) -> torch.Tensor
Tr rho^2.