From d644294bea4cca126ea8ceae99de403472d8243b Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Thu, 3 Oct 2024 10:55:36 +0400 Subject: [PATCH] test --- tests/test_quantum_info_entropies.py | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_quantum_info_entropies.py b/tests/test_quantum_info_entropies.py index b383effed6..f844146c7e 100644 --- a/tests/test_quantum_info_entropies.py +++ b/tests/test_quantum_info_entropies.py @@ -6,6 +6,7 @@ classical_mutual_information, classical_relative_entropy, classical_relative_renyi_entropy, + classical_relative_tsallis_entropy, classical_renyi_entropy, classical_tsallis_entropy, entanglement_entropy, @@ -382,6 +383,36 @@ def test_classical_tsallis_entropy(backend, alpha, base, kind): ) +@pytest.mark.parametrize("kind", [None, list]) +@pytest.mark.parametrize("base", [2, 10, np.e, 5]) +@pytest.mark.parametrize("alpha", [0, 1, 2, 3]) +def test_classical_relative_tsallis_entropy(backend, alpha, base, kind): + prob_dist_p = np.random.rand(10) + prob_dist_p /= np.sum(prob_dist_p) + + prob_dist_q = np.random.rand(10) + prob_dist_q /= np.sum(prob_dist_q) + + prob_dist_p = backend.np.real(backend.cast(prob_dist_p)) + prob_dist_q = backend.np.real(backend.cast(prob_dist_q)) + + if alpha == 1.0: + target = classical_relative_entropy(prob_dist_p, prob_dist_q, base, backend) + else: + target = ((prob_dist_p / prob_dist_q) ** (1 - alpha) - 1) / (1 - alpha) + target = backend.np.sum(prob_dist_p**alpha * target) + + if kind is not None: + prob_dist_p = kind(prob_dist_p) + prob_dist_q = kind(prob_dist_q) + + value = classical_relative_tsallis_entropy( + prob_dist_p, prob_dist_q, alpha, base, backend + ) + + backend.assert_allclose(value, target) + + @pytest.mark.parametrize("check_hermitian", [False, True]) @pytest.mark.parametrize("base", [2, 10, np.e, 5]) def test_von_neumann_entropy(backend, base, check_hermitian):