From 7df1bff5e80233c1cf868a9ebccdaacfc139d238 Mon Sep 17 00:00:00 2001 From: Magdalena Date: Wed, 3 Apr 2024 10:15:25 +0200 Subject: [PATCH] fix and rename helper function to recognize python backends. (#430) fix the is_otf: - recognize backend by backend.__name__ - invert the negation: it now tests positively for python backends in addition unskip those tests with embedded that now work, only skip for roundtrip because it is too slow and run the datatests for metric fields with gtfn_cpu . --- ci/default.yml | 3 ++- .../icon4py/model/common/test_utils/helpers.py | 18 ++++++++++-------- .../tests/metric_tests/test_metric_fields.py | 9 +++++---- .../metric_tests/test_reference_atmosphere.py | 14 +++++++++----- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/ci/default.yml b/ci/default.yml index 2eed087173..4a85316030 100644 --- a/ci/default.yml +++ b/ci/default.yml @@ -30,7 +30,8 @@ test_model_datatests: extends: .test_template stage: test script: - - tox -r -e run_model_tests -c model/ --verbose -- $COMPONENT + - tox -r -e run_model_tests -c model/ --verbose -- --backend=$BACKEND $COMPONENT parallel: matrix: - COMPONENT: [atmosphere/diffusion/tests/diffusion_tests, atmosphere/dycore/tests/dycore_tests, common/tests, driver/tests] + BACKEND: [gtfn_cpu] diff --git a/model/common/src/icon4py/model/common/test_utils/helpers.py b/model/common/src/icon4py/model/common/test_utils/helpers.py index b5232afee0..25cf8357da 100644 --- a/model/common/src/icon4py/model/common/test_utils/helpers.py +++ b/model/common/src/icon4py/model/common/test_utils/helpers.py @@ -14,7 +14,6 @@ from dataclasses import dataclass, field from typing import ClassVar, Optional -import gt4py.next.program_processors.modular_executor import numpy as np import numpy.typing as npt import pytest @@ -37,16 +36,19 @@ def backend(request): return request.param -def is_otf(backend) -> bool: +def is_python(backend) -> bool: # want to exclude python backends: # - cannot run on embedded: because of slicing # - roundtrip is very slow on large grid - if hasattr(backend, "executor"): - if isinstance( - backend.executor, gt4py.next.program_processors.modular_executor.ModularExecutor - ): - return True - return False + return is_embedded(backend) or is_roundtrip(backend) + + +def is_embedded(backend) -> bool: + return backend is None + + +def is_roundtrip(backend) -> bool: + return backend.__name__ == "roundtrip" if backend else False def _shape( diff --git a/model/common/tests/metric_tests/test_metric_fields.py b/model/common/tests/metric_tests/test_metric_fields.py index 5b5df485c4..f4ba7dad2d 100644 --- a/model/common/tests/metric_tests/test_metric_fields.py +++ b/model/common/tests/metric_tests/test_metric_fields.py @@ -25,7 +25,8 @@ from icon4py.model.common.test_utils.helpers import ( StencilTest, dallclose, - is_otf, + is_python, + is_roundtrip, random_field, zero_field, ) @@ -65,7 +66,7 @@ def input_data(self, grid) -> dict: def test_compute_ddq_z_half(icon_grid, metrics_savepoint, backend): - if not is_otf(backend): + if is_python(backend): pytest.skip("skipping: unsupported backend") ddq_z_half_ref = metrics_savepoint.ddqz_z_half() z_ifc = metrics_savepoint.z_ifc() @@ -100,8 +101,8 @@ def test_compute_ddq_z_half(icon_grid, metrics_savepoint, backend): def test_compute_ddqz_z_full(icon_grid, metrics_savepoint, backend): - if not is_otf(backend): - pytest.skip("skipping: unsupported backend") + if is_roundtrip(backend): + pytest.skip("skipping: slow backend") z_ifc = metrics_savepoint.z_ifc() inv_ddqz_full_ref = metrics_savepoint.inv_ddqz_z_full() ddqz_z_full = zero_field(icon_grid, CellDim, KDim) diff --git a/model/common/tests/metric_tests/test_reference_atmosphere.py b/model/common/tests/metric_tests/test_reference_atmosphere.py index 1cdc6f9291..5e39a0b59a 100644 --- a/model/common/tests/metric_tests/test_reference_atmosphere.py +++ b/model/common/tests/metric_tests/test_reference_atmosphere.py @@ -26,7 +26,7 @@ compute_reference_atmosphere_cell_fields, compute_reference_atmosphere_edge_fields, ) -from icon4py.model.common.test_utils.helpers import dallclose, is_otf, zero_field +from icon4py.model.common.test_utils.helpers import dallclose, is_roundtrip, zero_field from icon4py.model.common.type_alias import wpfloat @@ -38,6 +38,8 @@ def test_compute_reference_atmosphere_fields_on_full_level_masspoints( icon_grid, metrics_savepoint, backend ): + if is_roundtrip(backend): + pytest.skip("skipping: slow backend") exner_ref_mc_ref = metrics_savepoint.exner_ref_mc() rho_ref_mc_ref = metrics_savepoint.rho_ref_mc() theta_ref_mc_ref = metrics_savepoint.theta_ref_mc() @@ -89,6 +91,8 @@ def test_compute_reference_atmosphere_fields_on_full_level_masspoints( def test_compute_reference_atmsophere_on_half_level_mass_points( icon_grid, metrics_savepoint, backend ): + if is_roundtrip(backend): + pytest.skip("skipping: slow backend") theta_ref_ic_ref = metrics_savepoint.theta_ref_ic() z_ifc = metrics_savepoint.z_ifc() @@ -124,8 +128,8 @@ def test_compute_reference_atmsophere_on_half_level_mass_points( @pytest.mark.datatest def test_compute_d_exner_dz_ref_ic(icon_grid, metrics_savepoint, backend): - if not is_otf(backend): - pytest.skip("skipping: unsupported backend") + if is_roundtrip(backend): + pytest.skip("skipping: slow backend") theta_ref_ic = metrics_savepoint.theta_ref_ic() d_exner_dz_ref_ic_ref = metrics_savepoint.d_exner_dz_ref_ic() d_exner_dz_ref_ic = zero_field(icon_grid, CellDim, KDim, extend={KDim: 1}) @@ -144,8 +148,8 @@ def test_compute_d_exner_dz_ref_ic(icon_grid, metrics_savepoint, backend): def test_compute_reference_atmosphere_on_full_level_edge_fields( icon_grid, interpolation_savepoint, metrics_savepoint, backend ): - if not is_otf(backend): - pytest.skip("skipping: unsupported backend") + if is_roundtrip(backend): + pytest.skip("skipping: slow backend") rho_ref_me_ref = metrics_savepoint.rho_ref_me() theta_ref_me_ref = metrics_savepoint.theta_ref_me() rho_ref_me = metrics_savepoint.rho_ref_me()