Skip to content

Commit a6f4f2f

Browse files
authored
Merge pull request #1345 from tnemoz/fix_1088
Added Rényi entropy of a quantum state
2 parents 3ea1b5c + ec8f92c commit a6f4f2f

4 files changed

Lines changed: 167 additions & 0 deletions

File tree

docs/refs.bib

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,19 @@ @misc{Molina_2012_Optimal
987987
primaryClass={quant-ph}
988988
}
989989

990+
@article{Muller_2013_Renyi_Generalization,
991+
title={On quantum Rényi entropies: A new generalization and some properties},
992+
volume={54},
993+
ISSN={1089-7658},
994+
url={http://dx.doi.org/10.1063/1.4838856},
995+
DOI={10.1063/1.4838856},
996+
number={12},
997+
journal={Journal of Mathematical Physics},
998+
publisher={AIP Publishing},
999+
author={Müller-Lennert, Martin and Dupuis, Frédéric and Szehr, Oleg and Fehr, Serge and Tomamichel, Marco},
1000+
year={2013},
1001+
month=dec }
1002+
9901003
% Last name begins with N
9911004
@article{Navascues_2008_AConvergent,
9921005
title={A convergent hierarchy of semidefinite programs characterizing the set of quantum correlations},

toqito/state_props/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@
2626
from toqito.state_props.is_distinguishable import is_distinguishable
2727
from toqito.state_props.is_unextendible_product_basis import is_unextendible_product_basis
2828
from toqito.state_props.common_quantum_overlap import common_quantum_overlap
29+
from toqito.state_props.renyi_entropy import renyi_entropy
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Tests for renyi_entropy."""
2+
3+
import numpy as np
4+
import pytest
5+
6+
from toqito.state_props import purity, renyi_entropy, von_neumann_entropy
7+
from toqito.states import bell, max_mixed
8+
9+
RHO_TEST = np.array([[0.8, 0.0], [0.0, 0.2]])
10+
11+
12+
@pytest.mark.parametrize(
13+
"rho, alpha, expected_result",
14+
[
15+
# Entangled state Rényi entropy should be zero.
16+
(bell(0) @ bell(0).conj().T, 3 / 2, 0),
17+
# Rényi entropy of the maximally mixed state should be one.
18+
(max_mixed(2, is_sparse=False), 5 / 2, 1),
19+
# For alpha=0, log of the number of outcomes
20+
(RHO_TEST, 0.0, 1.0),
21+
# For alpha=1, recovers von Neumann entropy
22+
(RHO_TEST, 1.0, von_neumann_entropy(RHO_TEST)),
23+
# For alpha=2, collision entropy
24+
(RHO_TEST, 2.0, -np.log2(purity(RHO_TEST))),
25+
# For alpha=+inf, min-entropy
26+
(RHO_TEST, float("inf"), -np.log2(0.8)),
27+
],
28+
)
29+
def test_renyi_entropy(rho, alpha, expected_result):
30+
"""Test function works as expected for a valid input."""
31+
np.testing.assert_allclose(renyi_entropy(rho, alpha), expected_result, atol=1e-5)
32+
33+
34+
@pytest.mark.parametrize(
35+
"rho, alpha",
36+
[
37+
# Test Rényi entropy on non-density matrix.
38+
(np.array([[1, 2], [3, 4]]), 3 / 2),
39+
# Test Rényi entropy on non-positive order.
40+
(RHO_TEST, -1.0),
41+
],
42+
)
43+
def test_renyi_invalid_input(rho, alpha):
44+
"""Test function works as expected for an invalid input."""
45+
with np.testing.assert_raises(ValueError):
46+
renyi_entropy(rho, alpha)

0 commit comments

Comments
 (0)