Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pytest coverage for CB trace norm #234

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions tests/test_channel_metrics/test_completely_bounded_trace_norm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for completely_bounded_trace_norm."""
import numpy as np
import pytest

from toqito.channel_metrics import completely_bounded_trace_norm
from toqito.channel_ops import kraus_to_choi
Expand All @@ -9,27 +10,31 @@
def test_cb_trace_norm_quantum_channel():
"""The diamond norm of a quantum channel is 1."""
phi = dephasing(2)
np.testing.assert_equal(completely_bounded_trace_norm(phi), 1)
assert completely_bounded_trace_norm(phi) == 1


def test_cb_trace_norm_CP():
"""Test for the diamond norm of a CP map."""
non_normalized_depolarizing_array = np.eye(4)
assert completely_bounded_trace_norm(non_normalized_depolarizing_array) == 4.0

purva-thakre marked this conversation as resolved.
Show resolved Hide resolved

def test_cb_trace_norm_unitaries_channel():
"""The diamond norm of phi = id- U id U* is the diameter of the smallest circle that contains the eigenvalues of U."""
"""The diamond norm of phi = id- U id U* is the diameter of the smallest circle
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the linter is over-aggressively making new lines here when it shouldn't be?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably due to us having different configuration files with incompatible line lengths.

that contains the eigenvalues of U."""
U = 1 / np.sqrt(2) * np.array([[1, 1], [-1, 1]]) # Hadamard gate
phi = kraus_to_choi([[np.eye(2), np.eye(2)], [U, -U]])
lam, _ = np.linalg.eig(U)
dist = np.abs(lam[:, None] - lam[None, :]) # all to all distance
diameter = np.max(dist)
np.testing.assert_equal(
np.isclose(completely_bounded_trace_norm(phi), diameter, atol=1e-3), True
)
assert np.isclose(completely_bounded_trace_norm(phi), diameter, atol=1e-3)


def test_cb_trace_norm_non_square():
"""Non-square inputs for cb trace norm."""
with np.testing.assert_raises(ValueError):
with pytest.raises(
ValueError,
match="The input and output spaces of the superoperator phi must both be square.",
):
phi = np.array([[1, 2, 3], [4, 5, 6]])
completely_bounded_trace_norm(phi)


if __name__ == "__main__":
np.testing.run_module_suite()