Is the Batch Pure?

density matrix · purity · trace · mixed state

A chip test log hands you density matrices. Some describe one definite state |\psi\rangle\langle\psi| (a pure state); others describe a mixture \sum_k p_k|\psi_k\rangle\langle\psi_k| that is not equal to any single state (a mixed state). One number tells them apart, the purity

\gamma = \mathrm{Tr}(\rho^2) = \sum_i (\rho^2)_{ii} = \sum_i \sum_j \rho_{ij}\,\rho_{ji},

where \mathrm{Tr} (the trace) is the sum of the diagonal and \rho^2 is the matrix product \rho\rho. For a d \times d density matrix, \gamma = 1 exactly for a pure state, and \gamma < 1 for a mixed one; the smallest value, 1/d, belongs to the maximally mixed state I/d.

Write purity_report(rho) that returns a pair (gamma, label): the purity as a real number, and the string "pure" if |\gamma - 1| \le 10^{-9}, else "mixed". rho is a valid density matrix (a list of rows: Hermitian, trace 1, no negative eigenvalues) of size 2, 4 or 8. Every test is either pure, or has \gamma \le 0.999.

Examples

Input:  rho = [[0.5, 0.5], [0.5, 0.5]]
Output: (1.0, 'pure')
Explanation: this is |+><+| with |+> = (|0> + |1>)/sqrt(2).

Input:  rho = [[0.5, 0], [0, 0.5]]
Output: (0.5, 'mixed')
Explanation: I/2, the most mixed qubit: gamma = 1/d = 1/2.

Input:  rho = [[0.52, 0.36], [0.36, 0.48]]
Output: (0.76, 'mixed')
Explanation: 0.52*0.52 + 0.36*0.36 + 0.36*0.36 + 0.48*0.48 = 0.76.

The purity is compared with a tolerance of 1e-6; the label exactly.

Goals

  • Compute the purity $\mathrm{Tr}(\rho^2)$ of a density matrix
  • Tell a pure state from a mixture with a stated tolerance
Starting Python…