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

Porting the tracer advection to gt4py #252

Merged
merged 119 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
2e37841
Add first 5 tracer advection stencils to icon4py
muellch Sep 9, 2022
6fda446
Fix hflx limiter pd stencil (#91)
halungge Sep 20, 2022
7cd58ed
Fixes to hflx_limiter_pd_stencil_02 to make it pass probtest
muellch Sep 27, 2022
8b324a3
Tracer advection stencil porting ml -> tracer advection stencils (#98)
halungge Oct 12, 2022
2446205
fix return type of hflx_limiter_mo_stencil_03.py (#104)
halungge Oct 14, 2022
e7de05a
Tracer advection stencils - agopal (#93)
abishekg7 Oct 14, 2022
fd9d93f
Fix v_limit_prbl_sm_stencil_01 (#107)
abishekg7 Oct 14, 2022
fdf3aed
Tracer advection stencils zero copy (#106)
halungge Oct 19, 2022
60391f1
fix pre-commit hook
halungge Oct 19, 2022
f9df7b4
Add third coefficient to upwind hflux miura stencil 02
muellch Oct 24, 2022
73addd3
Merge branch 'main' into tracer_advection_stencils
Dec 5, 2022
b90bb4e
hflux_ffsl_hybrid (scheme 5) stencils
Jan 4, 2023
98c60e6
recon_lsq_cell_c_stencil.py addition but svd=False doesn't work in ICON
Jan 6, 2023
f861a3f
CECEC + C2E2C2E2C definitions added
Jan 13, 2023
006cadd
Merge branch 'main' into tracer_advection_stencils
muellch Jan 29, 2023
fcae838
Merge branch 'main' into tracer_advection_stencils
muellch Feb 7, 2023
9af4c87
first try
huppd Feb 9, 2023
6f5b7b4
add _face_val_ppm_stencil_01
huppd Feb 14, 2023
ccce859
add more stencils
huppd Feb 14, 2023
090147b
rename file
huppd Feb 16, 2023
1c781e4
merge stencils
huppd Feb 16, 2023
54e5d2f
add stencil 2
huppd Feb 16, 2023
b2e8536
remove stencil 3
huppd Feb 16, 2023
2f018e2
fix bounds
huppd Feb 22, 2023
11e63e3
fix test
huppd Feb 22, 2023
4ec708b
fix test
huppd Feb 22, 2023
4773201
fix test
huppd Feb 22, 2023
bf80cf4
add test
huppd Feb 23, 2023
a127cb3
cleanup
huppd Feb 23, 2023
9e32f4f
fix
huppd Feb 23, 2023
d88e899
fix stencil
huppd Feb 23, 2023
25f16ee
cleanup
huppd Feb 24, 2023
9a7c475
add second test
huppd Feb 24, 2023
f31ce79
cleanup
huppd Feb 24, 2023
ab9255d
rm print
huppd Feb 24, 2023
38520aa
fix stencil
huppd Mar 3, 2023
c6c66d4
fix test
huppd Mar 3, 2023
fc37993
rm stenc
huppd Mar 3, 2023
976f0de
WIP stencil 03
huppd Mar 10, 2023
c71af47
first draft for 5
huppd Mar 14, 2023
3e52303
Merge remote-tracking branch 'origin/main' into tracer_advection_sten…
huppd Mar 23, 2023
539aa10
fix merge
huppd Mar 23, 2023
96b7222
cleanup
huppd Mar 23, 2023
1394d8e
Merge remote-tracking branch 'origin/main' into tracer_advection_sten…
huppd Mar 30, 2023
540b987
Fixed code generation bug in case there are no tolerance fields
muellch Apr 3, 2023
3788147
Merge branch 'main' into tracer_advection_stencils_hud
muellch Apr 3, 2023
6c3faac
change from acc parallel to acc kernels
huppd Apr 12, 2023
d4e07d6
Merge branch 'tracer_advection_stencils_hud' of github.com:C2SM/icon4…
huppd Apr 12, 2023
a1fbbba
Merge remote-tracking branch 'origin/main' into tracer_advection_sten…
huppd Apr 13, 2023
548591f
first draft
huppd May 4, 2023
c230cb5
first cleanup startcreate
huppd May 4, 2023
bbae0c0
update validate
huppd May 4, 2023
07c6bf7
make START CREATE with Arguements
huppd May 4, 2023
a8b21a9
kind of working
huppd May 9, 2023
3400755
fix generate
huppd May 9, 2023
0db9940
add accnodata
huppd May 15, 2023
928ac5e
fix before fields
huppd May 17, 2023
b6966bf
fix first testss
huppd May 17, 2023
2773148
fix test_generation
huppd May 23, 2023
f02de62
fix test
huppd May 23, 2023
19debe5
fix parser
huppd May 23, 2023
60bb671
fix test
huppd May 23, 2023
0552f74
fix test
huppd May 23, 2023
2c6292e
update README
huppd May 23, 2023
7a560a7
impprove README
huppd May 23, 2023
366a0bb
fix style
huppd May 25, 2023
96b593f
Merge remote-tracking branch 'origin/main' into tracer_advection_sten…
huppd Jun 8, 2023
cf990a1
update style
huppd Jun 8, 2023
11f805b
split stencil
huppd Jun 12, 2023
e585d2e
Merge remote-tracking branch 'origin/main' into tracer_advection_sten…
huppd Jun 12, 2023
577b548
fix test utils
huppd Jun 12, 2023
8f34b57
fix advection
huppd Jun 13, 2023
ff2885f
fix advection tests
huppd Jun 13, 2023
5f5fd40
fix style
huppd Jun 13, 2023
06f6e8d
fix test
huppd Jun 13, 2023
b425274
fix style
huppd Jun 13, 2023
b6b406a
add init
huppd Jun 13, 2023
095df44
fix stencil
huppd Jun 19, 2023
fd5bcb0
add optional feature to allow mergecopy for more then two stencils
huppd Jun 19, 2023
de73562
split stencil
huppd Jun 19, 2023
f44a92e
fix style
huppd Jun 19, 2023
1785a89
add utest
huppd Jun 19, 2023
e760e9f
fix style
huppd Jun 19, 2023
f327de2
advection cycling routine addition + relative idx in btraj o1 modific…
Jun 28, 2023
3bc12da
adapt stencil btraj_compute_01
Jul 20, 2023
0ec6e1e
adapt stencil upwind_hflux_miura_stencil_01.py
Jul 20, 2023
21628a3
add hybrid_stencil_01a and liskofy hybrid_stencil_02
Jul 20, 2023
b244b55
Adapt btraj_dreg_03 and modify short length condition
Jul 20, 2023
d035ebc
liskofy recon_lsq_cell_l/c_svd
Jul 20, 2023
23a1bf2
liskofy divide_flux_area_list_stencil_01/02.py
Jul 20, 2023
145b159
Adapt+add stencils+tests for advection scheme 52
Jul 27, 2023
1d48a14
Merge origin/main into dsl_advection_52_part2
Jul 27, 2023
2322c5e
Moved files according to icon4py model structure
Jul 27, 2023
55688dd
Add README and requirements to advection folder
Jul 27, 2023
cded6f5
Adapt to icon4py refactor for advection
Jul 28, 2023
cc0aff9
Merge branch 'main' of github.com:C2SM/icon4py into tracer_advection_…
Aug 18, 2023
27b89e9
Pre-commit run - ICON4Py Quality Assurance
Aug 21, 2023
ab1bf91
Place compute_airmass.py and btraj_01.py in right directory and adapt…
Aug 24, 2023
fdbb38a
Remove __init__.py in advection/tests/ and dycore/tests for pytest to…
Aug 25, 2023
eec8057
Modify recon_lsq_cell_c_stencil.py (not used in ICON code path)
Aug 25, 2023
d85b366
Correct for passing flake8 code style checks
Aug 25, 2023
a0bb3f3
Merge remote-tracking branch 'origin/main' into tracer_advection_sten…
Aug 28, 2023
d45cdc2
Pre-commit run
Aug 28, 2023
5b9fd19
Merge remote-tracking branch 'origin/main' into tracer_advection_sten…
Sep 8, 2023
f42ae38
Adapt pre-commit and QA fixes for advection component
Sep 8, 2023
a76337f
Pre-commit run with new configs
Sep 8, 2023
3851687
Change names for test folders to '<component>_tests' and add __init__.py
Sep 8, 2023
a95c820
Merge greenline to main (#260)
halungge Sep 12, 2023
0872455
[CI] add option to use custom spack-c2sm branch for spack tests (#268)
jonasjucker Sep 13, 2023
7876eb5
Adapt conftest.py and remove stencil not in code path
Sep 21, 2023
6a7d8f1
Fix test references (assuming wrap around) (#270)
havogt Sep 19, 2023
6358ce9
Fix typing in icon4pytools (#267)
samkellerhals Sep 21, 2023
9e2fbb4
Ignore delete statements in fused mode (#266)
huppd Sep 26, 2023
ad6b8b7
Add custom marker slow_tests to skip 4 slow stencils for testing
Sep 26, 2023
a50b1af
Run pre-commit
Sep 26, 2023
24a6788
Add custom marker slow_tests to skip 4 slow stencils for testing
Sep 26, 2023
d4436c0
Run pre-commit
Sep 26, 2023
303882b
Merge remote-tracking branch 'origin/main' into tracer_advection_sten…
Sep 27, 2023
aad80b8
pre-commit fix
Sep 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/icon4py-qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ jobs:
- name: Run checks icon4py-model-atmosphere-diffusion
run: |
pre-commit run --config model/atmosphere/diffusion/.pre-commit-config.yaml --all-files

- name: Run checks icon4py-model-atmosphere-advection
run: |
pre-commit run --config model/atmosphere/advection/.pre-commit-config.yaml --all-files
2 changes: 2 additions & 0 deletions model/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ It includes the following packages:

- `atmosphere/dycore`: Contains implementations of the dynamical core of the ICON model
- `atmosphere/diffusion`: Contains the implementation of diffusion in the ICON model
- `atmosphere/advection`: Contains implementations of the advection component of the ICON model
- `common`: Contains shared functionality that is required by multiple components.
- `driver`: Contains the driving code for the model

Expand All @@ -18,6 +19,7 @@ In the following example it is assumed that you have already created and activat
```bash
# changing into the corresponding directory
cd model/atmosphere/dycore
cd model/atmosphere/advection

# installing a development version
pip install -r requirements-dev.txt
Expand Down
42 changes: 42 additions & 0 deletions model/atmosphere/advection/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[flake8]
# Some sane defaults for the code style checker flake8
max-line-length = 100
max-complexity = 15
doctests = true
extend-ignore =
# Do not perform function calls in argument defaults
B008,
# Public code object needs docstring
D1,
# Disable dargling errors by default
DAR,
# Whitespace before ':' (black formatter breaks this sometimes)
E203,
# Line too long (using Bugbear's B950 warning)
E501,
# Line break occurred before a binary operator
W503

exclude =
.eggs,
.gt_cache,
.ipynb_checkpoints,
.tox,
_local_,
build,
dist,
docs,
_external_src,
tests/_disabled,
setup.py

rst-roles =
py:mod, mod,
py:func, func,
py:data, data,
py:const, const,
py:class, class,
py:meth, meth,
py:attr, attr,
py:exc, exc,
py:obj, obj,
114 changes: 114 additions & 0 deletions model/atmosphere/advection/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# NOTE: pre-commit runs all hooks from the root folder of the repository,
# as regular git hooks do. Therefore, paths passed as arguments to the plugins
# should always be relative to the root folder.

default_stages: [commit, push]
default_language_version:
python: python3.10
minimum_pre_commit_version: 2.20.0
files: "model/atmosphere/advection/.*"

repos:
- repo: meta
hooks:
- id: check-hooks-apply
stages: [manual]
- id: check-useless-excludes
stages: [manual]

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.20.1
hooks:
# Run only manually because it deletes comments
- id: setup-cfg-fmt
name: format setup.cfg
stages: [manual]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-case-conflict
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: check-yaml
- id: debug-statements
- id: destroyed-symlinks

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.6.0
hooks:
- id: pretty-format-ini
args: [--autofix]
- id: pretty-format-toml
args: [--autofix]
- id: pretty-format-yaml
args: [--autofix, --preserve-quotes, --indent, "2"]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.4
hooks:
- id: prettier
types_or: [markdown, json]

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.3.0
hooks:
- id: insert-license
name: add license for all ICON4Py Python source files
types: [python]
args: [--comment-style, "|#|", --license-filepath, model/.license_header.txt, --fuzzy-match-generates-todo]

- repo: https://github.com/asottile/yesqa
rev: v1.3.0
hooks:
- id: yesqa

- repo: https://github.com/psf/black
rev: '22.3.0'
hooks:
- id: black
name: black Python formatter
args: [--config, model/atmosphere/advection/pyproject.toml]

- repo: https://github.com/asottile/blacken-docs
rev: v1.12.1
hooks:
- id: blacken-docs
name: black Python formatter for docstrings
additional_dependencies: [black==22.3.0]

- repo: https://github.com/PyCQA/isort
rev: '5.12.0'
hooks:
- id: isort
args: [--config-root, model/atmosphere/advection/, --resolve-all-configs]

- repo: https://github.com/PyCQA/flake8
rev: '4.0.1'
hooks:
- id: flake8
name: flake8 code style checks
additional_dependencies:
- darglint
- flake8-bugbear
- flake8-builtins
- flake8-debugger
- flake8-docstrings
- flake8-eradicate
- flake8-mutable
- pygments
args: [--config=model/atmosphere/advection/.flake8, model/atmosphere/advection/src/icon4py/]

- repo: local
hooks:
- id: mypy
name: mypy static type checker
entry: bash -c 'echo mypy temporarily disabled'
#entry: bash -c 'cd model/atmosphere/dycore; mypy src/' --
language: system
types_or: [python, pyi]
always_run: true
#pass_filenames: false
require_serial: true
stages: [commit]
9 changes: 9 additions & 0 deletions model/atmosphere/advection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# icon4py-atmosphere-advection

## Description

Contains code ported from ICON `src/advection`, which is the advection component of the ICON model.

## Installation instructions

Check the `README.md` at the root of the `model` folder for installation instructions.
12 changes: 12 additions & 0 deletions model/atmosphere/advection/advection_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# ICON4Py - ICON inspired code in Python and GT4Py
#
# Copyright (c) 2022, ETH Zurich and MeteoSwiss
# All rights reserved.
#
# This file is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or any later
# version. See the LICENSE.txt file at the top-level directory of this
# distribution for a copy of the license or check <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
33 changes: 33 additions & 0 deletions model/atmosphere/advection/advection_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ICON4Py - ICON inspired code in Python and GT4Py
#
# Copyright (c) 2022, ETH Zurich and MeteoSwiss
# All rights reserved.
#
# This file is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or any later
# version. See the LICENSE.txt file at the top-level directory of this
# distribution for a copy of the license or check <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
import pytest
from gt4py.next.program_processors.runners.roundtrip import executor

from icon4py.model.common.test_utils.simple_mesh import SimpleMesh


BACKENDS = {"embedded": executor}
MESHES = {"simple_mesh": SimpleMesh()}


@pytest.fixture(
ids=MESHES.keys(),
params=MESHES.values(),
)
def mesh(request):
return request.param


@pytest.fixture(ids=BACKENDS.keys(), params=BACKENDS.values())
def backend(request):
return request.param
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# ICON4Py - ICON inspired code in Python and GT4Py
#
# Copyright (c) 2022, ETH Zurich and MeteoSwiss
# All rights reserved.
#
# This file is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or any later
# version. See the LICENSE.txt file at the top-level directory of this
# distribution for a copy of the license or check <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later

import numpy as np

from icon4py.model.atmosphere.advection.btraj_dreg_stencil_01 import btraj_dreg_stencil_01
from icon4py.model.common.dimension import EdgeDim, KDim
from icon4py.model.common.test_utils.helpers import random_field, zero_field
from icon4py.model.common.test_utils.simple_mesh import SimpleMesh


def btraj_dreg_stencil_01_numpy(
lcounterclock: bool,
p_vn: np.array,
tangent_orientation: np.array,
):
tangent_orientation = np.expand_dims(tangent_orientation, axis=-1)

tangent_orientation = np.broadcast_to(tangent_orientation, p_vn.shape)

lvn_sys_pos_true = np.where(tangent_orientation * p_vn >= 0.0, True, False)

mask_lcounterclock = np.broadcast_to(lcounterclock, p_vn.shape)

lvn_sys_pos = np.where(mask_lcounterclock, lvn_sys_pos_true, False)

return lvn_sys_pos


def test_btraj_dreg_stencil_01():
mesh = SimpleMesh()
lcounterclock = True
p_vn = random_field(mesh, EdgeDim, KDim)

tangent_orientation = random_field(mesh, EdgeDim)

lvn_sys_pos = zero_field(mesh, EdgeDim, KDim, dtype=bool)

ref = btraj_dreg_stencil_01_numpy(
lcounterclock,
np.asarray(p_vn),
np.asarray(tangent_orientation),
)

btraj_dreg_stencil_01(
lcounterclock,
p_vn,
tangent_orientation,
lvn_sys_pos,
offset_provider={},
)

assert np.allclose(ref, lvn_sys_pos)
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# ICON4Py - ICON inspired code in Python and GT4Py
#
# Copyright (c) 2022, ETH Zurich and MeteoSwiss
# All rights reserved.
#
# This file is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or any later
# version. See the LICENSE.txt file at the top-level directory of this
# distribution for a copy of the license or check <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later

import numpy as np
from gt4py.next.ffront.fbuiltins import int32
from gt4py.next.iterator.embedded import StridedNeighborOffsetProvider

from icon4py.model.atmosphere.advection.btraj_dreg_stencil_02 import btraj_dreg_stencil_02
from icon4py.model.common.dimension import ECDim, EdgeDim, KDim
from icon4py.model.common.test_utils.helpers import as_1D_sparse_field, random_field, zero_field
from icon4py.model.common.test_utils.simple_mesh import SimpleMesh


def btraj_dreg_stencil_02_numpy(
p_vn: np.array,
p_vt: np.array,
edge_cell_length: np.array,
p_dt: float,
):
lvn_pos = np.where(p_vn >= 0.0, True, False)

traj_length = np.sqrt(p_vn**2 + p_vt**2) * p_dt

edge_cell_length = np.expand_dims(edge_cell_length, axis=-1)
e2c_length = np.where(lvn_pos, edge_cell_length[:, 0], edge_cell_length[:, 1])

opt_famask_dsl = np.where(
traj_length > (1.25 * np.broadcast_to(e2c_length, p_vn.shape)),
int32(1),
int32(0),
)

return opt_famask_dsl


def test_btraj_dreg_stencil_02():
mesh = SimpleMesh()
p_vn = random_field(mesh, EdgeDim, KDim)
p_vt = random_field(mesh, EdgeDim, KDim)
edge_cell_length = np.asarray(mesh.e2c, dtype=float)
edge_cell_length_new = as_1D_sparse_field(edge_cell_length, ECDim)
p_dt = 1.0
opt_famask_dsl = zero_field(mesh, EdgeDim, KDim, dtype=int32)

ref = btraj_dreg_stencil_02_numpy(
np.asarray(p_vn), np.asarray(p_vt), np.asarray(edge_cell_length), p_dt
)

btraj_dreg_stencil_02(
p_vn,
p_vt,
edge_cell_length_new,
p_dt,
opt_famask_dsl,
offset_provider={
"E2C": mesh.get_e2c_offset_provider(),
"E2EC": StridedNeighborOffsetProvider(EdgeDim, ECDim, mesh.n_e2c),
},
)

assert np.allclose(ref, opt_famask_dsl)
Loading