Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomello committed Oct 3, 2024
1 parent fc46733 commit d644294
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_quantum_info_entropies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit d644294

Please sign in to comment.