Compute the sub fidelity of two density matrices 1.
The sub-fidelity is a measure of similarity between density operators. It is defined as
\[
E(\rho, \sigma) = \text{Tr}(\rho \sigma) +
\sqrt{2 \left[ \text{Tr}(\rho \sigma)^2 - \text{Tr}(\rho \sigma \rho \sigma) \right]},
\]
where \(\sigma\) and \(\rho\) are density matrices. The sub-fidelity serves as a lower bound for the
fidelity.
Parameters:
-
rho
(ndarray)
–
-
sigma
(ndarray)
–
Returns:
-
float
–
The sub-fidelity between rho and sigma.
Raises:
-
ValueError
–
If matrices are not of equal dimension.
Examples:
Consider the following pair of states:
\[
\rho = \frac{3}{4}|0\rangle \langle 0| +
\frac{1}{4}|1 \rangle \langle 1|
\quad \text{and} \quad
\sigma = \frac{1}{8}|0 \rangle \langle 0| +
\frac{7}{8}|1 \rangle \langle 1|.
\]
Calculating the fidelity between the states \(\rho\) and \(\sigma\) as \(F(\rho, \sigma) \approx
0.774\). This can be observed in |toqito⟩ as
from toqito.states import basis
from toqito.state_metrics import fidelity
e_0, e_1 = basis(2, 0), basis(2, 1)
rho = 3 / 4 * e_0 @ e_0.conj().T + 1 / 4 * e_1 @ e_1.conj().T
sigma = 1/8 * e_0 @ e_0.conj().T + 7/8 * e_1 @ e_1.conj().T
print(fidelity(rho, sigma))
As the sub-fidelity is a lower bound on the fidelity, that is \(E(\rho, \sigma) \leq F(\rho, \sigma)\), we can
use |toqito⟩ to observe that \(E(\rho, \sigma) \approx 0.599 \leq F(\rho, \sigma) \approx 0.774\).
from toqito.states import basis
from toqito.state_metrics import sub_fidelity
e_0, e_1 = basis(2, 0), basis(2, 1)
rho = 3 / 4 * e_0 @ e_0.conj().T + 1 / 4 * e_1 @ e_1.conj().T
sigma = 1/8 * e_0 @ e_0.conj().T + 7/8 * e_1 @ e_1.conj().T
print(sub_fidelity(rho, sigma))
References
1 Miszczak, J. and Puchała, Z. and Horodecki, P. and Uhlmann, A. and Życzkowski, K.. Sub-- and super--fidelity as bounds for quantum fidelity. (2008).
Source code in toqito/state_metrics/sub_fidelity.py
| def sub_fidelity(rho: np.ndarray, sigma: np.ndarray) -> float:
r"""Compute the sub fidelity of two density matrices [@miszczak2008sub].
The sub-fidelity is a measure of similarity between density operators. It is defined as
\[
E(\rho, \sigma) = \text{Tr}(\rho \sigma) +
\sqrt{2 \left[ \text{Tr}(\rho \sigma)^2 - \text{Tr}(\rho \sigma \rho \sigma) \right]},
\]
where \(\sigma\) and \(\rho\) are density matrices. The sub-fidelity serves as a lower bound for the
fidelity.
Args:
rho: Density operator.
sigma: Density operator.
Returns:
The sub-fidelity between `rho` and `sigma`.
Raises:
ValueError: If matrices are not of equal dimension.
Examples:
Consider the following pair of states:
\[
\rho = \frac{3}{4}|0\rangle \langle 0| +
\frac{1}{4}|1 \rangle \langle 1|
\quad \text{and} \quad
\sigma = \frac{1}{8}|0 \rangle \langle 0| +
\frac{7}{8}|1 \rangle \langle 1|.
\]
Calculating the fidelity between the states \(\rho\) and \(\sigma\) as \(F(\rho, \sigma) \approx
0.774\). This can be observed in `|toqito⟩` as
```python exec="1" source="above" result="text"
from toqito.states import basis
from toqito.state_metrics import fidelity
e_0, e_1 = basis(2, 0), basis(2, 1)
rho = 3 / 4 * e_0 @ e_0.conj().T + 1 / 4 * e_1 @ e_1.conj().T
sigma = 1/8 * e_0 @ e_0.conj().T + 7/8 * e_1 @ e_1.conj().T
print(fidelity(rho, sigma))
```
As the sub-fidelity is a lower bound on the fidelity, that is \(E(\rho, \sigma) \leq F(\rho, \sigma)\), we can
use `|toqito⟩` to observe that \(E(\rho, \sigma) \approx 0.599 \leq F(\rho, \sigma) \approx 0.774\).
```python exec="1" source="above" result="text"
from toqito.states import basis
from toqito.state_metrics import sub_fidelity
e_0, e_1 = basis(2, 0), basis(2, 1)
rho = 3 / 4 * e_0 @ e_0.conj().T + 1 / 4 * e_1 @ e_1.conj().T
sigma = 1/8 * e_0 @ e_0.conj().T + 7/8 * e_1 @ e_1.conj().T
print(sub_fidelity(rho, sigma))
```
"""
# Perform some error checking.
if not np.all(rho.shape == sigma.shape):
raise ValueError("InvalidDim: `rho` and `sigma` must be matrices of the same size.")
if not is_density(rho) or not is_density(sigma):
raise ValueError("Sub-fidelity is only defined for density operators.")
inner = np.trace(rho @ sigma)
# The radicand is non-negative in exact arithmetic, but floating-point error can push it
# slightly below zero for pure/near-equal states; clamp it before the square root.
radicand = 2 * (inner**2 - np.trace(rho @ sigma @ rho @ sigma))
return np.real(inner + np.sqrt(np.maximum(np.real(radicand), 0.0)))
|