Skip to content

Commit

Permalink
uncomment failing tests + change import path
Browse files Browse the repository at this point in the history
  • Loading branch information
purva-thakre committed Nov 13, 2023
1 parent 523bf11 commit 9679322
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
31 changes: 16 additions & 15 deletions tests/test_channel_metrics/test_channel_fidelity.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@
from toqito.channel_metrics import channel_fidelity
from toqito.channels import dephasing, depolarizing

# def test_channel_fidelity_same_channel():
# """The fidelity of identical channels should yield 1."""
# choi_1 = dephasing(4)
# choi_2 = dephasing(4)
# np.testing.assert_equal(np.isclose(channel_fidelity(choi_1, choi_2), 1, atol=1e-3), True)
dephasing_channel = dephasing(4)
depolarizing_channel = depolarizing(4)


# def test_channel_fidelity_different_channel():
# """Calculate the channel fidelity of different channels."""
# choi_1 = dephasing(4)
# choi_2 = depolarizing(4)
# np.testing.assert_equal(np.isclose(channel_fidelity(choi_1, choi_2), 1 / 2, atol=1e-3), True)
def test_channel_fidelity_same_channel():
"""The fidelity of identical channels should yield 1."""
assert np.isclose(channel_fidelity(dephasing_channel, dephasing_channel), 1, atol=1e-3)


def test_channel_fidelity_different_channel():
"""Calculate the channel fidelity of different channels."""
assert np.isclose(channel_fidelity(dephasing_channel, depolarizing_channel), 1 / 2, atol=1e-3)


def test_channel_fidelity_inconsistent_dims():
"""Inconsistent dimensions between Choi matrices."""
with pytest.raises(ValueError, match='The Choi matrices provided should be of equal dimension.'):
choi_1 = depolarizing(4)
choi_2 = dephasing(2)
channel_fidelity(choi_1, choi_2)
with pytest.raises(
ValueError, match="The Choi matrices provided should be of equal dimension."
):
small_dim_depolarizing_channel = depolarizing(2)
channel_fidelity(depolarizing_channel, small_dim_depolarizing_channel)


def test_channel_fidelity_non_square():
"""Non-square inputs for channel fidelity."""
with pytest.raises(ValueError, match='The Choi matrix provided must be square.'):
with pytest.raises(ValueError, match="The Choi matrix provided must be square."):
choi_1 = np.array([[1, 2, 3], [4, 5, 6]])
choi_2 = np.array([[1, 2, 3], [4, 5, 6]])
channel_fidelity(choi_1, choi_2)
2 changes: 1 addition & 1 deletion toqito/channel_metrics/channel_fidelity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import cvxpy
import numpy as np

from picos import partial_trace
from toqito.channels import partial_trace


def channel_fidelity(choi_1: np.ndarray, choi_2: np.ndarray) -> float:
Expand Down

0 comments on commit 9679322

Please sign in to comment.