Skip to content

Commit

Permalink
Fix pre-commit config to check all model files (#637)
Browse files Browse the repository at this point in the history
Fix pre-commit config to work on all model files, and not only on
`model/common` folder. This PR also includes all the format and linter
changes required to make CI pass.

Additionally, add the `esbonio` language server for RestructuredText to
the`docs` dependency group.

Bug originally reported by @havogt

---------

Co-authored-by: Nicoletta Farabullini <[email protected]>
  • Loading branch information
egparedes and nfarabullini authored Jan 9, 2025
1 parent 5a19c81 commit 77a7a68
Show file tree
Hide file tree
Showing 165 changed files with 408 additions and 302 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ minimum_pre_commit_version: 3.8.0
files: |
(?x)^(
tools/.*|
model/common/.*
model/.*
)$
repos:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ICON4Py is licensed under the terms of the BSD-3-Clause.

Since this project is still in a highly experimental state, it is not yet available as a regular Python distribution package through PyPI. The installation procedure involves cloning the [ICON4Py GitHub repository](https://github.com/C2SM/icon4py) and installing it in a Python virtual environment (_venv_).

ICON4Py uses the `uv` tool to manage the development workflow. `uv` is a versatile tool that consolidates functionality previously distributed across different applications into subcommands.
ICON4Py uses the [`uv`](https://docs.astral.sh/uv/) project manager for development workflow. `uv` is a versatile tool that consolidates functionality previously distributed across different applications into subcommands.

- The `uv pip` subcommand provides a _fast_ Python package manager, emulating [`pip`](https://pip.pypa.io/en/stable/).
- The `uv export | lock | sync` subcommands manage dependency versions in a manner similar to the [`pip-tools`](https://pip-tools.readthedocs.io/en/stable/) command suite.
Expand Down
27 changes: 18 additions & 9 deletions model/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ Until the development reaches a stable state, we recommend you to follow the gen
See the repository [README](../README.md) for general information.

#### Unit tests for stencils

The `gt4py` stencils in the `icon4py-model` packages are used for integration into Fortran code
via [icon4pygen](../tools/src/icon4py/icon4pygen). To make integration easier
unit tests for the stencils need to be placed into
a `stencil_tests` subfolder of the packages test path. For example

```
model/atmosphere/diffusion/tests/stencil_tests
model/atmosphere/dycore/tests/stencil_tests
Expand All @@ -35,10 +37,10 @@ model/common/tests/tests/stencil_tests

#### Data dependent tests

Some test depend on serialized data generated by a full model run.
Those test are marked with `pytest.mark.datatest` and are only run when the `--datatest`
option is specified. Note that due to `pytests` configuration discovery
you need to specify the base a package directory i.e. one that contains a `pyproject.toml` for the
Some tests depend on serialized data generated by a full model run.
Those tests are marked with `pytest.mark.datatest` and are only run when the `--datatest`
option is specified. Note that due to `pytest` configuration discovery
you need to specify the base package directory i.e. one that contains a `pyproject.toml` for the
commandline option to work.

```bash
Expand All @@ -48,6 +50,7 @@ pytest -v --datatest model/atmosphere/diffusion
```

#### Testing parallel code

Icon4Py uses GHEX as communication library. It is an optional dependency of the model. In order to install and
run the parallel version do the following:

Expand All @@ -56,25 +59,31 @@ run the parallel version do the following:
```bash
sudo apt-get install libopenmpi-dev
```

or

```bash
sudo apt-get install mpich
```
On MacOS run

On MacOS run

```bash
brew install mpich
```

2. Install optional python libraries:
In the main folder of the repository run
In the main folder of the repository, run

```bash
pip install -r requirements-dev-opt.txt
```

Note that the current Python build for GHEX seems not to run on MacOS.

3. Run parallel tests
In order to run the parallel tests you need to specify specify the `--with-mpi` option to `pytest`
and _pass the exact folder location of the tests_ to `pytest`.

In order to run the parallel tests you need to specify the `--with-mpi` option to `pytest`
and _pass the exact folder location of the tests_ to `pytest`.

```bash
mpirun -np 4 pytest -v -s --with-mpi --datatest model/atmosphere/diffusion/diffusion_tests/mpi_tests/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def reference(
@pytest.fixture
def input_data(self, grid) -> dict:
p_rhodz_new = data_alloc.random_field(grid, dims.CellDim, dims.KDim)
p_mflx_contra_v = data_alloc.random_field(grid, dims.CellDim, dims.KDim, extend={dims.KDim: 1})
p_mflx_contra_v = data_alloc.random_field(
grid, dims.CellDim, dims.KDim, extend={dims.KDim: 1}
)
deepatmo_divzl = data_alloc.random_field(grid, dims.KDim)
deepatmo_divzu = data_alloc.random_field(grid, dims.KDim)
rhodz_ast2 = data_alloc.zero_field(grid, dims.CellDim, dims.KDim)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from icon4py.model.common import dimension as dims
from icon4py.model.common.utils import data_allocation as data_alloc


class TestApplyInterpolatedTracerTimeTendency(helpers.StencilTest):
PROGRAM = apply_interpolated_tracer_time_tendency
OUTPUTS = ("p_tracer_new",)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from icon4py.model.atmosphere.advection.stencils.apply_vertical_density_increment import (
apply_vertical_density_increment,
)
from icon4py.model.common.utils import data_allocation as data_alloc
from icon4py.model.common import dimension as dims
from icon4py.model.common.utils import data_allocation as data_alloc


class TestApplyVerticalDensityIncrement(helpers.StencilTest):
Expand Down Expand Up @@ -48,7 +48,9 @@ def reference(
@pytest.fixture
def input_data(self, grid) -> dict:
rhodz_ast = data_alloc.random_field(grid, dims.CellDim, dims.KDim)
p_mflx_contra_v = data_alloc.random_field(grid, dims.CellDim, dims.KDim, extend={dims.KDim: 1})
p_mflx_contra_v = data_alloc.random_field(
grid, dims.CellDim, dims.KDim, extend={dims.KDim: 1}
)
deepatmo_divzl = data_alloc.random_field(grid, dims.KDim)
deepatmo_divzu = data_alloc.random_field(grid, dims.KDim)
rhodz_ast2 = data_alloc.zero_field(grid, dims.CellDim, dims.KDim)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from icon4py.model.common.utils import data_allocation as data_alloc



class TestAverageHorizontalFluxSubcycling2(helpers.StencilTest):
PROGRAM = average_horizontal_flux_subcycling_2
OUTPUTS = ("p_out_e",)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from icon4py.model.common import dimension as dims
from icon4py.model.common.utils import data_allocation as data_alloc


class TestAverageHorizontalFluxSubcycling3(helpers.StencilTest):
PROGRAM = average_horizontal_flux_subcycling_3
OUTPUTS = ("p_out_e",)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import numpy as np
import pytest

import icon4py.model.testing.helpers as helpers
import icon4py.model.common.utils.data_allocation as data_alloc
import icon4py.model.testing.helpers as helpers
from icon4py.model.atmosphere.advection.stencils.compute_antidiffusive_cell_fluxes_and_min_max import (
compute_antidiffusive_cell_fluxes_and_min_max,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import numpy as np
import pytest

import icon4py.model.testing.helpers as helpers
import icon4py.model.common.utils.data_allocation as data_alloc
import icon4py.model.testing.helpers as helpers
from icon4py.model.atmosphere.advection.stencils.compute_barycentric_backtrajectory import (
compute_barycentric_backtrajectory,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import numpy as np
import pytest

import icon4py.model.testing.helpers as helpers
import icon4py.model.common.utils.data_allocation as data_alloc
import icon4py.model.testing.helpers as helpers
from icon4py.model.atmosphere.advection.stencils.compute_barycentric_backtrajectory_alt import (
compute_barycentric_backtrajectory_alt,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import numpy as np
import pytest

import icon4py.model.testing.helpers as helpers
import icon4py.model.common.utils.data_allocation as data_alloc
import icon4py.model.testing.helpers as helpers
from icon4py.model.atmosphere.advection.stencils.compute_ffsl_backtrajectory import (
compute_ffsl_backtrajectory,
)
from icon4py.model.common import dimension as dims
from icon4py.model.common.utils import data_allocation as data_alloc


class TestComputeFfslBacktrajectory(helpers.StencilTest):
PROGRAM = compute_ffsl_backtrajectory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from icon4py.model.common import dimension as dims
from icon4py.model.common.utils import data_allocation as data_alloc


class TestComputeFfslBacktrajectoryCounterclockwiseIndicator(helpers.StencilTest):
PROGRAM = compute_ffsl_backtrajectory_counterclockwise_indicator
OUTPUTS = ("lvn_sys_pos",)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from icon4py.model.common import dimension as dims
from icon4py.model.common.utils import data_allocation as data_alloc


class TestComputeHorizontalTracerFluxFromCubicCoefficients(helpers.StencilTest):
PROGRAM = compute_horizontal_tracer_flux_from_cubic_coefficients
OUTPUTS = ("p_out_e_hybrid_2",)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from icon4py.model.common.utils import data_allocation as data_alloc



class TestComputeHorizontalTracerFluxFromLinearCoefficients(helpers.StencilTest):
PROGRAM = compute_horizontal_tracer_flux_from_linear_coefficients
OUTPUTS = ("p_out_e",)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from icon4py.model.common.grid import horizontal as h_grid
from icon4py.model.common.utils import data_allocation as data_alloc


class TestComputeHorizontalTracerFluxFromLinearCoefficientsAlt(helpers.StencilTest):
PROGRAM = compute_horizontal_tracer_flux_from_linear_coefficients_alt
OUTPUTS = ("p_out_e",)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import numpy as np
import pytest

import icon4py.model.testing.helpers as helpers
import icon4py.model.common.utils.data_allocation as data_alloc
import icon4py.model.testing.helpers as helpers
from icon4py.model.atmosphere.advection.stencils.compute_positive_definite_horizontal_multiplicative_flux_factor import (
compute_positive_definite_horizontal_multiplicative_flux_factor,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
from icon4py.model.atmosphere.advection.stencils.compute_ppm_all_face_values import (
compute_ppm_all_face_values,
)
from icon4py.model.common.utils import data_allocation as data_alloc

from icon4py.model.common import dimension as dims

from icon4py.model.common.utils import data_allocation as data_alloc


class TestComputePpmAllFaceValues(helpers.StencilTest):
Expand Down Expand Up @@ -55,7 +53,7 @@ def input_data(self, grid) -> dict:
p_cellhgt_mc_now = data_alloc.random_field(grid, dims.CellDim, dims.KDim)
p_face_in = data_alloc.random_field(grid, dims.CellDim, dims.KDim)
p_face = data_alloc.zero_field(grid, dims.CellDim, dims.KDim)
k = data_alloc.allocate_indices(dims.KDim, grid, is_halfdim=False, dtype=gtx.int32)
k = data_alloc.allocate_indices(dims.KDim, grid, is_halfdim=False, dtype=gtx.int32)
slev = gtx.int32(1)
slevp1 = gtx.int32(2)
elev = gtx.int32(k[-3].as_scalar())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from icon4py.model.common import dimension as dims
from icon4py.model.common.utils import data_allocation as data_alloc


outslice = (slice(None), slice(1, None))


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from icon4py.model.common import dimension as dims
from icon4py.model.common.utils import data_allocation as data_alloc


class TestComputePpmQuarticFaceValues(helpers.StencilTest):
PROGRAM = compute_ppm_quartic_face_values
OUTPUTS = (helpers.Output("p_face", gtslice=(slice(None), slice(2, None))),)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import gt4py.next as gtx
import numpy as np
import pytest
from gt4py.next import as_field

import icon4py.model.testing.helpers as helpers
from icon4py.model.atmosphere.advection.stencils.compute_ppm_slope import (
Expand All @@ -18,6 +17,7 @@
from icon4py.model.common import dimension as dims
from icon4py.model.common.utils import data_allocation as data_alloc


class TestComputePpmSlope(helpers.StencilTest):
PROGRAM = compute_ppm_slope
OUTPUTS = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from icon4py.model.common import dimension as dims
from icon4py.model.common.utils import data_allocation as data_alloc


class TestComputeTendency(helpers.StencilTest):
PROGRAM = compute_tendency
OUTPUTS = ("opt_ddt_tracer_adv",)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from icon4py.model.common import dimension as dims
from icon4py.model.common.utils import data_allocation as data_alloc


class TestIntegrateTracerDensityHorizontally(helpers.StencilTest):
PROGRAM = integrate_tracer_density_horizontally
OUTPUTS = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import numpy as np
import pytest

import icon4py.model.testing.helpers as helpers
import icon4py.model.common.utils.data_allocation as data_alloc
import icon4py.model.testing.helpers as helpers
from icon4py.model.atmosphere.advection.stencils.integrate_tracer_horizontally import (
integrate_tracer_horizontally,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import gt4py.next as gtx
import numpy as np
import pytest
from gt4py.next import as_field

import icon4py.model.testing.helpers as helpers
from icon4py.model.atmosphere.advection.stencils.integrate_tracer_vertically import (
Expand Down Expand Up @@ -61,12 +60,14 @@ def reference(
def input_data(self, grid) -> dict:
tracer_now = data_alloc.random_field(grid, dims.CellDim, dims.KDim)
rhodz_now = data_alloc.random_field(grid, dims.CellDim, dims.KDim)
p_mflx_tracer_v = data_alloc.random_field(grid, dims.CellDim, dims.KDim, extend={dims.KDim: 1})
p_mflx_tracer_v = data_alloc.random_field(
grid, dims.CellDim, dims.KDim, extend={dims.KDim: 1}
)
deepatmo_divzl = data_alloc.random_field(grid, dims.KDim)
deepatmo_divzu = data_alloc.random_field(grid, dims.KDim)
rhodz_new = data_alloc.random_field(grid, dims.CellDim, dims.KDim)
tracer_new = data_alloc.zero_field(grid, dims.CellDim, dims.KDim)
k = data_alloc.allocate_indices(dims.KDim, grid, is_halfdim=False,dtype=gtx.int32 )
k = data_alloc.allocate_indices(dims.KDim, grid, is_halfdim=False, dtype=gtx.int32)
p_dtime = np.float64(5.0)
ivadv_tracer = 1
iadv_slev_jt = 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import numpy as np
import pytest


import icon4py.model.testing.helpers as helpers
from icon4py.model.atmosphere.advection.stencils.limit_vertical_slope_semi_monotonically import (
limit_vertical_slope_semi_monotonically,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from icon4py.model.common import dimension as dims
from icon4py.model.common.utils import data_allocation as data_alloc


class TestPostprocessAntidiffusiveCellFluxesAndMinMax(helpers.StencilTest):
PROGRAM = postprocess_antidiffusive_cell_fluxes_and_min_max
OUTPUTS = ("z_tracer_new_low", "z_tracer_max", "z_tracer_min")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import numpy as np
import pytest

import icon4py.model.testing.helpers as helpers
import icon4py.model.common.utils.data_allocation as data_alloc
import icon4py.model.testing.helpers as helpers
from icon4py.model.atmosphere.advection.stencils.prepare_ffsl_flux_area_patches_list import (
prepare_ffsl_flux_area_patches_list,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from icon4py.model.common import dimension as dims
from icon4py.model.common.utils import data_allocation as data_alloc


class TestPrepareNumericalQuadratureListForCubicReconstruction(helpers.StencilTest):
PROGRAM = prepare_numerical_quadrature_list_for_cubic_reconstruction
OUTPUTS = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import numpy as np
import pytest

import icon4py.model.testing.helpers as helpers
import icon4py.model.common.utils.data_allocation as data_alloc
import icon4py.model.testing.helpers as helpers
from icon4py.model.atmosphere.advection.stencils.reconstruct_cubic_coefficients_svd import (
reconstruct_cubic_coefficients_svd,
)
from icon4py.model.common import dimension as dims
from icon4py.model.common.grid import horizontal as h_grid


class TestReconstructCubicCoefficientsSvd(helpers.StencilTest):
PROGRAM = reconstruct_cubic_coefficients_svd
OUTPUTS = (
Expand Down
Loading

0 comments on commit 77a7a68

Please sign in to comment.