ICON model in Python.
Project description
ICON4Py
This repository hosts a work-in-progress Python implementation of the ICON climate and weather model. Additionally, it includes icon4py.tools, a collection of command-line interfaces (CLIs), and utilities required for the integration of ICON4Py code into the ICON Fortran model. ICON4Py leverages GT4Py to ensure efficient and performance portable implementations of these components.
Project Structure
The repository is organized as a monorepo, where various ICON model components and utilities are developed as independent Python namespace packages in subfolders. An icon4py Python package is defined at the root folder with the purpose to collect specific versions of the different components as package dependencies. The component can also be installed independently, although since they are not (yet) available from a package repository, they need to be installed from their specific location within this repository.
License
ICON4Py is licensed under the terms of the BSD-3-Clause.
Installation Instructions
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 and installing it in a Python virtual environment (venv).
ICON4Py uses the uv project manager for development workflow. uv is a versatile tool that consolidates functionality previously distributed across different applications into subcommands.
- The
uv pipsubcommand provides a fast Python package manager, emulatingpip. - The
uv export | lock | syncsubcommands manage dependency versions in a manner similar to thepip-toolscommand suite. - The
uv init | add | remove | build | publish | ...subcommands facilitate project development workflows, akin tohatch. - The
uv toolsubcommand serves as a runner for Python applications in isolation, similar topipx. - The
uv pythonsubcommands manage different Python installations and versions, much likepyenv.
uv can be installed in various ways (see its installation instructions), with the recommended method being the standalone installer:
$ curl -LsSf https://astral.sh/uv/install.sh | sh
ICON4Py Development Environment
Once uv is installed in your system, it is enough to clone this repository and let uv handling the installation of the development environment.
Important: the uv sync command should always be executed from the root folder of the repository, to make sure it installs all the workspace dependencies and not only the dependencies of a subproject.
The --extra distributed option installs mpi4py and ghex, which require Boost headers and an MPI implementation (e.g. OpenMPI) to be available on the system.
# Clone the repository
git clone git@github.com:C2SM/icon4py.git
cd icon4py
# Let uv create the development environment at `.venv`.
# The `--extra all` option tells uv to install all the optional
# dependencies of icon4py, and thus it is not strictly necessary.
# Note that if no dependency groups are provided as an option,
# uv uses `--group dev` by default so the development dependencies
# are also installed.
uv sync --extra all
# Activate the virtual environment and start writing code!
source .venv/bin/activate
The new venv is a standard Python virtual environment preconfigured with all necessary runtime and development dependencies. Additionally, all icon4py subpackages are installed in editable mode, allowing for seamless development and testing.
To install new packages, use the uv pip subcommand, which emulates the pip interface and is generally much faster. Alternatively, the standard pip command is also available within the venv, although using pip directly is slower and not recommended.
The pyproject.toml file at the root folder contains both the definition of the icon4py Python distribution package and the settings of the development tools used in this project, most notably uv, ruff, mypy and pytest. It also contains dependency groups (see PEP 735 for further reference) with the development requirements listed in different groups (build, docs, lint, test, typing, ...) and collected together in the general dev group which gets installed by default by uv.
Development Instructions
By following the installation instructions above, the source files are imported directly by the Python interpreter meaning that any code change is available and executed by the interpreter.
To add new dependencies to the project, either core/optional run-time or development-only dependencies, it is possible to use the uv cli direcly or to modify by hand the appropriate tables in the corresponding pyproject.toml (check uv documentation for more information https://docs.astral.sh/uv/concepts/projects/dependencies/).
Code Quality Checks
pre-commit is used to run several linting and checking tools. It should always be executed locally before opening a pull request. When executing pre-commit locally you can either run it for the model or tools folder:
For example to run code checks on all components in icon4py.model you can do:
# running precommit for all components in model
cd model/
pre-commit run --all-files
Testing
pytest is used for testing and it also comes with a command tool to easily run tests:
# Run all tests (verbose mode)
pytest -v
# Run only tests in `path/to/test/folder`
pytest -v path/to/test/folder
nox is recommended for running comprehensive test suites across multiple Python versions and configurations, mirroring the setup used in the CI pipeline.
# List all available test sessions (colored items are the default sessions)
nox -l
# Run all parametrized cases of a session
nox -s 'test_common'
# Run a test session for a specific python version and parameter value
nox -s 'test_atmosphere_advection-3.10(datatest=True)'
To run distributed tests, make sure an MPI implementation is installed and run uv sync --extra distributed or uv sync --extra all. Then run tests using mpirun, the --with-mpi pytest flag, and the -k mpi_tests filter:
mpirun -np 4 pytest -v -s --with-mpi -k mpi_tests
To avoid all ranks writing their test output to stdout, use the helper script ci/scripts/ci-mpi-wrapper.sh around the pytest command:
mpirun -np 4 ci/scripts/ci-mpi-wrapper.sh pytest -v -s --with-mpi -k mpi_tests
Distributed runs on Alps
Compiling
On Alps with Cray MPICH and GH200 or A100 GPUs, install mpi4py and GHEX as follows:
export GHEX_USE_GPU=ON
export GHEX_GPU_TYPE=NVIDIA
export GHEX_GPU_ARCH="80;90"
export GHEX_TRANSPORT_BACKEND=MPI
export MPICH_CXX=$(which g++)
export MPICH_CC=$(which gcc)
uv sync --no-binary-package mpi4py --extra all --extra distributed --extra cuda12 --python $(which python) --refresh
If you already have a broken GHEX, mpi4py, or other package in the uv cache, run the command with --no-cache after either uninstalling the broken package or wiping the virtualenv.
--no-binary-package mpi4py is required because Cray MPICH is not ABI compatible with the MPI used to build mpi4py binary wheels. If you don't do this you may get an error like:
ImportError: libmpi.so.12: cannot open shared object file: No such file or directory
when importing mpi4py. The GHEX_* options tell GHEX to build with GPU support. If you don't, you may see errors like:
AttributeError: module 'ghex.pyghex' has no attribute 'unstructured__data_descriptor_gpu_int_int_double_'
when GHEX tries to perform halo exchanges. The MPICH_* options make sure mpi4py gets built with GCC instead of NVHPC. mpi4py assumes that it can set certain compiler flags that GCC supports, but NVHPC does not support. The error message will typically look like:
[stderr]
nvc-Error-Unknown switch: -fwrapv
error: Cannot compile MPI programs. Check your configuration!!!
Installing mpi4py requires a working MPI implementation.
If you are running on a supercomputer or cluster, check with
the system administrator or refer to the system user guide.
Otherwise, if you are running on a laptop or desktop computer,
your may be missing the MPICH or Open MPI development package:
Running
When running make sure to
export MPICH_GPU_SUPPORT_ENABLED=1
export GT4PY_UNSTRUCTURED_HORIZONTAL_HAS_UNIT_STRIDE=1
Cray MPICH will otherwise segfault when communicating GPU buffers. Also see the CSCS Cray MPICH documentation for more details.
The UNIT_STRIDE variable is necessary when using the DaCe backend, which otherwise fails (see PR1130).
When performance is important you may want to
export PYTHONOPTIMIZE=2
Benchmarking
We use pytest-benchmark to benchmark the execution time of stencils in icon4py. To disable benchmarking during testing you can use --benchmark-disable when invoking pytest.
Documentation
Documentation is at a very early stage given the constant state of development. Ongoing efforts to document the dycore can be viewed at c2sm.github.io/icon4py.
You can install the required packages by using the provided docs dependency group, which is included in the dev installed by default by uv sync if no dependency groups are specified.
To build the html documentation in your local repository copy starting from the most upwards directory, apply the following commands:
cd model/atmosphere/dycore/docs
make html
The local documentation could then be accessed at docs/_build/html/index.html
More Information
For more information please consult the package specific READMEs found in the model and tools folders.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file icon4py-0.2.0rc2.tar.gz.
File metadata
- Download URL: icon4py-0.2.0rc2.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c979492ae3be8ea448f5fbca2393dc3f0950a261b45859548c1c8e6158a322f9
|
|
| MD5 |
e8ec76ea588f6da41f3b927b21eb6e58
|
|
| BLAKE2b-256 |
2bf6aa222b713673d1294535ece2bae64b747c8045d12f234b1cc61e0ee0cc38
|
Provenance
The following attestation bundles were made for icon4py-0.2.0rc2.tar.gz:
Publisher:
pypi-deploy.yml on C2SM/icon4py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
icon4py-0.2.0rc2.tar.gz -
Subject digest:
c979492ae3be8ea448f5fbca2393dc3f0950a261b45859548c1c8e6158a322f9 - Sigstore transparency entry: 1641167680
- Sigstore integration time:
-
Permalink:
C2SM/icon4py@4e9dad8a1fa0193c82216e1440e658d73774f116 -
Branch / Tag:
refs/tags/v0.2.0rc2 - Owner: https://github.com/C2SM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-deploy.yml@4e9dad8a1fa0193c82216e1440e658d73774f116 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file icon4py-0.2.0rc2-py3-none-any.whl.
File metadata
- Download URL: icon4py-0.2.0rc2-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0dc17482c935e17cac866e35bea0183a9328191de525e75e769281afe59a01cd
|
|
| MD5 |
5f18b4a92f8db2e9f641dba4b6e031a5
|
|
| BLAKE2b-256 |
b8abd379c2283a08434185178e39ba4c9cb301034b3827fe1bf07fd67adc7e9e
|
Provenance
The following attestation bundles were made for icon4py-0.2.0rc2-py3-none-any.whl:
Publisher:
pypi-deploy.yml on C2SM/icon4py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
icon4py-0.2.0rc2-py3-none-any.whl -
Subject digest:
0dc17482c935e17cac866e35bea0183a9328191de525e75e769281afe59a01cd - Sigstore transparency entry: 1641167822
- Sigstore integration time:
-
Permalink:
C2SM/icon4py@4e9dad8a1fa0193c82216e1440e658d73774f116 -
Branch / Tag:
refs/tags/v0.2.0rc2 - Owner: https://github.com/C2SM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-deploy.yml@4e9dad8a1fa0193c82216e1440e658d73774f116 -
Trigger Event:
workflow_dispatch
-
Statement type: