Hide code cell content
import mmf_setup;mmf_setup.nbinit()
import logging;logging.getLogger('matplotlib').setLevel(logging.CRITICAL)
%matplotlib inline
import numpy as np, matplotlib.pyplot as plt

This cell adds /home/docs/checkouts/readthedocs.org/user_builds/physics-555-quantum-technologies/checkouts/latest/src to your path, and contains some definitions for equations and some CSS for styling the notebook. If things look a bit strange, please try the following:

  • Choose "Trust Notebook" from the "File" menu.
  • Re-execute this cell.
  • Reload the notebook.

Fidelity#

In section §9.2.2 [Nielsen and Chuang, 2010], they define the fidelity as a measure of the distance between density matrices:

\[\begin{gather*} F(\mat{\rho}, \mat{\sigma}) = \Tr \sqrt{\mat{\rho}^{1/2}\mat{\sigma}\mat{\rho}^{1/2}}. \end{gather*}\]

The advantage of this formulation is that, since density matrices are positive, the matrix square-root is well defined. However, in many cases, the following formulation may be easier to use:

\[\begin{gather*} F(\mat{\rho}, \mat{\sigma}) = \Tr \sqrt{\mat{\rho}\mat{\sigma}}. \end{gather*}\]
import numpy as np
from scipy.linalg import sqrtm

rng = np.random.default_rng(seed=2)
N = 5
for n in range(10):
    A, B = rng.normal(size=(2, N, N)) + 1j*rng.normal(size=(2, N, N))
    # Make these positive definite as density matrices must be
    A = A.T.conj() @ A
    B = B.T.conj() @ B
    assert not np.allclose(A @ B, B @ A)
    assert np.allclose(
        np.trace(sqrtm(sqrtm(A) @ B @ sqrtm(A))),
        np.trace(sqrtm(B @ A)))

Qingze points out, however, that this is not always well defined. Consider for example:

\[\begin{gather*} \mat{\rho} = \begin{pmatrix} 0 & 0\\ 0 & 1 \end{pmatrix}, \qquad \mat{\sigma} = \begin{pmatrix} 1 & 1\\ 1 & 0 \end{pmatrix}. \end{gather*}\]

In this case, the product is then a Jordan matrix which has no well-defined matrix square root, which is very unlikely to occur randomly, but can appear in special cases. One can easily verify that \(\mat{\rho}^2 = \mat{\rho} = \sqrt{\mat{\rho}}\), hence the original form gives a well-defined fidelity:

\[\begin{gather*} F(\mat{\rho}, \mat{\sigma}) = \Tr\sqrt{\mat{\rho}\mat{\sigma}\mat{\rho}} = \Tr\sqrt{\mat{0}} = 0. \end{gather*}\]