Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomello committed Sep 18, 2024
1 parent 4f1e28e commit cbda593
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/test_quantum_info_entropies.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
from qibo.config import PRECISION_TOL
from qibo.quantum_info.entropies import (
_matrix_power,
classical_mutual_information,
classical_relative_entropy,
classical_relative_renyi_entropy,
classical_renyi_entropy,
classical_tsallis_entropy,
entanglement_entropy,
mutual_information,
relative_renyi_entropy,
relative_von_neumann_entropy,
renyi_entropy,
Expand Down Expand Up @@ -125,6 +127,25 @@ def test_classical_relative_entropy(backend, base, kind):
backend.assert_allclose(divergence, target, atol=1e-5)


@pytest.mark.parametrize("base", [2, 10, np.e, 5])
def test_classical_mutual_information(backend, base):
prob_p = np.random.rand(10)
prob_q = np.random.rand(10)
prob_p /= np.sum(prob_p)
prob_q /= np.sum(prob_q)

joint_dist = np.kron(prob_p, prob_q)
joint_dist /= np.sum(joint_dist)

prob_p = backend.cast(prob_p, dtype=prob_p.dtype)
prob_q = backend.cast(prob_q, dtype=prob_q.dtype)
joint_dist = backend.cast(joint_dist, dtype=joint_dist.dtype)

assert (
classical_mutual_information(joint_dist, prob_p, prob_q, base, backend) == 0.0
)


@pytest.mark.parametrize("kind", [None, list])
@pytest.mark.parametrize("base", [2, 10, np.e, 5])
@pytest.mark.parametrize("alpha", [0, 1, 2, 3, np.inf])
Expand Down Expand Up @@ -499,6 +520,18 @@ def test_relative_entropy(backend, base, check_hermitian):
)


@pytest.mark.parametrize("check_hermitian", [False, True])
@pytest.mark.parametrize("base", [2, 10, np.e, 5])
def test_mutual_information(backend, base, check_hermitian):
state_a = random_density_matrix(4, backend=backend)
state_b = random_density_matrix(4, backend=backend)
state = backend.np.kron(state_a, state_b)

assert (
mutual_information(state, [0, 1], base, check_hermitian, backend) == 0.0
)


@pytest.mark.parametrize("base", [2, 10, np.e, 5])
@pytest.mark.parametrize("alpha", [0, 1, 2, 3, np.inf])
def test_renyi_entropy(backend, alpha, base):
Expand Down

0 comments on commit cbda593

Please sign in to comment.