From b328a92d464ff5ffbd21b3858b921e5f02d90e96 Mon Sep 17 00:00:00 2001 From: Eugene Rublenko <16805621+stand-by@users.noreply.github.com> Date: Mon, 22 Jul 2024 12:35:21 -0400 Subject: [PATCH] Make code compliant with new linting and formatting rules --- README.md | 2 +- fast_pauli/cpp/include/__pauli_op.hpp | 2 +- fast_pauli/cpp/include/__pauli_string.hpp | 2 +- fast_pauli/cpp/tests/test_pauli_string.cpp | 2 +- fast_pauli/py/pypauli/helpers.py | 2 +- fast_pauli/py/pypauli/operations.py | 2 +- fast_pauli/py/tests/test_operations.py | 20 ++++++++++---------- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 15a5b51..8050733 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ - [X] PauliString - [ ] PauliOp - [ ] SummedPauliOp -- [ ] Figure out the tranpose non-sense or support both (some functions take the transpose of the states and others don't) +- [ ] Figure out the transpose non-sense or support both (some functions take the transpose of the states and others don't) - [ ] Clean up `apply_batch` we shouldn't need to pass a coeff - [ ] Clean up tests - [ ] Add apply method to SummedPauliOp that takes precomputed weighted data diff --git a/fast_pauli/cpp/include/__pauli_op.hpp b/fast_pauli/cpp/include/__pauli_op.hpp index e886f45..df1771a 100644 --- a/fast_pauli/cpp/include/__pauli_op.hpp +++ b/fast_pauli/cpp/include/__pauli_op.hpp @@ -163,7 +163,7 @@ template struct PauliOp { ps.apply_batch(new_states_local, states, c); } - // Do the reduction and tranpose back + // Do the reduction and transpose back #pragma omp for schedule(static) collapse(2) for (size_t i = 0; i < new_states.extent(0); ++i) { for (size_t t = 0; t < new_states.extent(1); ++t) { diff --git a/fast_pauli/cpp/include/__pauli_string.hpp b/fast_pauli/cpp/include/__pauli_string.hpp index ec51d3f..b2f8b88 100644 --- a/fast_pauli/cpp/include/__pauli_string.hpp +++ b/fast_pauli/cpp/include/__pauli_string.hpp @@ -252,7 +252,7 @@ struct PauliString { * columns * * @tparam T The floating point base to use for all the complex numbers - * @param new_states_T The outpus states after applying the PauliString + * @param new_states_T The output states after applying the PauliString * (n_data x n_dim) * @param states_T THe original states to apply the PauliString to (n_data x * n_dim) diff --git a/fast_pauli/cpp/tests/test_pauli_string.cpp b/fast_pauli/cpp/tests/test_pauli_string.cpp index d261bee..5c31721 100644 --- a/fast_pauli/cpp/tests/test_pauli_string.cpp +++ b/fast_pauli/cpp/tests/test_pauli_string.cpp @@ -201,7 +201,7 @@ TEST_CASE("test apply batch") { size_t const n_states = 10; // Testing each of these pauli strings individually - // NOTE: apply_batch takes the tranpose of the states and new_states + // NOTE: apply_batch takes the transpose of the states and new_states for (PauliString ps : {"IXYZ", "YYIX", "XXYIYZ", "IZIXYYZ"}) { size_t const dims = ps.dims(); diff --git a/fast_pauli/py/pypauli/helpers.py b/fast_pauli/py/pypauli/helpers.py index f7dbf1a..5ba51bb 100644 --- a/fast_pauli/py/pypauli/helpers.py +++ b/fast_pauli/py/pypauli/helpers.py @@ -3,7 +3,7 @@ import numpy as np -def pauli_matrices() -> dict: +def pauli_matrices() -> dict[str | int, np.ndarray]: """Provide a dictionary containing the Pauli matrices. The Pauli matrices are a set of 2x2 matrices commonly used in quantum mechanics. diff --git a/fast_pauli/py/pypauli/operations.py b/fast_pauli/py/pypauli/operations.py index bc97728..49010fa 100644 --- a/fast_pauli/py/pypauli/operations.py +++ b/fast_pauli/py/pypauli/operations.py @@ -113,7 +113,7 @@ def compose_sparse_pauli(string: str) -> tuple[np.ndarray, np.ndarray]: return cols, vals -def compose_sparse_diag_pauli(string) -> np.ndarray: +def compose_sparse_diag_pauli(string: str) -> np.ndarray: """Produce sparse representation of diagonal pauli string. Args: diff --git a/fast_pauli/py/tests/test_operations.py b/fast_pauli/py/tests/test_operations.py index 07e5343..a790fa8 100644 --- a/fast_pauli/py/tests/test_operations.py +++ b/fast_pauli/py/tests/test_operations.py @@ -13,12 +13,12 @@ @pytest.fixture -def paulis(): +def paulis() -> dict[str | int, np.ndarray]: """Fixture to provide dict with Pauli matrices.""" - return pauli_matrices() + return pauli_matrices() # type: ignore -def test_pauli_string(paulis): +def test_pauli_string(paulis: dict) -> None: """Test the PauliString class.""" for p in ["I", "X", "Y", "Z"]: ps = PauliString(p) @@ -60,7 +60,7 @@ def test_pauli_string(paulis): assert PauliString("ZIXIZYXXY").weight == 7 -def test_sparse_pauli_composer(paulis): +def test_sparse_pauli_composer(paulis: dict) -> None: """Test sparsepauli composer functions.""" ps = PauliString("II") assert ps.dim == 4 @@ -104,7 +104,7 @@ def test_sparse_pauli_composer(paulis): ) -def test_sparse_pauli_composer_equivalence(): +def test_sparse_pauli_composer_equivalence() -> None: """Test the equivalence of sparse Pauli composer with naive method.""" for c in ["I", "X", "Y", "Z"]: np.testing.assert_array_equal( @@ -112,15 +112,15 @@ def test_sparse_pauli_composer_equivalence(): naive_pauli_converter(c), ) - for s in permutations("XYZ", 2): - s = "".join(s) + for p2 in permutations("XYZ", 2): + s = "".join(p2) np.testing.assert_array_equal( PauliString(s).dense(), naive_pauli_converter(s), ) - for s in permutations("IXYZ", 3): - s = "".join(s) + for p3 in permutations("IXYZ", 3): + s = "".join(p3) np.testing.assert_array_equal( PauliString(s).dense(), naive_pauli_converter(s), @@ -138,7 +138,7 @@ def test_sparse_pauli_composer_equivalence(): np.testing.assert_array_equal(PauliString(s).dense(), naive_pauli_converter(s)) -def test_sparse_pauli_multiply(): +def test_sparse_pauli_multiply() -> None: """Test the equivalence of multiply method that relies on sparse Pauli composer.""" rng = np.random.default_rng(321)