Skip to content

improving test coverage for float precision variants in backends #1145

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 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
16 changes: 14 additions & 2 deletions tests/unit_tests/backends/test_collisions_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ def test_pair_indices(i, idx, is_first_in_pair, gamma, expected):
((4, 5, 4.5, 3, 0.1), (0, 1, 2, 3, 4, 5), 5),
),
)
def test_adaptive_sdm_end(backend_class, dt_left, cell_start, expected):
def test_adaptive_sdm_end(
backend_class, dt_left, cell_start, expected, double_precision
):
if backend_class.__name__ == "Numba" and not double_precision:
pytest.skip() # TODO #1144

# Arrange
backend = backend_class()
dt_left = backend.Storage.from_ndarray(np.asarray(dt_left))
Expand Down Expand Up @@ -161,7 +166,11 @@ def test_scale_prob_for_adaptive_sdm_gamma(
is_first_in_pair,
expected_dt_left,
expected_n_substep,
double_precision,
):
if backend_class.__name__ == "Numba" and not double_precision:
pytest.skip() # TODO #1144

# Arrange
backend = backend_class()
_gamma = backend.Storage.from_ndarray(np.asarray(gamma))
Expand Down Expand Up @@ -208,7 +217,10 @@ def test_scale_prob_for_adaptive_sdm_gamma(
"backend_class, scheme",
((CPU, "counting_sort"), (CPU, "counting_sort_parallel"), (GPU, "default")),
)
def test_cell_caretaker(backend_class, scheme):
def test_cell_caretaker(backend_class, scheme, double_precision):
if backend_class.__name__ == "Numba" and not double_precision:
pytest.skip() # TODO #1144

# Arrange
backend = backend_class()
idx = [0, 3, 2, 4]
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/backends/test_freezing_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_freeze_singular(backend_class):
# 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()
pytest.skip() # TODO #1144

# Arrange
seed = 44
Expand Down
6 changes: 5 additions & 1 deletion tests/unit_tests/backends/test_moments_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
(0, 1, 1.5, 0),
],
)
def test_moments_range(backend_class, min_x, max_x, value, expected):
# pylint: disable=too-many-arguments
def test_moments_range(backend_class, min_x, max_x, value, expected, double_precision):
if backend_class.__name__ == "Numba" and not double_precision:
pytest.skip() # TODO #1144

# Arrange
backend = backend_class(Formulae())

Expand Down
6 changes: 5 additions & 1 deletion tests/unit_tests/backends/test_physics_methods.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
import numpy as np
import pytest

from PySDM.physics import si


class TestPhysicsMethods: # pylint: disable=too-few-public-methods
@staticmethod
def test_temperature_pressure_RH(backend_class):
def test_temperature_pressure_RH(backend_class, double_precision):
if backend_class.__name__ == "Numba" and not double_precision:
pytest.skip() # TODO #1144

# Arrange
backend = backend_class()
sut = backend.temperature_pressure_RH
Expand Down
5 changes: 5 additions & 0 deletions tests/unit_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
@pytest.fixture(params=(CPU, GPU))
def backend_class(request):
return request.param


@pytest.fixture(params=(True, False))
def double_precision(request):
return request.param
9 changes: 7 additions & 2 deletions tests/unit_tests/dynamics/test_relaxed_velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@ def constant_timescale_fixture(request):
return request.param


def test_small_timescale(default_attributes, constant_timescale, backend_class):
def test_small_timescale(
default_attributes, constant_timescale, backend_class, double_precision
):
"""
When the fall velocity is initialized to 0 and relaxation is very quick,
the velocity should quickly approach the terminal velocity
"""
if backend_class.__name__ == "Numba" and not double_precision:
pytest.skip() # TODO #1144

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

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