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

improving test coverage for float precision variants in backends #1145

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions PySDM/backends/numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class Numba( # pylint: disable=too-many-ancestors,duplicate-code

default_croupier = "local"

def __init__(self, formulae=None, double_precision=True):
def __init__(self, formulae=None, *, double_precision=True):
if not double_precision:
raise NotImplementedError()
raise NotImplementedError() # TODO #1144
self.formulae = formulae or Formulae()
CollisionsMethods.__init__(self)
PairMethods.__init__(self)
Expand Down
2 changes: 1 addition & 1 deletion PySDM/backends/thrust_rtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ThrustRTC( # pylint: disable=duplicate-code,too-many-ancestors
default_croupier = "global"

def __init__(
self, formulae=None, double_precision=False, debug=False, verbose=False
self, formulae=None, *, double_precision=False, debug=False, verbose=False
):
self.formulae = formulae or Formulae()

Expand Down
13 changes: 2 additions & 11 deletions tests/unit_tests/backends/test_freezing_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,8 @@ def test_freeze_singular(backend_class):
)

@staticmethod
@pytest.mark.parametrize("double_precision", (True, False))
# pylint: disable=too-many-locals
def test_freeze_time_dependent(backend_class, double_precision, plot=False):
if backend_class.__name__ == "Numba" and not double_precision:
pytest.skip()

def test_freeze_time_dependent(backend_class, plot=False):
# Arrange
seed = 44
cases = (
Expand Down Expand Up @@ -151,12 +147,7 @@ def low(t):
key = f"{case['dt']}:{case['N']}"
output[key] = {"unfrozen_fraction": [], "dt": case["dt"], "N": case["N"]}

builder = Builder(
n_sd=n_sd,
backend=backend_class(
formulae=formulae, double_precision=double_precision
),
)
builder = Builder(n_sd=n_sd, backend=backend_class(formulae=formulae))
env = Box(dt=case["dt"], dv=d_v)
builder.set_environment(env)
builder.add_dynamic(Freezing(singular=False))
Expand Down
22 changes: 21 additions & 1 deletion tests/unit_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@
from PySDM.backends import CPU, GPU


@pytest.fixture(params=(CPU, GPU))
class GPUFP32(GPU): # pylint: disable=too-many-ancestors
def __init__(self, formulae=None, **kwargs):
if "double_precision" in kwargs:
if kwargs["double_precision"]:
pytest.skip()
else:
del kwargs["double_precision"]
super().__init__(formulae=formulae, double_precision=False, **kwargs)


class GPUFP64(GPU): # pylint: disable=too-many-ancestors
def __init__(self, formulae=None, **kwargs):
if "double_precision" in kwargs:
if kwargs["double_precision"]:
del kwargs["double_precision"]
else:
pytest.skip()
super().__init__(formulae=formulae, double_precision=True, **kwargs)


@pytest.fixture(params=(CPU, GPUFP32, GPUFP64)) # TODO #1144 CPU float
def backend_class(request):
return request.param
2 changes: 1 addition & 1 deletion tests/unit_tests/dummy_particulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class DummyParticulator(Builder, Particulator):
def __init__(self, backend_class, n_sd=0, formulae=None, grid=None):
backend = backend_class(formulae, double_precision=True)
backend = backend_class(formulae=formulae, double_precision=True)
Builder.__init__(self, n_sd, backend)
Particulator.__init__(self, n_sd, backend)
self.particulator = self
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/dynamics/collisions/test_croupiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

@pytest.mark.parametrize("croupier", ["local", "global"])
def test_final_state(croupier, backend_class):
if backend_class is ThrustRTC:
return # TODO #330
if issubclass(backend_class, ThrustRTC):
pytest.skip() # TODO #330

# Arrange
n_part = 100000
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/dynamics/test_relaxed_velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def test_small_timescale(default_attributes, constant_timescale, backend_class):
When the fall velocity is initialized to 0 and relaxation is very quick,
the velocity should quickly approach the terminal velocity
"""

builder = Builder(
n_sd=len(default_attributes["multiplicity"]), backend=backend_class()
n_sd=len(default_attributes["multiplicity"]),
backend=backend_class(),
)

builder.set_environment(Box(dt=1, dv=1))
Expand Down
Loading