diff --git a/ci/default.yml b/ci/default.yml index 197d2913ac..c99b71768a 100644 --- a/ci/default.yml +++ b/ci/default.yml @@ -18,3 +18,13 @@ test_tools: stage: test script: - tox -r -c tools/ --verbose + + +test_model_datatests: + extends: .test_template + stage: test + script: + - tox -r -e run_model_tests -c model/ --verbose -- $COMPONENT + parallel: + matrix: + - COMPONENT: [atmosphere/diffusion/tests/diffusion_tests, atmosphere/dycore/tests/dycore_tests, common/tests, driver/tests] diff --git a/model/atmosphere/dycore/tests/dycore_tests/test_solve_nonhydro.py b/model/atmosphere/dycore/tests/dycore_tests/test_solve_nonhydro.py index 23c504bc6b..9e53e13c95 100644 --- a/model/atmosphere/dycore/tests/dycore_tests/test_solve_nonhydro.py +++ b/model/atmosphere/dycore/tests/dycore_tests/test_solve_nonhydro.py @@ -776,6 +776,7 @@ def test_run_solve_nonhydro_single_step( ) +@pytest.mark.slow_tests @pytest.mark.datatest @pytest.mark.parametrize("experiment", [REGIONAL_EXPERIMENT]) @pytest.mark.parametrize( diff --git a/model/common/src/icon4py/model/common/math/smagorinsky.py b/model/common/src/icon4py/model/common/math/smagorinsky.py index ace495078d..8e18ddc381 100644 --- a/model/common/src/icon4py/model/common/math/smagorinsky.py +++ b/model/common/src/icon4py/model/common/math/smagorinsky.py @@ -11,7 +11,7 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -from gt4py.next import Field, field_operator, program +from gt4py.next import Field, GridType, field_operator, program from gt4py.next.ffront.fbuiltins import broadcast, maximum, minimum from icon4py.model.common.dimension import KDim, Koff @@ -47,7 +47,7 @@ def _en_smag_fac_for_zero_nshift( return enh_smag_fac -@program +@program(grid_type=GridType.UNSTRUCTURED) def en_smag_fac_for_zero_nshift( vect_a: Field[[KDim], float], hdiff_smag_fac: float, diff --git a/model/common/tests/math_tests/test_smagorinsky.py b/model/common/tests/math_tests/test_smagorinsky.py index a5b31f82a7..402606bb92 100644 --- a/model/common/tests/math_tests/test_smagorinsky.py +++ b/model/common/tests/math_tests/test_smagorinsky.py @@ -12,30 +12,53 @@ # SPDX-License-Identifier: GPL-3.0-or-later import numpy as np -from gt4py.next.program_processors.runners.roundtrip import backend as roundtrip +import pytest from icon4py.model.common.dimension import KDim -from icon4py.model.common.grid.simple import SimpleGrid from icon4py.model.common.math.smagorinsky import en_smag_fac_for_zero_nshift -from icon4py.model.common.test_utils.helpers import random_field, zero_field +from icon4py.model.common.test_utils.helpers import StencilTest, random_field, zero_field from icon4py.model.common.test_utils.reference_funcs import enhanced_smagorinski_factor_numpy -# TODO (magdalena) stencil does not run on embedded backend, broadcast(0.0, (KDim,)) return scalar? -# TODO (magdalena) run as to StencilTest -def test_init_enh_smag_fac(): - grid = SimpleGrid() - enh_smag_fac = zero_field(grid, KDim) - a_vec = random_field(grid, KDim, low=1.0, high=10.0, extend={KDim: 1}) - fac = (0.67, 0.5, 1.3, 0.8) - z = (0.1, 0.2, 0.3, 0.4) +class TestEnhancedSmagorinskiFactor(StencilTest): + PROGRAM = en_smag_fac_for_zero_nshift + OUTPUTS = ("enh_smag_fac",) - enhanced_smag_fac_np = enhanced_smagorinski_factor_numpy(fac, z, a_vec.asnumpy()) - en_smag_fac_for_zero_nshift.with_backend(roundtrip)( - a_vec, - *fac, - *z, - enh_smag_fac, - offset_provider={"Koff": KDim}, - ) - assert np.allclose(enhanced_smag_fac_np, enh_smag_fac.asnumpy()) + @staticmethod + def reference( + grid, + vect_a: np.ndarray, + hdiff_smag_fac: float, + hdiff_smag_fac2: float, + hdiff_smag_fac3: float, + hdiff_smag_fac4: float, + hdiff_smag_z: float, + hdiff_smag_z2: float, + hdiff_smag_z3: float, + hdiff_smag_z4: float, + **kwargs, + ): + fac = (hdiff_smag_fac, hdiff_smag_fac2, hdiff_smag_fac3, hdiff_smag_fac4) + z = (hdiff_smag_z, hdiff_smag_z2, hdiff_smag_z3, hdiff_smag_z4) + enh_smag_fac = enhanced_smagorinski_factor_numpy(fac, z, vect_a) + return dict(enh_smag_fac=enh_smag_fac) + + @pytest.fixture + def input_data(self, grid): + enh_smag_fac = zero_field(grid, KDim) + a_vec = random_field(grid, KDim, low=1.0, high=10.0, extend={KDim: 1}) + fac = (0.67, 0.5, 1.3, 0.8) + z = (0.1, 0.2, 0.3, 0.4) + + return dict( + enh_smag_fac=enh_smag_fac, + vect_a=a_vec, + hdiff_smag_fac=fac[0], + hdiff_smag_fac2=fac[1], + hdiff_smag_fac3=fac[2], + hdiff_smag_fac4=fac[3], + hdiff_smag_z=z[0], + hdiff_smag_z2=z[1], + hdiff_smag_z3=z[2], + hdiff_smag_z4=z[3], + ) diff --git a/model/tox.ini b/model/tox.ini index 7aed4fb051..2718b464e4 100644 --- a/model/tox.ini +++ b/model/tox.ini @@ -36,6 +36,10 @@ commands = pytest -s -m "not slow_tests" atmosphere/diffusion/tests/diffusion_stencil_tests --benchmark-only {posargs} pytest -s -m "not slow_tests" atmosphere/dycore/tests/dycore_stencil_tests --benchmark-only {posargs} +[testenv:run_model_tests] +commands = + pytest -v -s -m "not slow_tests" --datatest {posargs} + [testenv:dev] setenv = diff --git a/requirements-dev.txt b/requirements-dev.txt index 61f75ec630..232ea6fb4f 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,7 +3,7 @@ # icon4py model -e ./model/atmosphere/dycore -e ./model/atmosphere/advection --e ./model/common +-e ./model/common['netcdf'] -e ./model/atmosphere/diffusion -e ./model/driver