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

Add pydcostyle + pylint in ruff rules #298

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
37 changes: 35 additions & 2 deletions docs/articles.bib
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ @article{Bandyopadhyay_2014_Conclusive
year={2014},
month={Feb}}

@article{Bandyopadhyay_2015_Limitations,
title={Limitations on Separable Measurements by Convex Optimization},
volume={61},
ISSN={1557-9654},
url={http://dx.doi.org/10.1109/TIT.2015.2417755},
DOI={10.1109/tit.2015.2417755},
number={6},
journal={IEEE Transactions on Information Theory},
publisher={Institute of Electrical and Electronics Engineers (IEEE)},
author={Bandyopadhyay, Somshubhro and Cosentino, Alessandro and Johnston, Nathaniel and Russo, Vincent and Watrous, John and Yu, Nengkun},
year={2015},
month=jun, pages={3593-3604} }

@article{Bennett_1999_QuantumNonlocality,
title={Quantum nonlocality without entanglement},
volume={59},
Expand Down Expand Up @@ -92,6 +105,14 @@ @article{Cabello_2002_NParticle
url = {https://link.aps.org/doi/10.1103/Cabello_2002_NParticle}
}

@misc{Chen_2003_Matrix,
title={A matrix realignment method for recognizing entanglement},
author={Kai Chen and Ling-An Wu},
year={2003},
eprint={quant-ph/0205017},
archivePrefix={arXiv},
primaryClass={quant-ph}
}

@article{Chen_2014_Symmetric,
title={Symmetric extension of two-qubit states},
Expand Down Expand Up @@ -652,6 +673,18 @@ @article{Sych_2009_AComplete
}

#Last name begins with T
@article{Terhal_2001_Hiding,
title={Hiding Bits in Bell States},
volume={86},
ISSN={1079-7114},
url={http://dx.doi.org/10.1103/PhysRevLett.86.5807},
DOI={10.1103/physrevlett.86.5807},
number={25},
journal={Physical Review Letters},
publisher={American Physical Society (APS)},
author={Terhal, Barbara M. and DiVincenzo, David P. and Leung, Debbie W.},
year={2001},
month=jun, pages={5807-5810} }

#Last name begins with U

Expand Down Expand Up @@ -929,7 +962,7 @@ @misc{WikiMUB

@misc{WikiNorm,
author = "Wikipedia",
title = "Outer product",
title = "Normal Matrix",
howpublished = {https://en.wikipedia.org/wiki/Normal_matrix}

}
Expand All @@ -944,7 +977,7 @@ @misc{WikiOrthog

@misc{WikiOuterProd,
author = "Wikipedia",
title = "Normal matrix",
title = "Outer Product",
howpublished = {https://en.wikipedia.org/wiki/Outer_product}

}
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ line-length = 120
target-version = "py311"

[tool.ruff.lint]
select = ["I", "E", "W"]
select = ["I", "E", "W", "D", "PL"]
# ruff configuration
# E, W -- pycodestyle
# D -- pydocstyle
Expand All @@ -68,7 +68,7 @@ select = ["I", "E", "W"]
# Rules considered over other incompatible ones
exclude = ["docs/conf.py", "setup.py"]

ignore = ["D407", "D203", "D213", "D416", "PLR0912", "PLR0911", "PLR0915"]
ignore = ["D407", "D203", "D213", "D416", "PLR0912", "PLR0911", "PLR0915", "PLR2004"]
# Rules Ignored

# D407 - Ignored because ==== under a section heading is considered as a missing underline.
Expand All @@ -84,6 +84,7 @@ ignore = ["D407", "D203", "D213", "D416", "PLR0912", "PLR0911", "PLR0915"]
# PLR0912 -- Checks for functions or methods with too many branches. The default number is 12.
# PLR0911 -- Checks for functions or methods with too many return statements. The default number is 6.
# PLR0915 -- Checks for functions or methods with too many statements. The default number is 50.
# PLR2004 -- Checks if an equality or an inequality is compared to a variable or a num (prefers variable pre)

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["I001"]
Expand Down
3 changes: 1 addition & 2 deletions toqito/channel_metrics/channel_fidelity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@


def channel_fidelity(choi_1: np.ndarray, choi_2: np.ndarray) -> float:
r"""
Compute the channel fidelity between two quantum channels :cite:`Katariya_2021_Geometric`.
r"""Compute the channel fidelity between two quantum channels :cite:`Katariya_2021_Geometric`.

Let :math:`\Phi : \text{L}(\mathcal{Y}) \rightarrow \text{L}(\mathcal{X})` and
:math:`\Psi: \text{L}(\mathcal{Y}) \rightarrow \text{L}(\mathcal{X})` be quantum channels. Then
Expand Down
3 changes: 1 addition & 2 deletions toqito/channel_metrics/completely_bounded_trace_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@


def completely_bounded_trace_norm(phi: np.ndarray) -> float:
r"""
Find the completely bounded trace norm of a quantum channel.
r"""Find the completely bounded trace norm of a quantum channel.

Also known as the completely bounded diamond norm of a quantum
channel (Section 3.3.2 of :cite:`Watrous_2018_TQI`). The algorithm in p.11 of :cite:`Watrous_2012_Simpler` with
Expand Down
3 changes: 1 addition & 2 deletions toqito/channel_metrics/diamond_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@


def diamond_norm(choi_1: np.ndarray, choi_2: np.ndarray) -> float:
r"""
Return the diamond norm distance between two quantum channels.
r"""Return the diamond norm distance between two quantum channels.

The calculation uses the simplified semidefinite program of Watrous in
:cite:`Watrous_2009_Semidefinite`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


def test_dual_is_cb_trace_norm():
"""Test CB Spectral norm of a dephasing channel is the same as the CB Trace norm of a dephasing channel."""
phi = dephasing(2)
np.testing.assert_equal(
completely_bounded_spectral_norm(phi), completely_bounded_trace_norm(dual_channel(phi))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ def test_cb_trace_norm_CP():


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."""
"""Test the CB trace norm of phi.

The diamond norm of phi = id- U id U* is the diameter of the smallest circle 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)
Expand Down
3 changes: 1 addition & 2 deletions toqito/channel_ops/choi_to_kraus.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
def choi_to_kraus(
choi_mat: np.ndarray, tol: float = 1e-9, dim: int | list[int] | np.ndarray = None
) -> list[np.ndarray] | list[list[np.ndarray]]:
r"""
Compute a list of Kraus operators from the Choi matrix from :cite:`Rigetti_2022_Forest`.
r"""Compute a list of Kraus operators from the Choi matrix from :cite:`Rigetti_2022_Forest`.

Note that unlike the Choi or natural representation of operators, the Kraus representation is
*not* unique.
Expand Down
13 changes: 4 additions & 9 deletions toqito/channel_ops/tests/test_apply_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@


def test_apply_channel_choi():
"""
The swap operator is the Choi matrix of the transpose map.
"""The swap operator is the Choi matrix of the transpose map.

The following test is a (non-ideal, but illustrative) way of computing
the transpose of a matrix.
Expand All @@ -25,8 +24,7 @@ def test_apply_channel_choi():


def test_apply_channel_choi_non_square():
"""
The swap operator is the Choi matrix of the transpose map.
"""The swap operator is the Choi matrix of the transpose map.

The following test is a (non-ideal, but illustrative) way of computing
the transpose of a non square matrix.
Expand All @@ -42,8 +40,7 @@ def test_apply_channel_choi_non_square():


def test_apply_channel_kraus():
"""
Apply Kraus map.
"""Apply Kraus map.

The following test computes PHI(X) where X = [[1, 2], [3, 4]] and
where PHI is the superoperator defined by:
Expand All @@ -67,9 +64,7 @@ def test_apply_channel_kraus():

@pytest.mark.parametrize("nested", [1, 2, 3])
def test_apply_channel_cpt_kraus(nested):
"""
Apply Kraus map of single qubit depolarizing channel.
"""
"""Apply Kraus map of single qubit depolarizing channel."""
test_input_mat = np.array([[1, 0], [0, 0]])

expected_res = np.array([[0.5, 0], [0, 0.5]])
Expand Down
2 changes: 0 additions & 2 deletions toqito/channel_ops/tests/test_choi_to_kraus.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

def test_choi_to_kraus():
"""Choi matrix of the swap operator."""

choi_mat = np.array([[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]])
kraus_ops = [
[
Expand Down Expand Up @@ -58,7 +57,6 @@ def test_choi_to_kraus_cpt():

def test_choi_to_kraus_non_square():
"""Choi matrix of the swap operator for non square input/output."""

choi_mat = swap_operator([2, 3])
kraus_ops = [
[
Expand Down
9 changes: 6 additions & 3 deletions toqito/channel_ops/tests/test_dual_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,17 @@ def test_dual_channel_not_matrix():


def test_dual_channel_unspecified_dims():
"""If the size of the Choi matrix is not a perfect square,
the dimensions of the input and output spaces must be specified."""
"""Test output of function when the dimensions must be specified.

If the size of the Choi matrix is not a perfect square, the dimensions of the input and output spaces must be
specified.
"""
with np.testing.assert_raises(ValueError):
j = np.arange(36).reshape(6, 6)
dual_channel(j)


def test_dual_channel_invalid_input():
"""Invalid input"""
"""Test error is raised for an invalid input."""
with np.testing.assert_raises(ValueError):
dual_channel([0])
21 changes: 6 additions & 15 deletions toqito/channel_ops/tests/test_partial_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@


def test_partial_channel_depolarizing_first_system():
"""
Perform the partial map using the depolarizing channel as the Choi
matrix on first system.
"""
"""Perform the partial map using the depolarizing channel as the Choi matrix on first system."""
rho = np.array(
[
[
Expand Down Expand Up @@ -56,10 +53,7 @@ def test_partial_channel_depolarizing_first_system():


def test_partial_channel_depolarizing_second_system():
"""
Perform the partial map using the depolarizing channel as the Choi
matrix on second system.
"""
"""Perform the partial map using the depolarizing channel as the Choi matrix on second system."""
rho = np.array(
[
[
Expand Down Expand Up @@ -104,9 +98,9 @@ def test_partial_channel_depolarizing_second_system():


def test_partial_channel_dim_list():
"""
Perform the partial map using the depolarizing channel as the Choi
matrix on first system when the dimension is specified as list.
"""Perform the partial map.

Test uses the depolarizing channel as the Choi matrix on first system when the dimension is specified as list.
"""
rho = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])
res = partial_channel(rho, depolarizing(2), 2, [2, 2])
Expand All @@ -126,10 +120,7 @@ def test_partial_channel_dim_list():

@pytest.mark.parametrize("nested", [1, 2, 3])
def test_partial_channel_cpt_kraus(nested):
"""
Perform the partial map using the Kraus representation of
the depolarizing channel.
"""
"""Perform the partial map using the Kraus representation of the depolarizing channel."""
rho = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])
kraus = [0.5 * pauli(ind) for ind in range(4)]
if nested == 2:
Expand Down
3 changes: 1 addition & 2 deletions toqito/channel_props/is_trace_preserving.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def is_trace_preserving(
sys: int | list[int] = 2,
dim: list[int] | np.ndarray = None,
) -> bool:
r"""
Determine whether the given channel is trace-preserving.
r"""Determine whether the given channel is trace-preserving.

A map :math:`\Phi \in \text{T} \left(\mathcal{X}, \mathcal{Y} \right)` is
*trace-preserving* if it holds that
Expand Down
3 changes: 1 addition & 2 deletions toqito/channel_props/is_unital.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ def is_unital(
atol: float = 1e-08,
dim: int | list[int] | np.ndarray = None,
) -> bool:
r"""
Determine whether the given channel is unital.
r"""Determine whether the given channel is unital.

A map :math:`\Phi \in \text{T} \left(\mathcal{X}, \mathcal{Y} \right)` is *unital* if it holds that:

Expand Down
8 changes: 5 additions & 3 deletions toqito/channel_props/tests/test_choi_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def test_choi_rank_list_kraus():
"""Verify that a list of Kraus operators gives correct Choi rank"""
"""Verify that a list of Kraus operators gives correct Choi rank."""
kraus_1 = np.array([[1, 0], [0, 0]])
kraus_2 = np.array([[1, 0], [0, 0]]).conj().T
kraus_3 = np.array([[0, 1], [0, 0]])
Expand All @@ -32,8 +32,10 @@ def test_choi_rank_choi_matrix():


def test_choi_bad_input():
"""Verify that a bad input (such as a string which still passes
with `numpy.linalg.matrix_rank`) raises an error"""
"""Verify that a bad input raises an error.

The bad input is a string which still passes with `numpy.linalg.matrix_rank`.
"""
with pytest.raises(ValueError, match="Not a valid"):
bad_input = "string"
choi_rank(bad_input)
3 changes: 1 addition & 2 deletions toqito/channels/choi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@


def choi(a_var: int = 1, b_var: int = 1, c_var: int = 0) -> np.ndarray:
r"""
Produce the Choi channel or one of its generalizations :cite:`Choi_1992_Generalized`.
r"""Produce the Choi channel or one of its generalizations :cite:`Choi_1992_Generalized`.

The *Choi channel* is a positive map on 3-by-3 matrices that is capable of detecting some
entanglement that the transpose map is not.
Expand Down
3 changes: 1 addition & 2 deletions toqito/channels/partial_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def partial_trace(
sys: int | list[int] = None,
dim: int | list[int] = None,
) -> np.ndarray | Expression:
r"""
Compute the partial trace of a matrix :cite:`WikiPartialTr`.
r"""Compute the partial trace of a matrix :cite:`WikiPartialTr`.

The *partial trace* is defined as

Expand Down
3 changes: 1 addition & 2 deletions toqito/channels/realignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@


def realignment(input_mat: np.ndarray, dim: int | list[int] = None) -> np.ndarray:
r"""
Compute the realignment of a bipartite operator :cite:`Lupo_2008_Bipartite`.
r"""Compute the realignment of a bipartite operator :cite:`Lupo_2008_Bipartite`.

Gives the realignment of the matrix :code:`input_mat`, where it is assumed that the number
of rows and columns of :code:`input_mat` are both perfect squares and both subsystems have
Expand Down
3 changes: 1 addition & 2 deletions toqito/channels/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@


def reduction(dim: int, k: int = 1) -> np.ndarray:
r"""
Produce the reduction map or reduction channel :cite:`WikiReductionCrit`.
r"""Produce the reduction map or reduction channel :cite:`WikiReductionCrit`.

If :code:`k = 1`, this returns the Choi matrix of the reduction map which is a positive map
on :code:`dim`-by-:code:`dim` matrices. For a different value of :code:`k`, this yields the
Expand Down
3 changes: 1 addition & 2 deletions toqito/channels/tests/test_choi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def test_choi_standard():


def test_choi_reduction():
"""
The reduction map is the map R defined by: R(X) = Tr(X)I - X.
"""The reduction map is the map R defined by: R(X) = Tr(X)I - X.

The reduction map is the Choi map that arises when a = 0, b = c = 1.
"""
Expand Down
Loading