|
| 1 | +"""Calculates the Rényi entropy metric of a quantum state.""" |
| 2 | + |
| 3 | +import numpy as np |
| 4 | + |
| 5 | +from toqito.matrix_props import is_density |
| 6 | +from toqito.state_props import von_neumann_entropy |
| 7 | + |
| 8 | + |
| 9 | +def renyi_entropy(rho: np.ndarray, alpha: float) -> float: |
| 10 | + r"""Compute the Rényi entropy of a density matrix :footcite:`Muller_2013_Renyi_Generalization`. |
| 11 | +
|
| 12 | + Let :math:`P \in \text{Pos}(\mathcal{X})` be a positive semidefinite operator, for a complex |
| 13 | + Euclidean space :math:`\mathcal{X}`. Then one defines the *Rényi entropy of order* |
| 14 | + :math:`\alpha\geqslant0` as |
| 15 | +
|
| 16 | + .. math:: |
| 17 | + H_{\alpha}(P) = H_{\alpha}(\lambda(P)), |
| 18 | +
|
| 19 | + where :math:`\lambda(P)` is the vector of eigenvalues of :math:`P` and where the function |
| 20 | + :math:`H(\cdot)` is the classical Rényi entropy of order :math:`\alpha` defined as |
| 21 | +
|
| 22 | + .. math:: |
| 23 | + H_{\alpha}(u) = \frac{1}{1-\alpha}\log\left(\sum_{a \in \Sigma} u(a)^{\alpha}\right), |
| 24 | +
|
| 25 | + where the :math:`\log` function is assumed to be the base-2 logarithm, and where |
| 26 | + :math:`\Sigma` is an alphabet where :math:`u \in [0, \infty)^{\Sigma}` is a vector of |
| 27 | + nonnegative real numbers indexed by :math:`\Sigma`. It recovers the von Neumann entropy for |
| 28 | + :math:`\alpha=1` and the min-entropy for :math:`\alpha=+\infty`. |
| 29 | +
|
| 30 | + Examples |
| 31 | + ========== |
| 32 | +
|
| 33 | + Consider the following Bell state: |
| 34 | +
|
| 35 | + .. math:: |
| 36 | + u = \frac{1}{\sqrt{2}} \left(|00 \rangle + |11 \rangle \right) \in \mathcal{X}. |
| 37 | +
|
| 38 | + The corresponding density matrix of :math:`u` may be calculated by: |
| 39 | +
|
| 40 | + .. math:: |
| 41 | + \rho = u u^* = \frac{1}{2} \begin{pmatrix} |
| 42 | + 1 & 0 & 0 & 1 \\ |
| 43 | + 0 & 0 & 0 & 0 \\ |
| 44 | + 0 & 0 & 0 & 0 \\ |
| 45 | + 1 & 0 & 0 & 1 |
| 46 | + \end{pmatrix} \in \text{D}(\mathcal{X}). |
| 47 | +
|
| 48 | + Calculating the Rényi entropy of order :math:`2` of :math:`\rho` in :code:`|toqito⟩` can be |
| 49 | + done as follows. |
| 50 | +
|
| 51 | + .. jupyter-execute:: |
| 52 | +
|
| 53 | + from toqito.state_props import renyi_entropy |
| 54 | + import numpy as np |
| 55 | + test_input_mat = np.array( |
| 56 | + [[1 / 2, 0, 0, 1 / 2], [0, 0, 0, 0], |
| 57 | + [0, 0, 0, 0], [1 / 2, 0, 0, 1 / 2]] |
| 58 | + ) |
| 59 | + renyi_entropy(test_input_mat, 2) |
| 60 | +
|
| 61 | + Consider the density operator corresponding to the maximally mixed state of dimension two |
| 62 | +
|
| 63 | + .. math:: |
| 64 | + \rho = \frac{1}{2} |
| 65 | + \begin{pmatrix} |
| 66 | + 1 & 0 \\ |
| 67 | + 0 & 1 |
| 68 | + \end{pmatrix}. |
| 69 | +
|
| 70 | + As this state is maximally mixed, the Rényi entropy of :math:`\rho` is |
| 71 | + equal to one for all orders :math:`\alpha`. We can see this in :code:`|toqito⟩` as follows. |
| 72 | +
|
| 73 | + .. jupyter-execute:: |
| 74 | +
|
| 75 | + from toqito.state_props import renyi_entropy |
| 76 | + import numpy as np |
| 77 | + rho = 1/2 * np.identity(2) |
| 78 | + renyi_entropy(rho, 3/2) |
| 79 | +
|
| 80 | + References |
| 81 | + ========== |
| 82 | + .. footbibliography:: |
| 83 | +
|
| 84 | +
|
| 85 | +
|
| 86 | + :param rho: Density operator. |
| 87 | + :param alpha: Order for the Rényi entropy. Note that numerical instability may happen for small |
| 88 | + positive values because of the computation of the spectral decomposition. |
| 89 | + :return: The Rényi entropy of order :code:`alpha` of :code:`rho`. |
| 90 | +
|
| 91 | + """ |
| 92 | + if not is_density(rho): |
| 93 | + raise ValueError("Rényi entropy is only defined for density operators.") |
| 94 | + if alpha < 0: |
| 95 | + raise ValueError("Rényi entropy is only defined for positive orders.") |
| 96 | + if alpha == 0: |
| 97 | + return np.log2(np.linalg.matrix_rank(rho)) |
| 98 | + if alpha == 1: |
| 99 | + return von_neumann_entropy(rho) |
| 100 | + |
| 101 | + eigs = np.linalg.eigvalsh(rho) |
| 102 | + eigs = eigs[eigs > 0] |
| 103 | + |
| 104 | + if alpha == float("inf"): |
| 105 | + return -np.log2(eigs.max()) |
| 106 | + |
| 107 | + return np.log2(pow(eigs, alpha).sum()) / (1 - alpha) |
0 commit comments