How Alike Are Two Blurred States?

fidelity · matrix square root · eigendecomposition · density matrix · numpy

Two noisy copies of a qubit (or of a pair of qubits) are described by density matrices \rho and \sigma (lists of rows, both d \times d with d = 2 or 4). How alike are they?

When \rho = |\psi\rangle\langle\psi| is pure, the fidelity is F = \langle\psi|\sigma|\psi\rangle. For two mixed states it is defined with matrix square roots:

F(\rho, \sigma) = \Big(\mathrm{Tr}\sqrt{\sqrt\rho\;\sigma\,\sqrt\rho}\Big)^2.

Here the square root of a Hermitian matrix M with no negative eigenvalues is built from its eigendecomposition M = V\,\mathrm{diag}(\lambda_1, \dots, \lambda_d)\,V^\dagger (the columns of V are orthonormal eigenvectors, V^\dagger is the conjugate transpose): \sqrt M = V\,\mathrm{diag}(\sqrt{\lambda_1}, \dots, \sqrt{\lambda_d})\,V^\dagger. Rounding can turn an eigenvalue of 0 into -1e-17: treat negative eigenvalues as 0. The trace \mathrm{Tr}\sqrt{M} is simply \sum_k \sqrt{\lambda_k}. With this definition F is a number from 0 to 1, F(\rho, \sigma) = F(\sigma, \rho), F = 1 exactly when \rho = \sigma, and it agrees with \langle\psi|\sigma|\psi\rangle when \rho is pure (no square root is taken of the result).

This problem is the one where numpy is the tool: np.linalg.eigh(M) returns the eigenvalues and the matrix V of a Hermitian matrix, and np.linalg.eigvalsh(M) the eigenvalues alone.

Write mixed_fidelity(rho, sigma) that returns F(\rho, \sigma) as a real number.

Examples

Input:  rho = [[1, 0], [0, 0]], sigma = [[0.52, 0.36], [0.36, 0.48]]
Output: 0.52
Explanation: rho = |0><0| is pure, so F = <0|sigma|0> = sigma[0][0].

Input:  rho = [[0.5, 0], [0, 0.5]], sigma = [[0.5, 0], [0, 0.5]]
Output: 1.0

Input:  rho = [[0.9, 0], [0, 0.1]], sigma = [[0.5, 0], [0, 0.5]]
Output: 0.8
Explanation: (sqrt(0.9 * 0.5) + sqrt(0.1 * 0.5))**2 = (0.6708 + 0.2236)**2 = 0.8.

The answer is compared with a tolerance of 1e-6.

Goals

  • Compute the square root of a density matrix from its eigendecomposition
  • Compute the fidelity of two mixed states, which reduces to $\langle\psi|\sigma|\psi\rangle$ when one is pure
Starting Python…