Skip to content

Commit

Permalink
edits following review
Browse files Browse the repository at this point in the history
  • Loading branch information
nfarabullini committed Jan 30, 2025
1 parent 114c81e commit 1bd64f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
23 changes: 12 additions & 11 deletions model/testing/src/icon4py/model/testing/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import numpy as np
import pytest
from gt4py._core.definitions import is_scalar_type
from gt4py.next import constructors
from gt4py.next import backend as gtx_backend, constructors
from gt4py.next.ffront.decorator import Program
from typing_extensions import Buffer

Expand All @@ -38,26 +38,26 @@ def grid(request):
return request.param


def is_python(backend) -> bool:
def is_python(backend: gtx_backend.Backend | None) -> bool:
# want to exclude python backends:
# - cannot run on embedded: because of slicing
# - roundtrip is very slow on large grid
return is_embedded(backend) or is_roundtrip(backend)


def is_dace(backend) -> bool:
def is_dace(backend: gtx_backend.Backend | None) -> bool:
return backend.name.startswith("run_dace_") if backend else False


def is_embedded(backend) -> bool:
def is_embedded(backend: None) -> bool:
return backend is None


def is_roundtrip(backend) -> bool:
def is_roundtrip(backend: gtx_backend.Backend | None) -> bool:
return backend.name == "roundtrip" if backend else False


def extract_backend_name(backend) -> str:
def extract_backend_name(backend: gtx_backend.Backend | None) -> str:
return "embedded" if backend is None else backend.name


Expand All @@ -78,10 +78,11 @@ def allocate_data(backend, input_data):
return input_data


def match_marker(
markers: tuple[pytest.Mark | pytest.MarkDecorator, ...], backend: str, is_datatest: bool = False
def apply_markers(
markers: tuple[pytest.Mark | pytest.MarkDecorator, ...],
backend: str | None,
is_datatest: bool = False,
):
backend = None if backend == "embedded" else backend
for marker in markers:
match marker.name:
case "embedded_remap_error" if is_embedded(backend):
Expand All @@ -108,7 +109,7 @@ class Output:

def _test_validation(self, grid, backend, input_data):
if self.MARKERS is not None:
match_marker(self.MARKERS, backend)
apply_markers(self.MARKERS, backend)

connectivities = {dim: data_alloc.as_numpy(table) for dim, table in grid.connectivities.items()}
reference_outputs = self.reference(
Expand Down Expand Up @@ -141,7 +142,7 @@ def _test_validation(self, grid, backend, input_data):

def _test_execution_benchmark(self, pytestconfig, grid, backend, input_data, benchmark):
if self.MARKERS is not None:
match_marker(self.MARKERS, backend)
apply_markers(self.MARKERS, backend)

if pytestconfig.getoption(
"--benchmark-disable"
Expand Down
4 changes: 2 additions & 2 deletions model/testing/src/icon4py/model/testing/pytest_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
GLOBAL_EXPERIMENT,
REGIONAL_EXPERIMENT,
)
from icon4py.model.testing.helpers import match_marker
from icon4py.model.testing.helpers import apply_markers


def _check_backend_validity(backend_name: str) -> None:
Expand Down Expand Up @@ -86,7 +86,7 @@ def pytest_addoption(parser):


def pytest_runtest_setup(item):
match_marker(
apply_markers(
item.own_markers,
model_backends.BACKENDS[item.config.getoption("--backend")],
is_datatest=item.config.getoption("--datatest"),
Expand Down

0 comments on commit 1bd64f3

Please sign in to comment.