Skip to content
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

Datatest on ci #380

Merged
merged 19 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions ci/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions model/common/src/icon4py/model/common/math/smagorinsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
63 changes: 43 additions & 20 deletions model/common/tests/math_tests/test_smagorinsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
)
4 changes: 4 additions & 0 deletions model/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading