Skip to content

Commit

Permalink
Change test_array_backends mixin classes to subclass QiskitDynamicsTe…
Browse files Browse the repository at this point in the history
…stCase (#272)
  • Loading branch information
DanPuzzuoli authored Oct 18, 2023
1 parent c595d8d commit 3a373cf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions test/dynamics/arraylias/test_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
from qiskit_dynamics import DYNAMICS_NUMPY as unp
from qiskit_dynamics import DYNAMICS_SCIPY as usp

from ..common import QiskitDynamicsTestCase, test_array_backends
from ..common import test_array_backends


@partial(test_array_backends, array_libraries=["numpy", "jax", "array_numpy", "array_jax"])
class TestDynamicsNumpy(QiskitDynamicsTestCase):
class TestDynamicsNumpy:
"""Test cases for global numpy configuration."""

def test_simple_case(self):
Expand All @@ -41,7 +41,7 @@ def test_simple_case(self):


@test_array_backends
class TestDynamicsScipy(QiskitDynamicsTestCase):
class TestDynamicsScipy:
"""Test cases for global scipy configuration."""

def test_simple_case(self):
Expand Down
14 changes: 9 additions & 5 deletions test/dynamics/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
``assertArrayType`` method for validating that an array is from that library. These classes can
also implement any required setup and teardown methods for working with that library (e.g.
``JAXTestBase`` skips tests if running on windows).
- Each ``<array_library>TestBase`` subclasses ``QiskitDynamicsTestCase``.
- When used on a given ``test_class``, the decorator ``test_array_backends`` creates a series of
subclasses inheriting from ``test_class`` and a desired list of ``<array_library>TestBase``. The
desired list is specified via the ``array_libraries`` argument, which are matched against the
Expand Down Expand Up @@ -76,7 +77,7 @@ def assertAllCloseSparse(self, A, B, rtol=1e-8, atol=1e-8):
self.assertTrue(np.allclose(A, B, rtol=rtol, atol=atol))


class NumpyTestBase(unittest.TestCase):
class NumpyTestBase(QiskitDynamicsTestCase):
"""Base class for tests working with numpy arrays."""

@classmethod
Expand All @@ -93,7 +94,7 @@ def assertArrayType(self, a):
return isinstance(a, np.ndarray)


class JAXTestBase(unittest.TestCase):
class JAXTestBase(QiskitDynamicsTestCase):
"""Base class for tests working with JAX arrays."""

@classmethod
Expand Down Expand Up @@ -121,7 +122,7 @@ def assertArrayType(self, a):
return isinstance(a, jnp.ndarray)


class ArrayNumpyTestBase(unittest.TestCase):
class ArrayNumpyTestBase(QiskitDynamicsTestCase):
"""Base class for tests working with qiskit_dynamics Arrays with numpy backend."""

@classmethod
Expand All @@ -138,7 +139,7 @@ def assertArrayType(self, a):
return isinstance(a, Array) and a.backend == "numpy"


class ArrayJaxTestBase(unittest.TestCase):
class ArrayJaxTestBase(QiskitDynamicsTestCase):
"""Base class for tests working with qiskit_dynamics Arrays with jax backend."""

@classmethod
Expand Down Expand Up @@ -178,7 +179,10 @@ def test_array_backends(test_class: Type, array_libraries: Optional[List[str]] =
Creates subclasses of ``test_class`` with any class in this file implementing an
``array_library`` class method whose output matches an entry of ``array_libraries``. These
classes are added to the calling module, and the original ``test_class`` is deleted.
classes are added to the calling module, and the original ``test_class`` is deleted. The classes
in this file implementing ``array_library`` are assumed to be a subclass of
``QiskitDynamicsTestCase``, and hence ``test_class`` should not already be a subclass of
``QiskitDynamicsTestCase`` or ``unittest.TestCase``.
Read the file doc string for the intended usage.
Expand Down

0 comments on commit 3a373cf

Please sign in to comment.