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

Fix velocity advection stencil test and references #632

Merged
merged 11 commits into from
Jan 10, 2025
3 changes: 1 addition & 2 deletions ci/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ include:
.benchmark_model_stencils:
stage: benchmark
script:
# force execution of tests where validation is expected to fail, because the reason for failure is wrong numpy reference
- nox -s benchmark_model-3.10 -- --backend=$BACKEND --grid=$GRID --runxfail
- nox -s benchmark_model-3.10 -- --backend=$BACKEND --grid=$GRID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will apply the same change in the dace CI pipeline:

# force execution of tests where validation is expected to fail, because the reason for failure is wrong numpy reference

parallel:
matrix:
- BACKEND: [gtfn_cpu, gtfn_gpu]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _fused_velocity_advection_stencil_8_to_13_predictor(

w_concorr_c = where(
nflatlev + 1 <= k < nlev,
_interpolate_to_half_levels_vp(interpolant=z_w_concorr_mc, wgtfac_c=wgtfac_c),
_interpolate_to_half_levels_vp(wgtfac_c=wgtfac_c, interpolant=z_w_concorr_mc),
nfarabullini marked this conversation as resolved.
Show resolved Hide resolved
w_concorr_c,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def copy_cell_kdim_field_to_vp_numpy(field: np.array) -> np.array:
field_copy = field
field_copy = field[...]
havogt marked this conversation as resolved.
Show resolved Hide resolved
return field_copy


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def correct_contravariant_vertical_velocity_numpy(
w_concorr_c: np.array, z_w_con_c: np.array
z_w_con_c: np.array, w_concorr_c: np.array
nfarabullini marked this conversation as resolved.
Show resolved Hide resolved
) -> np.array:
z_w_con_c = z_w_con_c - w_concorr_c
return z_w_con_c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _fused_velocity_advection_stencil_1_to_6_numpy(
z_w_concorr_me,
)

return vt, vn_ie, z_kin_hor_e, z_w_concorr_me
return vt, vn_ie, z_vt_ie, z_kin_hor_e, z_w_concorr_me
havogt marked this conversation as resolved.
Show resolved Hide resolved

@classmethod
def reference(
Expand Down Expand Up @@ -145,6 +145,7 @@ def reference(
(
vt,
vn_ie,
z_vt_ie,
z_kin_hor_e,
z_w_concorr_me,
) = cls._fused_velocity_advection_stencil_1_to_6_numpy(
Expand All @@ -170,7 +171,7 @@ def reference(

condition_mask = (lateral_boundary_7 <= edge) & (edge < halo_1) & (k_nlev < nlev)

z_v_w = mo_icon_interpolation_scalar_cells2verts_scalar_ri_dsl_numpy(grid, w, c_intp)
z_w_v = mo_icon_interpolation_scalar_cells2verts_scalar_ri_dsl_numpy(grid, w, c_intp)

if not lvn_only:
z_v_grad_w = np.where(
Expand All @@ -183,7 +184,7 @@ def reference(
z_vt_ie,
inv_primal_edge_length,
tangent_orientation,
z_v_w,
z_w_v,
),
z_v_grad_w,
)
Expand All @@ -198,10 +199,6 @@ def reference(

@pytest.fixture
def input_data(self, grid):
pytest.xfail(
"Verification of z_v_grad_w currently not working, because numpy version incorrect."
)

c_intp = data_alloc.random_field(grid, dims.VertexDim, dims.V2CDim)
vn = data_alloc.random_field(grid, dims.EdgeDim, dims.KDim)
rbf_vec_coeff_e = data_alloc.random_field(grid, dims.EdgeDim, dims.E2C2EDim)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
)
from icon4py.model.common import dimension as dims
from icon4py.model.testing.helpers import StencilTest
from icon4py.model.common.utils.data_allocation import (
random_field,
zero_field
)
from icon4py.model.common.utils.data_allocation import random_field, zero_field
from icon4py.model.common.utils import data_allocation as data_alloc

from .test_copy_cell_kdim_field_to_vp import copy_cell_kdim_field_to_vp_numpy
Expand Down Expand Up @@ -64,15 +61,13 @@ def reference(
)

if istep == 1:
z_w_concorr_mc = np.where(
(nflatlev <= k_nlev) & (k_nlev < nlev),
interpolate_to_cell_center_numpy(grid, z_w_concorr_me, e_bln_c_s),
z_w_concorr_mc,
)
z_w_concorr_mc = interpolate_to_cell_center_numpy(grid, z_w_concorr_me, e_bln_c_s)

w_concorr_c = np.where(
(nflatlev + 1 <= k_nlev) & (k_nlev < nlev),
interpolate_to_half_levels_vp_numpy(grid, z_w_concorr_mc, wgtfac_c),
interpolate_to_half_levels_vp_numpy(
havogt marked this conversation as resolved.
Show resolved Hide resolved
grid, wgtfac_c=wgtfac_c, interpolant=z_w_concorr_mc
),
w_concorr_c,
)

Expand All @@ -96,9 +91,6 @@ def reference(

@pytest.fixture
def input_data(self, grid):
pytest.xfail(
"Verification of w_concorr_c currently not working, because numpy version is incorrect."
)
z_kin_hor_e = random_field(grid, dims.EdgeDim, dims.KDim)
e_bln_c_s = random_field(grid, dims.CellDim, dims.C2EDim)
z_ekinh = zero_field(grid, dims.CellDim, dims.KDim)
Expand All @@ -123,7 +115,7 @@ def input_data(self, grid):

return dict(
z_kin_hor_e=z_kin_hor_e,
e_bln_c_s=as_1D_sparse_field(e_bln_c_s, dims.CEDim),
e_bln_c_s=data_alloc.as_1D_sparse_field(e_bln_c_s, dims.CEDim),
z_w_concorr_me=z_w_concorr_me,
wgtfac_c=wgtfac_c,
w=w,
Expand Down
6 changes: 3 additions & 3 deletions model/testing/src/icon4py/model/testing/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from icon4py.model.common.utils import data_allocation as data_alloc



try:
import pytest_benchmark
except ModuleNotFoundError:
Expand Down Expand Up @@ -96,11 +95,12 @@ def _test_validation(self, grid, backend, input_data):
else (out, (slice(None),), (slice(None),))
)

assert np.allclose(
np.testing.assert_allclose(
input_data[name].asnumpy()[gtslice],
reference_outputs[name][refslice],
equal_nan=True,
), f"Validation failed for '{name}'"
err_msg=f"Validation failed for '{name}'",
)


if pytest_benchmark:
Expand Down
Loading