From 8aa7ff90d328145e2ff506f77b67381ac41e58a8 Mon Sep 17 00:00:00 2001 From: Magdalena Luz Date: Mon, 5 Feb 2024 13:28:47 +0100 Subject: [PATCH 01/14] add datatest stage --- ci/default.yml | 7 +++++++ model/tox.ini | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/ci/default.yml b/ci/default.yml index 197d2913ac..1a62004b91 100644 --- a/ci/default.yml +++ b/ci/default.yml @@ -18,3 +18,10 @@ test_tools: stage: test script: - tox -r -c tools/ --verbose + + +test_datatests: + extends: .test_template + stage: test + script: + - tox -r -e run_datatests -c model/ --verbose diff --git a/model/tox.ini b/model/tox.ini index 7aed4fb051..30c271847a 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_datatests] +commands = + pytest -s -m "not slow_tests and datatest" --datatest . + [testenv:dev] setenv = From 3401e2e90ec4c2cf56c4b12eddf094888956ac3e Mon Sep 17 00:00:00 2001 From: Magdalena Luz Date: Mon, 5 Feb 2024 13:36:27 +0100 Subject: [PATCH 02/14] (FIX): quick fixes for test_smagorinsky.py serialbox_utils.py to use defalt on_gpu = False --- .../src/icon4py/model/common/test_utils/serialbox_utils.py | 2 +- model/common/tests/math_tests/test_smagorinsky.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/model/common/src/icon4py/model/common/test_utils/serialbox_utils.py b/model/common/src/icon4py/model/common/test_utils/serialbox_utils.py index af8a1c22b3..85d0233608 100644 --- a/model/common/src/icon4py/model/common/test_utils/serialbox_utils.py +++ b/model/common/src/icon4py/model/common/test_utils/serialbox_utils.py @@ -314,7 +314,7 @@ def _get_decomp_fields(self, dim: Dimension): mask = self.owner_mask(dim)[0 : self.num(dim)] return dim, global_index, mask - def construct_icon_grid(self, on_gpu: bool) -> IconGrid: + def construct_icon_grid(self, on_gpu: bool = False) -> IconGrid: cell_starts = self.cells_start_index() cell_ends = self.cells_end_index() vertex_starts = self.vertex_start_index() diff --git a/model/common/tests/math_tests/test_smagorinsky.py b/model/common/tests/math_tests/test_smagorinsky.py index 7413392932..5a0fd0f6af 100644 --- a/model/common/tests/math_tests/test_smagorinsky.py +++ b/model/common/tests/math_tests/test_smagorinsky.py @@ -12,6 +12,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later import numpy as np +from gt4py.next.program_processors.runners.roundtrip import backend as roundtrip from icon4py.model.common.dimension import KDim from icon4py.model.common.grid.simple import SimpleGrid @@ -20,6 +21,7 @@ from icon4py.model.common.test_utils.reference_funcs import enhanced_smagorinski_factor_numpy +# TODO (magdalena) FIX does not run on embedded, there is an issue with broadcast(0.0, (KDim,)) def test_init_enh_smag_fac(): grid = SimpleGrid() enh_smag_fac = zero_field(grid, KDim) @@ -28,7 +30,7 @@ def test_init_enh_smag_fac(): z = (0.1, 0.2, 0.3, 0.4) enhanced_smag_fac_np = enhanced_smagorinski_factor_numpy(fac, z, a_vec.asnumpy()) - en_smag_fac_for_zero_nshift( + en_smag_fac_for_zero_nshift.with_backend(roundtrip)( a_vec, *fac, *z, From ef824821f5695119de8f2eb3230cfa41429f71a2 Mon Sep 17 00:00:00 2001 From: Magdalena Luz Date: Mon, 5 Feb 2024 18:53:42 +0100 Subject: [PATCH 03/14] add -n auto option --- model/tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/tox.ini b/model/tox.ini index 30c271847a..33b0fa872a 100644 --- a/model/tox.ini +++ b/model/tox.ini @@ -38,7 +38,7 @@ commands = [testenv:run_datatests] commands = - pytest -s -m "not slow_tests and datatest" --datatest . + pytest -s -n auto -m "not slow_tests and datatest" --datatest . [testenv:dev] From c2044b779cd0e8a9971bcce0d49674876f2dcb1e Mon Sep 17 00:00:00 2001 From: Magdalena Luz Date: Mon, 5 Feb 2024 21:46:39 +0100 Subject: [PATCH 04/14] run tests for packages in parallel --- ci/default.yml | 5 ++++- model/tox.ini | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ci/default.yml b/ci/default.yml index 1a62004b91..57674e71f7 100644 --- a/ci/default.yml +++ b/ci/default.yml @@ -24,4 +24,7 @@ test_datatests: extends: .test_template stage: test script: - - tox -r -e run_datatests -c model/ --verbose + - tox -r -e run_datatests -c model/ --verbose -- $COMPONENT + parallel: + matrix: + - COMPONENT: [atmosphere/diffusion, atmosphere/dycore, common, driver] diff --git a/model/tox.ini b/model/tox.ini index 33b0fa872a..a8d189c45c 100644 --- a/model/tox.ini +++ b/model/tox.ini @@ -38,7 +38,7 @@ commands = [testenv:run_datatests] commands = - pytest -s -n auto -m "not slow_tests and datatest" --datatest . + pytest -v -s -m "not slow_tests and datatest" --datatest {posargs} [testenv:dev] From edc5e4ffabd21a14fa3f766c51fcfb263b11926b Mon Sep 17 00:00:00 2001 From: Magdalena Luz Date: Tue, 6 Feb 2024 12:46:37 +0100 Subject: [PATCH 05/14] add non datatests from greenline --- ci/default.yml | 2 +- model/tox.ini | 2 +- requirements-dev-opt.txt | 1 + requirements-dev.txt | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ci/default.yml b/ci/default.yml index 57674e71f7..2a723157cf 100644 --- a/ci/default.yml +++ b/ci/default.yml @@ -27,4 +27,4 @@ test_datatests: - tox -r -e run_datatests -c model/ --verbose -- $COMPONENT parallel: matrix: - - COMPONENT: [atmosphere/diffusion, atmosphere/dycore, common, driver] + - COMPONENT: [atmosphere/diffusion/tests/diffusion_tests, atmosphere/dycore/tests/dycore_tests, common/tests, driver/tests] diff --git a/model/tox.ini b/model/tox.ini index a8d189c45c..eef862259d 100644 --- a/model/tox.ini +++ b/model/tox.ini @@ -38,7 +38,7 @@ commands = [testenv:run_datatests] commands = - pytest -v -s -m "not slow_tests and datatest" --datatest {posargs} + pytest -v -s -m "not slow_tests" --datatest {posargs} [testenv:dev] diff --git a/requirements-dev-opt.txt b/requirements-dev-opt.txt index 3ddf8fe5a0..540a5ac7da 100644 --- a/requirements-dev-opt.txt +++ b/requirements-dev-opt.txt @@ -11,3 +11,4 @@ git+https://github.com/ghex-org/GHEX.git#subdirectory=bindings/python -e ./tools +dimension(:,:) 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 From d3e8f8f90b6f0b6073f972a255d3054f810e171d Mon Sep 17 00:00:00 2001 From: Magdalena Luz Date: Tue, 6 Feb 2024 17:36:34 +0100 Subject: [PATCH 06/14] (refactor) port test_smagorinsky.py to StencilTest --- .../icon4py/model/common/math/smagorinsky.py | 4 +- .../tests/math_tests/test_smagorinsky.py | 63 +++++++++++++------ 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/model/common/src/icon4py/model/common/math/smagorinsky.py b/model/common/src/icon4py/model/common/math/smagorinsky.py index ace495078d..e79a768978 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, field_operator, program, GridType 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..567dcf9d2e 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 random_field, zero_field, StencilTest 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], + ) From 7d713544f0dcf8b3b62447b80667b85c99fe81e4 Mon Sep 17 00:00:00 2001 From: Magdalena Luz Date: Wed, 7 Feb 2024 17:59:11 +0100 Subject: [PATCH 07/14] (WIP) use slow_test marker in test_solve_nonhydro.py --- .../atmosphere/dycore/tests/dycore_tests/test_solve_nonhydro.py | 1 + 1 file changed, 1 insertion(+) 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( From abb88e660704a0dff774bc6d832254d322723a53 Mon Sep 17 00:00:00 2001 From: Magdalena Luz Date: Fri, 9 Feb 2024 14:42:16 +0100 Subject: [PATCH 08/14] rename tox section --- ci/default.yml | 2 +- model/common/src/icon4py/model/common/math/smagorinsky.py | 2 +- model/common/tests/math_tests/test_smagorinsky.py | 2 +- model/tox.ini | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ci/default.yml b/ci/default.yml index 2a723157cf..7e49fbc48d 100644 --- a/ci/default.yml +++ b/ci/default.yml @@ -24,7 +24,7 @@ test_datatests: extends: .test_template stage: test script: - - tox -r -e run_datatests -c model/ --verbose -- $COMPONENT + - 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/common/src/icon4py/model/common/math/smagorinsky.py b/model/common/src/icon4py/model/common/math/smagorinsky.py index e79a768978..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, GridType +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 diff --git a/model/common/tests/math_tests/test_smagorinsky.py b/model/common/tests/math_tests/test_smagorinsky.py index 567dcf9d2e..402606bb92 100644 --- a/model/common/tests/math_tests/test_smagorinsky.py +++ b/model/common/tests/math_tests/test_smagorinsky.py @@ -16,7 +16,7 @@ from icon4py.model.common.dimension import KDim 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, StencilTest +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 diff --git a/model/tox.ini b/model/tox.ini index eef862259d..2718b464e4 100644 --- a/model/tox.ini +++ b/model/tox.ini @@ -36,7 +36,7 @@ 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_datatests] +[testenv:run_model_tests] commands = pytest -v -s -m "not slow_tests" --datatest {posargs} From b35283214024bf85b16f27d87d8fe90a1ea6533f Mon Sep 17 00:00:00 2001 From: Magdalena Luz Date: Fri, 9 Feb 2024 14:45:05 +0100 Subject: [PATCH 09/14] rename ci job --- ci/default.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/default.yml b/ci/default.yml index 7e49fbc48d..c99b71768a 100644 --- a/ci/default.yml +++ b/ci/default.yml @@ -20,7 +20,7 @@ test_tools: - tox -r -c tools/ --verbose -test_datatests: +test_model_datatests: extends: .test_template stage: test script: From 98b3cd2eb1c2b4e0e3823f423eb77121d0eba2a1 Mon Sep 17 00:00:00 2001 From: Magdalena Luz Date: Fri, 9 Feb 2024 14:47:17 +0100 Subject: [PATCH 10/14] (fix) requirements-dev-opt.txt --- requirements-dev-opt.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/requirements-dev-opt.txt b/requirements-dev-opt.txt index 540a5ac7da..d75a8eccf3 100644 --- a/requirements-dev-opt.txt +++ b/requirements-dev-opt.txt @@ -9,6 +9,3 @@ git+https://github.com/ghex-org/GHEX.git#subdirectory=bindings/python # icon4pytools -e ./tools - - -dimension(:,:) From 33fc951bfad247c9ae730cbd5292bc2f38dae4e6 Mon Sep 17 00:00:00 2001 From: Magdalena Luz Date: Fri, 9 Feb 2024 14:48:16 +0100 Subject: [PATCH 11/14] (fix) requirements-dev-opt.txt --- requirements-dev-opt.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requirements-dev-opt.txt b/requirements-dev-opt.txt index d75a8eccf3..3ddf8fe5a0 100644 --- a/requirements-dev-opt.txt +++ b/requirements-dev-opt.txt @@ -9,3 +9,5 @@ git+https://github.com/ghex-org/GHEX.git#subdirectory=bindings/python # icon4pytools -e ./tools + + From 7a2fffeb6a72d4623ec84e1a46b819267ceee49a Mon Sep 17 00:00:00 2001 From: Magdalena Luz Date: Fri, 9 Feb 2024 16:01:48 +0100 Subject: [PATCH 12/14] revert change in serialbox_utils.py --- .../src/icon4py/model/common/test_utils/serialbox_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/common/src/icon4py/model/common/test_utils/serialbox_utils.py b/model/common/src/icon4py/model/common/test_utils/serialbox_utils.py index 06565ea249..fa7c6062d3 100644 --- a/model/common/src/icon4py/model/common/test_utils/serialbox_utils.py +++ b/model/common/src/icon4py/model/common/test_utils/serialbox_utils.py @@ -314,7 +314,7 @@ def _get_decomp_fields(self, dim: Dimension): mask = self.owner_mask(dim)[0 : self.num(dim)] return dim, global_index, mask - def construct_icon_grid(self, on_gpu: bool = False) -> IconGrid: + def construct_icon_grid(self, on_gpu: bool) -> IconGrid: cell_starts = self.cells_start_index() cell_ends = self.cells_end_index() vertex_starts = self.vertex_start_index() From a84044133d679c20867c873758a7b25196081627 Mon Sep 17 00:00:00 2001 From: Magdalena Luz Date: Tue, 20 Feb 2024 09:30:35 +0100 Subject: [PATCH 13/14] fix for mixed precision failure --- tools/tests/icon4pygen/test_codegen.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/tests/icon4pygen/test_codegen.py b/tools/tests/icon4pygen/test_codegen.py index 35d09c6a41..bece44624d 100644 --- a/tools/tests/icon4pygen/test_codegen.py +++ b/tools/tests/icon4pygen/test_codegen.py @@ -153,6 +153,12 @@ def test_invalid_module_path(cli) -> None: assert isinstance(result.exception, ModuleNotFoundError) +def reset_double_presicion() -> None: + os.environ["FLOAT_PRECISION"] = "double" + reload(type_alias) + assert (type_alias.vpfloat == float64) and (type_alias.wpfloat == float64) + + def test_mixed_precision_option(cli) -> None: module_path = get_stencil_module_path("some_module", "foo") cli.invoke( @@ -161,3 +167,4 @@ def test_mixed_precision_option(cli) -> None: reload(type_alias) assert os.environ.get("FLOAT_PRECISION") == "mixed" assert (type_alias.vpfloat == float32) and (type_alias.wpfloat == float64) + reset_double_presicion() From 1892b68b79790acef48cf2504b9c6f618a7969fd Mon Sep 17 00:00:00 2001 From: Magdalena Luz Date: Tue, 20 Feb 2024 14:42:55 +0100 Subject: [PATCH 14/14] remove patch for flaky tests --- tools/tests/icon4pygen/test_codegen.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tools/tests/icon4pygen/test_codegen.py b/tools/tests/icon4pygen/test_codegen.py index 0e24fd3420..8f9fae6746 100644 --- a/tools/tests/icon4pygen/test_codegen.py +++ b/tools/tests/icon4pygen/test_codegen.py @@ -147,12 +147,6 @@ def test_invalid_module_path(cli) -> None: assert isinstance(result.exception, ModuleNotFoundError) -def reset_double_presicion() -> None: - os.environ["FLOAT_PRECISION"] = "double" - reload(type_alias) - assert (type_alias.vpfloat == float64) and (type_alias.wpfloat == float64) - - def test_mixed_precision_option(cli) -> None: module_path = get_stencil_module_path("some_module", "foo") cli.invoke( @@ -161,4 +155,3 @@ def test_mixed_precision_option(cli) -> None: reload(type_alias) assert os.environ.get("FLOAT_PRECISION") == "mixed" assert (type_alias.vpfloat == float32) and (type_alias.wpfloat == float64) - reset_double_presicion()