Skip to content

Commit

Permalink
[feature/nanobind] Making ruff/mypy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesETsmith committed Aug 26, 2024
1 parent 3ae9f56 commit bf9b055
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions nanobind_test/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys

import numpy as np
import pytest

Expand All @@ -25,7 +26,7 @@ def my_op() -> mdspan_wrapper.PauliOp:
return mdspan_wrapper.PauliOp(pauli_strings, coeffs)


def test_fake_pauli_op_scope(my_op) -> None:
def test_fake_pauli_op_scope(my_op: mdspan_wrapper.PauliOp) -> None:
my_op.scale(2.0)
op2 = mdspan_wrapper.PauliOp(
np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0]], dtype=np.int32),
Expand All @@ -51,7 +52,7 @@ def test_fake_pauli_op_scope(my_op) -> None:
assert my_op == op2


def test_multiply_coeff(my_op) -> None:
def test_multiply_coeff(my_op: mdspan_wrapper.PauliOp) -> None:
coeffs = np.array([1.0, 2.0, 3.0])
my_op.multiply_coeff(coeffs)
op2 = mdspan_wrapper.PauliOp(
Expand All @@ -61,13 +62,13 @@ def test_multiply_coeff(my_op) -> None:
assert my_op == op2


def test_multiply_coeff_diff_type(my_op) -> None:
def test_multiply_coeff_diff_type(my_op: mdspan_wrapper.PauliOp) -> None:
coeffs = np.array([1.0, 2.0, 3.0], dtype=np.complex128)
with pytest.raises(TypeError):
my_op.multiply_coeff(coeffs)


def test_return_coeffs_non_owning(my_op) -> None:
def test_return_coeffs_non_owning(my_op: mdspan_wrapper.PauliOp) -> None:
c = np.zeros(3)
print(c)
my_op.return_coeffs(c)
Expand All @@ -76,7 +77,7 @@ def test_return_coeffs_non_owning(my_op) -> None:
np.testing.assert_allclose(c, np.array([1.0, 2.0, 3.0]))


def test_return_coeffs_owning(my_op) -> None:
def test_return_coeffs_owning(my_op: mdspan_wrapper.PauliOp) -> None:
c = my_op.return_coeffs_owning()
print("returned array", c)
np.testing.assert_allclose(c, np.array([1.0, 2.0, 3.0]))
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ strict_optional = true
ignore_missing_imports = true
explicit_package_bases = true

exclude = ["nanobind_test"]
exclude = []

[tool.ruff]
exclude = [
Expand Down Expand Up @@ -94,6 +94,7 @@ exclude = [
"venv",
".venv",
"fast_pauli/__version__.py",
"nanobind_test"
]

line-length = 88
Expand Down

0 comments on commit bf9b055

Please sign in to comment.