Move transformations (index2offset, transpose) from Fortran to Python #1119
Move transformations (index2offset, transpose) from Fortran to Python #1119
Conversation
Co-authored-by: Hannes Vogt <[email protected]>
…t_gradp_and_dim_swap3
|
cscs-ci run default |
|
cscs-ci run distributed |
|
cscs-ci run default |
|
cscs-ci run default |
|
cscs-ci run default |
…icon4py into tmp_vertoffset_gradp_and_dim_swap3
|
cscs-ci run default |
1 similar comment
|
cscs-ci run default |
|
cscs-ci run distributed |
| @@ -129,6 +129,5 @@ def compute_zdiff_gradp_dsl( # noqa: PLR0912 [too-many-branches] | |||
| break | |||
|
|
|||
| vertoffset_gradp = vertidx_gradp - vertoffset_gradp | |||
| vertoffset_gradp[:horizontal_start_1, :, :] = 0.0 | |||
There was a problem hiding this comment.
I don't see why this line was added...
There was a problem hiding this comment.
could this be related to the test that verifies this over the entire domain instead of dallclose(vertoffset_gradp[horizontal_start_1:, :, :] ...) similarly to the problems in test_solve_nonhydro.py with exner_at_cells_on_half_levels and temporal_extrapolation_of_perturbed_exner?
There was a problem hiding this comment.
As discussed, I couldn't find this line in Fortran. My best guess is that is made the test work with the previous serialized data, but not sure...
|
cscs-ci run default |
|
cscs-ci run default |
|
cscs-ci run distributed |
There was a problem hiding this comment.
Pull request overview
This PR updates ICON4Py’s Python/py2fgen wrapper and test infrastructure to consume v3 serialized data, moving a few previously-Fortran-side layout/index transformations into Python.
Changes:
- Move
vertoffset_gradpderivation to Python by passingvertidx_gradpthrough wrappers/savepoints and converting viaindex2offset. - Move
rbf_vec_coeff_{e,v}transpose/decomposition logic to Python (new 3Drbf_vec_coeff_vplumbing; swap/transpose done in wrappers/savepoints). - Introduce
field_utils(flip,index2offset), removekflip_wgtfacq, and update/extend unit + integration + MPI tests accordingly (serializedExperiment.versionbumped to 3).
Reviewed changes
Copilot reviewed 36 out of 37 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/tests/tools/py2fgen/wrappers/test_dycore_wrapper.py | Update dycore wrapper tests to use v3 fields (vertidx_gradp, new RBF coeff layout, raw wgtfacq read). |
| tools/tests/tools/py2fgen/wrappers/test_diffusion_wrapper.py | Update diffusion wrapper tests to use 3D rbf_vec_coeff_v instead of v1/v2. |
| tools/tests/tools/py2fgen/wrappers/references/dycore/dycore.py | Regenerate reference Python wrapper signature/packing to accept rbf_vec_coeff_v and vertidx_gradp. |
| tools/tests/tools/py2fgen/wrappers/references/dycore/dycore.h | Update C header for new dycore wrapper argument list (3D RBF + vertidx). |
| tools/tests/tools/py2fgen/wrappers/references/dycore/dycore.f90 | Update Fortran wrapper interface to match new argument list and shapes. |
| tools/tests/tools/py2fgen/wrappers/references/diffusion/diffusion.py | Regenerate reference Python wrapper signature/packing to accept rbf_vec_coeff_v. |
| tools/tests/tools/py2fgen/wrappers/references/diffusion/diffusion.h | Update C header for new diffusion wrapper argument list (3D RBF). |
| tools/tests/tools/py2fgen/wrappers/references/diffusion/diffusion.f90 | Update Fortran wrapper interface to match new argument list and shapes. |
| tools/src/icon4py/tools/py2fgen/wrappers/dycore_wrapper.py | Implement Python-side RBF decomposition/transposes, wgtfacq flipping, and vertidx→vertoffset conversion. |
| tools/src/icon4py/tools/py2fgen/wrappers/diffusion_wrapper.py | Accept 3D RBF input and decompose into rbf_coeff_{1,2} in Python. |
| tools/src/icon4py/tools/py2fgen/wrappers/common.py | Add Float64Array3D type alias for py2fgen wrapper signatures. |
| model/testing/src/icon4py/model/testing/test_utils.py | Add assert_dallclose helper (numpy.testing-based). |
| model/testing/src/icon4py/model/testing/serialbox.py | Add _get_field(..., transpose=...), flip wgtfacq_*, transpose rbf_vec_coeff_e, derive vertoffset_gradp from vertidx_gradp. |
| model/testing/src/icon4py/model/testing/definitions.py | Bump serialized experiment version from 2 → 3. |
| model/driver/tests/driver/integration_tests/test_icon4py.py | Switch to metrics_savepoint.wgtfacq_{c,e}() (no _dsl). |
| model/driver/src/icon4py/model/driver/initialization_utils.py | Switch to metrics_savepoint.wgtfacq_{c,e}() (no _dsl). |
| model/common/tests/common/utils_test.py | Add shared dummy_exchange for common tests (renamed import target). |
| model/common/tests/common/utils/unit_tests/test_field_utils.py | New unit tests for field_utils.flip and field_utils.index2offset. |
| model/common/tests/common/utils/unit_tests/init.py | Package init for new common utils unit tests. |
| model/common/tests/common/utils/init.py | Package init for common utils tests. |
| model/common/tests/common/metrics/unit_tests/test_metrics_factory.py | Adjust comparisons for uninitialized lateral boundary regions; use new assert_dallclose and wgtfacq_e(). |
| model/common/tests/common/metrics/unit_tests/test_metric_fields.py | Update imports to utils_test.dummy_exchange. |
| model/common/tests/common/metrics/unit_tests/test_compute_zdiff_gradp.py | Switch test to new compute_zdiff_gradp implementation and updated utils import. |
| model/common/tests/common/metrics/unit_tests/test_compute_weight_factors.py | Use flipped wgtfacq_{c,e}() and update utils import. |
| model/common/tests/common/metrics/unit_tests/test_compute_coeff_gradekin.py | Update utils import to utils_test. |
| model/common/tests/common/metrics/mpi_tests/test_parallel_metrics.py | Update distributed metrics comparisons with optional slicing for known uninitialized regions; use assert_dallclose; switch wgtfacq_e(). |
| model/common/tests/common/interpolation/unit_tests/test_rbf_interpolation.py | Update utils import to utils_test. |
| model/common/tests/common/interpolation/unit_tests/test_interpolation_fields.py | Update utils import to utils_test. |
| model/common/tests/common/grid/unit_tests/test_vertical.py | Update utils import to utils_test. |
| model/common/tests/common/grid/unit_tests/test_topography.py | Update utils import to utils_test. |
| model/common/src/icon4py/model/common/utils/field_utils.py | New helpers: flip and index2offset (array-api compatible). |
| model/common/src/icon4py/model/common/utils/data_allocation.py | Remove kflip_wgtfacq (replaced by field_utils.flip). |
| model/common/src/icon4py/model/common/metrics/metrics_factory.py | Switch provider from compute_zdiff_gradp_dsl to compute_zdiff_gradp. |
| model/common/src/icon4py/model/common/metrics/compute_zdiff_gradp.py | Rename to compute_zdiff_gradp and add explicit exchanges for outputs (partial). |
| model/atmosphere/dycore/tests/dycore/utils.py | Switch to flipped wgtfacq_{c,e}() accessors. |
| model/atmosphere/dycore/tests/dycore/integration_tests/test_velocity_advection.py | Switch to wgtfacq_e() accessor. |
| model/atmosphere/dycore/tests/dycore/integration_tests/test_solve_nonhydro.py | Switch to flipped wgtfacq_{c,e}(); adjust array comparisons to avoid uninitialized boundary regions. |
Comments suppressed due to low confidence (2)
model/common/src/icon4py/model/common/metrics/compute_zdiff_gradp.py:135
compute_zdiff_gradpmanually exchangeszdiff_gradp, but it returnsvertoffset_gradpas a second output without exchanging it. Sincevertoffset_gradpis later used as theikoffsetfield in dycore stencils, its halo/boundary values can be inconsistent across ranks. Add an exchange forvertoffset_gradp(or ensure NumpyDataProvider exchanges both outputs).
model/common/src/icon4py/model/common/metrics/compute_zdiff_gradp.py:134- Typo in comment: “implict exchange” → “implicit exchange”.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
model/atmosphere/dycore/tests/dycore/integration_tests/test_solve_nonhydro.py
Show resolved
Hide resolved
model/atmosphere/dycore/tests/dycore/integration_tests/test_solve_nonhydro.py
Show resolved
Hide resolved
| @@ -129,6 +129,5 @@ def compute_zdiff_gradp_dsl( # noqa: PLR0912 [too-many-branches] | |||
| break | |||
|
|
|||
| vertoffset_gradp = vertidx_gradp - vertoffset_gradp | |||
| vertoffset_gradp[:horizontal_start_1, :, :] = 0.0 | |||
There was a problem hiding this comment.
could this be related to the test that verifies this over the entire domain instead of dallclose(vertoffset_gradp[horizontal_start_1:, :, :] ...) similarly to the problems in test_solve_nonhydro.py with exner_at_cells_on_half_levels and temporal_extrapolation_of_perturbed_exner?
model/common/src/icon4py/model/common/metrics/compute_zdiff_gradp_dsl.py
Outdated
Show resolved
Hide resolved
| def assert_dallclose( | ||
| actual: npt.ArrayLike, | ||
| desired: npt.ArrayLike, | ||
| rtol: float = 1.0e-12, | ||
| atol: float = 0.0, | ||
| equal_nan: bool = False, | ||
| ) -> None: | ||
| np_testing.assert_allclose(actual, desired, rtol=rtol, atol=atol, equal_nan=equal_nan) # type: ignore[arg-type] | ||
|
|
There was a problem hiding this comment.
no need for the helper, use np.testing.assert_allclose directly as in other tests?
There was a problem hiding this comment.
Changed the other tests, the reason for helper is the defaults for double precision.
|
ah, remember to close the other two PRs that were merged into this one |
|
cscs-ci run default |
|
cscs-ci run distributed |
…icon4py into tmp_vertoffset_gradp_and_dim_swap3
|
Mandatory Tests Please make sure you run these tests via comment before you merge!
Optional Tests To run benchmarks you can use:
To run tests and benchmarks with the DaCe backend you can use:
To run test levels ignored by the default test suite (mostly simple datatest for static fields computations) you can use:
For more detailed information please look at CI in the EXCLAIM universe. |
|
cscs-ci run default |
|
cscs-ci run distributed |
jcanton
left a comment
There was a problem hiding this comment.
looks very nice now, and you are lucky it's not blocked by the distributed CI so go ahead and merge!
| vertoffset_gradp = vertidx_gradp - vertoffset_gradp | ||
| vertoffset_gradp[:horizontal_start_1, :, :] = 0.0 | ||
|
|
||
| # TODO(havogt): NumpyDataProvider needs to be extended to support implict exchange. |
There was a problem hiding this comment.
| # TODO(havogt): NumpyDataProvider needs to be extended to support implict exchange. | |
| # TODO(havogt): NumpyDataProvider needs to be extended to support implicit exchange. |
:(
Combines #1118 and #1115, because both require
v3serialized data:vertoffset_gradpfromvertidx_gradpto Python (index2offset)rbf_vec_coeff_vandrbf_vec_coeff_eto PythonAdditional:
compute_zdiff_gradp(test failure triggered by new serialized data, most likely unrelated to the other changes)kflip_wgtfacqto a more generalflipon fields