Skip to content

hilbert_schmidt

Hilbert-Schmidt metric is a distance metric used to generate an entanglement measure.

hilbert_schmidt

hilbert_schmidt(
    rho: ndarray, sigma: ndarray
) -> float | floating

Compute the Hilbert-Schmidt distance between two states 1.

The Hilbert-Schmidt distance between density operators \(\rho\) and \(\sigma\) is defined as

\[ D_{\text{HS}}(\rho, \sigma) = \text{Tr}((\rho - \sigma)^2) = \left\lVert \rho - \sigma \right\rVert_2^2. \]

Parameters:

  • rho (ndarray) –

    An input matrix.

  • sigma (ndarray) –

    An input matrix.

Returns:

  • float | floating

    The Hilbert-Schmidt distance between rho and sigma.

Raises:

  • ValueError

    If matrices are not density operators.

Examples:

One may consider taking the Hilbert-Schmidt distance between two Bell states. In |toqito⟩, one may accomplish this as

import numpy as np
from toqito.states import bell
from toqito.state_metrics import hilbert_schmidt

rho = bell(0) @ bell(0).conj().T
sigma = bell(3) @ bell(3).conj().T

print(np.around(hilbert_schmidt(rho, sigma), decimals=2))
2.0

References

1 Wikipedia. Hilbert-Schmidt operator. link.

Source code in toqito/state_metrics/hilbert_schmidt.py
def hilbert_schmidt(rho: np.ndarray, sigma: np.ndarray) -> float | np.floating:
    r"""Compute the Hilbert-Schmidt distance between two states [@wikipediahilbertschmidt].

    The Hilbert-Schmidt distance between density operators \(\rho\) and \(\sigma\) is defined as

    \[
        D_{\text{HS}}(\rho, \sigma) = \text{Tr}((\rho - \sigma)^2) = \left\lVert \rho - \sigma
        \right\rVert_2^2.
    \]

    Args:
        rho: An input matrix.
        sigma: An input matrix.

    Returns:
        The Hilbert-Schmidt distance between `rho` and `sigma`.

    Raises:
        ValueError: If matrices are not density operators.

    Examples:
        One may consider taking the Hilbert-Schmidt distance between two Bell states. In `|toqito⟩`,
        one may accomplish this as

        ```python exec="1" source="above" result="text"
        import numpy as np
        from toqito.states import bell
        from toqito.state_metrics import hilbert_schmidt

        rho = bell(0) @ bell(0).conj().T
        sigma = bell(3) @ bell(3).conj().T

        print(np.around(hilbert_schmidt(rho, sigma), decimals=2))
        ```

    """
    if not is_density(rho) or not is_density(sigma):
        raise ValueError("Hilbert-Schmidt is only defined for density operators.")
    return np.linalg.norm(rho - sigma, ord="fro") ** 2