Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into update_to_gtir_dace
Browse files Browse the repository at this point in the history
  • Loading branch information
edopao committed Jan 10, 2025
2 parents 78d81ce + d5de356 commit 84f1ec7
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 44 deletions.
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
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),
w_concorr_c,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
compute_horizontal_advection_term_for_vertical_velocity,
)
from icon4py.model.common import dimension as dims
from icon4py.model.common.grid import horizontal as h_grid
from icon4py.model.common.type_alias import vpfloat, wpfloat
from icon4py.model.common.utils.data_allocation import random_field, zero_field
from icon4py.model.testing.helpers import StencilTest
Expand Down Expand Up @@ -59,27 +60,27 @@ def reference(
inv_primal_edge_length: np.array,
tangent_orientation: np.array,
z_w_v: np.array,
z_v_grad_w: np.array,
horizontal_start: int,
horizontal_end: int,
**kwargs,
) -> dict:
z_v_grad_w = compute_horizontal_advection_term_for_vertical_velocity_numpy(
grid,
vn_ie,
inv_dual_edge_length,
w,
z_vt_ie,
inv_primal_edge_length,
tangent_orientation,
z_w_v,
)
z_v_grad_w[horizontal_start:horizontal_end, :] = (
compute_horizontal_advection_term_for_vertical_velocity_numpy(
grid,
vn_ie,
inv_dual_edge_length,
w,
z_vt_ie,
inv_primal_edge_length,
tangent_orientation,
z_w_v,
)
)[horizontal_start:horizontal_end, :]
return dict(z_v_grad_w=z_v_grad_w)

@pytest.fixture
def input_data(self, grid):
if np.any(grid.connectivities[dims.E2CDim] == -1) or np.any(
grid.connectivities[dims.E2VDim] == -1
):
pytest.xfail("Stencil does not support missing neighbors.")

vn_ie = random_field(grid, dims.EdgeDim, dims.KDim, dtype=vpfloat)
inv_dual_edge_length = random_field(grid, dims.EdgeDim, dtype=wpfloat)
w = random_field(grid, dims.CellDim, dims.KDim, dtype=wpfloat)
Expand All @@ -89,6 +90,18 @@ def input_data(self, grid):
z_w_v = random_field(grid, dims.VertexDim, dims.KDim, dtype=vpfloat)
z_v_grad_w = zero_field(grid, dims.EdgeDim, dims.KDim, dtype=vpfloat)

edge_domain = h_grid.domain(dims.EdgeDim)
horizontal_start = (
grid.start_index(edge_domain(h_grid.Zone.LATERAL_BOUNDARY_LEVEL_7))
if hasattr(grid, "start_index")
else 0
)
horizontal_end = (
grid.end_index(edge_domain(h_grid.Zone.HALO))
if hasattr(grid, "end_index")
else gtx.int32(grid.num_edges)
)

return dict(
vn_ie=vn_ie,
inv_dual_edge_length=inv_dual_edge_length,
Expand All @@ -98,8 +111,8 @@ def input_data(self, grid):
tangent_orientation=tangent_orientation,
z_w_v=z_w_v,
z_v_grad_w=z_v_grad_w,
horizontal_start=0,
horizontal_end=gtx.int32(grid.num_edges),
horizontal_start=horizontal_start,
horizontal_end=horizontal_end,
vertical_start=0,
vertical_end=gtx.int32(grid.num_levels),
)
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.copy()
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
) -> np.array:
z_w_con_c = z_w_con_c - w_concorr_c
return z_w_con_c
Expand All @@ -31,7 +31,7 @@ class TestCorrectContravariantVerticalVelocity(StencilTest):

@staticmethod
def reference(grid, w_concorr_c: np.array, z_w_con_c: np.array, **kwargs) -> dict:
z_w_con_c = correct_contravariant_vertical_velocity_numpy(w_concorr_c, z_w_con_c)
z_w_con_c = correct_contravariant_vertical_velocity_numpy(z_w_con_c, w_concorr_c)
return dict(z_w_con_c=z_w_con_c)

@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
fused_velocity_advection_stencil_1_to_7,
)
from icon4py.model.common import dimension as dims
from icon4py.model.common.grid import base as base_grid, horizontal as h_grid
from icon4py.model.common.utils import data_allocation as data_alloc
from icon4py.model.testing.helpers import StencilTest

Expand Down Expand Up @@ -106,7 +107,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

@classmethod
def reference(
Expand Down Expand Up @@ -145,6 +146,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 +172,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 +185,7 @@ def reference(
z_vt_ie,
inv_primal_edge_length,
tangent_orientation,
z_v_w,
z_w_v,
),
z_v_grad_w,
)
Expand All @@ -197,11 +199,7 @@ def reference(
)

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

def input_data(self, grid: base_grid.BaseGrid):
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 Expand Up @@ -232,8 +230,18 @@ def input_data(self, grid):
istep = 1
lvn_only = False

lateral_boundary_7 = 0
halo_1 = grid.num_edges
edge_domain = h_grid.domain(dims.EdgeDim)
# For the ICON grid we use the proper domain bounds (otherwise we will run into non-protected skip values)
lateral_boundary_7 = (
grid.start_index(edge_domain(h_grid.Zone.LATERAL_BOUNDARY_LEVEL_7))
if hasattr(grid, "start_index")
else 0
)
halo_1 = (
grid.end_index(edge_domain(h_grid.Zone.HALO))
if hasattr(grid, "end_index")
else grid.num_edges
)

horizontal_start = 0
horizontal_end = grid.num_edges
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,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(
grid, wgtfac_c=wgtfac_c, interpolant=z_w_concorr_mc
),
w_concorr_c,
)

Expand All @@ -93,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 Down
5 changes: 3 additions & 2 deletions model/testing/src/icon4py/model/testing/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,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

0 comments on commit 84f1ec7

Please sign in to comment.