Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
285 commits
Select commit Hold shift + click to select a range
a129138
start / end indices (WIP) add refinement.py
Sep 3, 2024
d303d90
merge main
Sep 3, 2024
82c2cf5
compute start end indices for Zones: local, halos
Sep 4, 2024
2ef989d
refactor: grid manager
Sep 4, 2024
73091d7
add boundary zones to test
Sep 4, 2024
02950be
Merge branch 'main' into halo_construction
Sep 4, 2024
6095199
use GridFile as content manager in grid_manager
Sep 5, 2024
a2d3d5e
make GridManager implement context manager
Sep 5, 2024
51bc2cd
get dummy parallel test_parallel_grid_manager.py to run
Sep 6, 2024
ebad859
Merge branch 'main' into halo_construction
Sep 6, 2024
5d9a331
add data URI for parallel APE R02B04 experiment
Sep 6, 2024
d53104c
merge main
Oct 4, 2024
161e097
merge main
Dec 12, 2024
013c078
merge main
Jan 15, 2025
c468651
Merge branch 'main' into halo_construction
Jul 3, 2025
aa1eccf
Merge branch 'main' into halo_construction
Jul 9, 2025
e01bc8d
fix grid_tests
Jul 9, 2025
35521c2
move test files in decomposition, fix some errors in halo.py
Jul 9, 2025
5ebd07f
fix tests
Jul 10, 2025
8596a8a
delete unused enum
Jul 10, 2025
e88bef9
add docstrings for decomposer
Jul 10, 2025
059add0
rename with_decomposer to set_decomposer
Jul 10, 2025
a4adf65
fix Optional typeing
Jul 10, 2025
05591c3
add TODO
Jul 10, 2025
3f54b8d
pass decomposition mapping in __call__
Jul 10, 2025
00b05e7
pass face to rank distributon to __call__
Jul 11, 2025
2cdcea6
WIP (1)
Jul 11, 2025
c5975ff
validate decomposer and run_properties
Jul 11, 2025
dbe051f
fix processor_props parametrization
Jul 11, 2025
badb246
Merge branch 'main' into halo_construction
Jul 22, 2025
a4b52c7
Merge branch 'main' into halo_construction
Jul 25, 2025
204f5a0
Merge branch 'main' into halo_construction
Jul 25, 2025
f51b9b8
rename GridConfig.horizontal_config to GridConfig.horizontal_size
Jul 25, 2025
683ec59
fix test_halo.py
Jul 25, 2025
562ff50
construct local patch (I)
Jul 25, 2025
72d4d4b
Merge branch 'main' into halo_construction
Jul 25, 2025
fa7e620
Merge branch 'main' into halo_construction
Jul 29, 2025
704cebc
global_to_local (1)
Jul 29, 2025
66cd76c
add global to local function
Aug 6, 2025
57993bb
Merge branch 'main' into halo_construction
Aug 6, 2025
90cbda1
run pre-commit
Aug 6, 2025
875b267
fix issues from merge (WIP 1)
Aug 7, 2025
2df11a7
move test files
Aug 8, 2025
361b582
remove grid size form decomposition info
Aug 8, 2025
ffe7023
duplicate _construct_grid to make single node tests run
Aug 8, 2025
514b14d
test fix
Aug 8, 2025
6c7d35e
test fix (3)
Aug 8, 2025
f6c68ca
test fix (3) offset provider for KDim
Aug 8, 2025
ed2336d
remove duplicated test
Aug 8, 2025
fc65d6d
apply global to local
Aug 8, 2025
2bec8d8
fix global to local transformation in grid_manager
Aug 11, 2025
7b0d4d8
compute start end indices WIP (i)
Aug 13, 2025
21bf6c5
Merge branch 'main' into halo_construction
Aug 13, 2025
b9472a2
change start_indices and end_indices to map from domain to index
Aug 13, 2025
04c359f
fix setup of simple grid
Aug 13, 2025
bfbbf3e
remove _index from Domain
Aug 13, 2025
2c7a9c6
simple map Domain -> index
Aug 13, 2025
01dfddb
fix grid wrapper
Aug 13, 2025
1c990eb
revert unnecessary changes
Aug 13, 2025
f507594
do not use function under test in test assertion
Aug 14, 2025
8e7b266
Merge branch 'main' into refactor_start_end_indices
Aug 14, 2025
7045a4f
fix typing in horizontal.py
Aug 14, 2025
5d50b61
Merge branch 'main' into halo_construction
Aug 14, 2025
2525fb5
Merge branch 'refactor_start_end_indices' into halo_construction
Aug 14, 2025
4c95d92
some typing fixes
Aug 14, 2025
324a2c0
move transformation to gridfile.py
Aug 14, 2025
048cbbc
Merge branch 'main' into halo_construction
Aug 25, 2025
dde8759
pass decomposer to GridManager.__call__
Aug 26, 2025
1f61a40
move fixture import to conftests.py in model/common/tests/common/grid
Aug 26, 2025
a9d9d33
fix import
Aug 26, 2025
e501865
fix selective read from gridfile
Aug 26, 2025
14f408e
test:distribute and gather simple fields (WIP)
Aug 27, 2025
eef1ea8
simple comparisison global grid manager distributed fields
Aug 29, 2025
d31a075
Merge branch 'main' into halo_construction
Aug 29, 2025
e2cdc6d
clean up interfaces
Aug 29, 2025
39c093d
fix start_index, end_index datatests
Sep 1, 2025
222dee6
add test skeletion for testing neighbor access
Sep 2, 2025
22a9bd6
Merge branch 'main' into halo_construction
Sep 2, 2025
28f4a7f
Merge branch 'main' into halo_construction
Sep 3, 2025
ce0869d
setup test for c2e access
Sep 3, 2025
04c765a
remove connectivity workaround
Sep 3, 2025
7353c3c
add test skeleton (WIP)
Sep 3, 2025
34956c6
compute local size for config
Sep 4, 2025
003b70c
neighbor access test (WIP)
Sep 5, 2025
d1f35cb
fix field gather assertion for multi dimensional field
Sep 9, 2025
b9b76df
Merge branch 'main' into halo_construction
Sep 9, 2025
29ffd9e
fix some tests after merge
Sep 9, 2025
dd0fc14
fix some tests after merge
Sep 9, 2025
11070e6
Merge branch 'main' into halo_construction
Sep 18, 2025
ed9a36c
pre-commit
Sep 18, 2025
271d70b
fix some typting in test_parallel_grid_manager.py
Sep 18, 2025
eca2a8f
make test run again
Sep 19, 2025
ab0f21e
Merge branch 'main' into halo_construction
Sep 19, 2025
3698b9a
fixes from merge
Sep 20, 2025
7a4170c
Merge branch 'main' into halo_construction
Oct 7, 2025
c9be1d0
fix merge: global grid params
Oct 7, 2025
0a2d126
fix typings
Oct 8, 2025
785f7d1
remove obsolete TODO
Oct 8, 2025
c5ad92b
fix parallel diffusion tests
Oct 10, 2025
8791be0
fix parallel non hydro test
Oct 10, 2025
ef3b494
delete files unrelated to this PR
Oct 14, 2025
c87800c
delete files unrelated to this PR
Oct 14, 2025
6a73bf0
Merge branch 'main' into halo_construction
Oct 16, 2025
e484e0c
Merge branch 'main' into halo_construction
Nov 17, 2025
ed51c58
Merge branch 'main' into halo_construction
Nov 19, 2025
935b113
get grid tests to run again
Nov 19, 2025
179d4b7
get parallel test to run again
Nov 19, 2025
45bbbf6
get parallel test to run again
Nov 19, 2025
bb190ec
start/end index for halos (I)
Nov 20, 2025
e89c5e5
fix parallel test for start_index/end_index
Nov 25, 2025
464302a
add tests WIP(1)
Nov 26, 2025
b0746c3
fix typing
Dec 1, 2025
12dbe47
pre-commit
Dec 1, 2025
88ae0ec
add tests (WIP)
Dec 1, 2025
3c35b61
simple fixes
Dec 3, 2025
def79a5
fix reading of additional edge fields
Dec 10, 2025
b418ac2
make all tests run
Dec 10, 2025
7f5973d
fixing some things
Dec 10, 2025
3a7d474
Merge branch 'main' into halo_construction
Dec 10, 2025
73e6a08
fix typings
Dec 10, 2025
378d269
use dummy props on test to make them simple unit tests
Dec 11, 2025
927e7d1
add test to check skip value configuration
Dec 12, 2025
3f64b2a
simple clean ups in PR
Dec 12, 2025
799ac8a
move function only used in test
Dec 12, 2025
e796b74
fix imports in parallel tests
Dec 12, 2025
7f0dedf
add doc strings for compute_domain bounds
Dec 14, 2025
0ca46f0
Merge branch 'main' into halo_construction
Dec 14, 2025
b50691e
pre-commit
Dec 14, 2025
09d4aaf
move serializable tests to unit_tests
Dec 15, 2025
5df9adc
doc string for IconLikeHaloConstructor
Dec 15, 2025
4c8adf3
fix test_local_connectivity to run on grid_manager
Dec 15, 2025
34c61c4
move global_to_local function
Dec 16, 2025
3bee001
Merge branch 'main' into halo_construction
Dec 16, 2025
0a79fdf
add pymetis to standard common dependencies, fix old gt4py version in…
Dec 16, 2025
1fb0c25
mypy
Dec 16, 2025
305d7a0
add missing datatest annotation
Dec 16, 2025
aa95ce8
rename test functions
Jan 1, 2026
d1234ed
fix halo construction: additional vertices for second level edges
Jan 1, 2026
3aaef7d
fix: add "corner" cell
Jan 2, 2026
e5692f1
remove duplicate test
Jan 2, 2026
cddc724
fix edge DecompositionFlag.THIRD
Jan 2, 2026
bb94545
add embedded markers
Jan 2, 2026
43c933d
Merge branch 'main' into halo_construction
Jan 2, 2026
d738ee9
add xfail for dace
Jan 2, 2026
52ddcea
fix ordering
Jan 2, 2026
f211473
cleanup of docstring including @msimberg 's review
jcanton Jan 19, 2026
336db99
little cleanup
jcanton Jan 19, 2026
a983ed7
one more grid for testing
jcanton Jan 26, 2026
3dba11f
fix filename
jcanton Jan 26, 2026
9ec0045
Merge remote-tracking branch 'origin/main' into halo_construction
msimberg Jan 28, 2026
d20f82e
Remove outdated xfails
msimberg Jan 28, 2026
be499fe
Remove another xfail
msimberg Jan 28, 2026
b1cea99
Remove old TODO
msimberg Jan 29, 2026
ff4e7db
Pass num cells to global grid params
msimberg Jan 29, 2026
dbbf829
Revert "refactor: testing infrastructure (#1002)"
msimberg Jan 29, 2026
eed64eb
Fix cupy/numpy issues
msimberg Jan 29, 2026
5440d2b
Fix another cupy/numpy issue
msimberg Jan 30, 2026
dbde86b
More cupy/numpy
msimberg Jan 30, 2026
05ba45f
TODO for distributed check in IconGrid constructor
msimberg Jan 30, 2026
0ae367c
Formatting
msimberg Jan 30, 2026
221d364
Add name to TODO
msimberg Jan 30, 2026
6475ead
Linting
msimberg Jan 30, 2026
bee4bc2
Merge remote-tracking branch 'origin/main' into halo_construction
msimberg Jan 30, 2026
460be4b
Unrevert data download changes
msimberg Jan 30, 2026
de480b5
Rename single_node to is_single_rank
msimberg Feb 3, 2026
59fa8a3
Rename *single_node test to *single_rank
msimberg Feb 3, 2026
44038d5
Minor formatting change
msimberg Feb 3, 2026
cc1839b
Remove unused variable
msimberg Feb 3, 2026
4b26503
Remove another unused variable
msimberg Feb 3, 2026
8c8876b
Add extra assert to test_props
msimberg Feb 3, 2026
0c20e61
Rename MissingConnectivity to MissingConnectivityError
msimberg Feb 3, 2026
39bcbfd
Update halo cut example
msimberg Feb 3, 2026
a69c3c7
Reformat halo construction docstring
msimberg Feb 3, 2026
df3bb06
Remove unnecessary numpy.unique from halo construction
msimberg Feb 3, 2026
05e992c
Minor renamings in grid_manager.py
msimberg Feb 3, 2026
0c6942a
Simplify some returns in halo.py
msimberg Feb 3, 2026
34a8eb2
Simplify _find_neighbors
msimberg Feb 3, 2026
5c11cb4
Remove some trivial helper functions in halo.py
msimberg Feb 3, 2026
3a67b94
Clean up and fix typo in docstring in decomposition utils
msimberg Feb 3, 2026
0fc37b8
Add fixture for global grids (not limited area grids)
msimberg Feb 3, 2026
f895bb3
Minor bugfix for LAM/distributed configuration
msimberg Feb 3, 2026
412c554
Rename SimpleMetisDecomposer to MetisDecomposer
msimberg Feb 3, 2026
d33c0da
Minor reformatting and more torus tests in test_gridfile.py
msimberg Feb 3, 2026
0d95056
Fix connectivity
msimberg Feb 3, 2026
9ebc747
Remove debugging
msimberg Feb 3, 2026
aaaa514
Add simple test to check that metis decomposition is roughly balanced
msimberg Feb 3, 2026
2ed874e
Expand test_local_connectivity parametrization
msimberg Feb 3, 2026
19fc9d5
Add note about partitioning being deterministic
msimberg Feb 3, 2026
294956b
Rename face to cell in halo.py
msimberg Feb 4, 2026
95e5ef1
Move decomposer to a separate file
msimberg Feb 4, 2026
3926eaa
Revert num_levels/vertical config change
msimberg Feb 4, 2026
8068529
Remove helper next_halo_line
msimberg Feb 4, 2026
5e7b984
Simplify owned_cells
msimberg Feb 4, 2026
32fc3dc
Remove unnecessary xfail
msimberg Feb 4, 2026
cc642c7
Remove owned_cells helper
msimberg Feb 4, 2026
d275bf8
Add check to disallow limited area grids with distributed runs
msimberg Feb 4, 2026
0706f6e
Revert "Remove helper next_halo_line"
msimberg Feb 5, 2026
d2919af
Simplify, but don't remove, next_halo_line helper
msimberg Feb 5, 2026
d284330
Merge remote-tracking branch 'origin/main' into halo_construction
msimberg Feb 6, 2026
4637105
Refactor test_parallel_grid_manager.py
msimberg Feb 6, 2026
dcf72b5
Minor cleanup and todo in test_parallel_halo.py
msimberg Feb 6, 2026
f7eb9be
Cleanup and todo
msimberg Feb 6, 2026
48e9a21
Clean up todos
msimberg Feb 6, 2026
f29e554
Remove global_grid_descriptor fixture, try to add metrics test
msimberg Feb 6, 2026
e1d05f5
Fix decomposer import
msimberg Feb 6, 2026
f52a883
Update comments in halo.py
msimberg Feb 9, 2026
774900c
Small renaming
msimberg Feb 9, 2026
571d0f6
Copy owner mask
msimberg Feb 9, 2026
bcedac6
Remove UNDEFINED flag from DecompositionFlag
msimberg Feb 9, 2026
8cc732b
Small renaming
msimberg Feb 9, 2026
3877652
Add assertion
msimberg Feb 9, 2026
c7f5ef8
Small update to docstring
msimberg Feb 9, 2026
57c5d06
Check singlenodedecomposer num_partitions
msimberg Feb 9, 2026
204a5ab
Remove test_geometry_stencils.py
msimberg Feb 9, 2026
67cd219
Revert changes in test_geometry.py
msimberg Feb 9, 2026
9f298c9
Small refactoring
msimberg Feb 9, 2026
6ff1bd2
Revert "Minor bugfix for LAM/distributed configuration"
msimberg Feb 9, 2026
aecfb5f
xfail lam grid
msimberg Feb 9, 2026
777a396
Assert there are no invalid indices in adjacency matrix for metis
msimberg Feb 9, 2026
5609570
Small refactoring of test_local_connectivity
msimberg Feb 9, 2026
d55a20d
Fix test_local_connectivity
msimberg Feb 9, 2026
b814c9f
More tests for test_parallel_icon.py
msimberg Feb 9, 2026
60a0c8e
Merge remote-tracking branch 'origin/main' into halo_construction
msimberg Feb 9, 2026
079f3ac
Clean up todo
msimberg Feb 9, 2026
3fd4d31
Add todos
msimberg Feb 9, 2026
a94be5a
Update icon grid skip values again
msimberg Feb 9, 2026
0274189
Revert "Remove UNDEFINED flag from DecompositionFlag"
msimberg Feb 10, 2026
e97b1c4
Revert "Remove owned_cells helper"
msimberg Feb 10, 2026
0e24b76
Fix decomposer import
msimberg Feb 10, 2026
356695a
Use low enough index in test for all tested grids
msimberg Feb 10, 2026
ee8ce4a
Add rbf fields to test_parallel_grid_manager.py
msimberg Feb 10, 2026
395553f
Remove todo
msimberg Feb 10, 2026
cd74e0c
xfail some distributed geometry tests with embedded backend
msimberg Feb 11, 2026
f0baaa3
Merge remote-tracking branch 'origin/main' into halo_construction
msimberg Feb 11, 2026
672cd93
Remove duplicated test
msimberg Feb 11, 2026
a9b24fc
Remove unused imports
msimberg Feb 11, 2026
fe38371
Fix pytest.mark.xfail to pytest.xfail
msimberg Feb 11, 2026
f7f3724
Clean up docstring for Zone
msimberg Feb 11, 2026
c7d8a74
Don't use get on dict to ensure exception on missing entries
msimberg Feb 11, 2026
c8bfbc6
Fix import for ToZeroBasedIndexTransformation
msimberg Feb 11, 2026
86da004
Remove unused import
msimberg Feb 11, 2026
814814f
Rename single/multi-node to single/multi-rank
msimberg Feb 11, 2026
f7dae6e
Add missing word
msimberg Feb 11, 2026
7abfc3d
Remove todos
msimberg Feb 11, 2026
3973bfb
Remove todo
msimberg Feb 11, 2026
85b091d
Remove unused logger
msimberg Feb 11, 2026
8e85390
Small refactor in halo.py
msimberg Feb 11, 2026
9e3f0fc
Revert horizontal_size/horizontal_config rename
msimberg Feb 11, 2026
2bd04a7
Fix typo
msimberg Feb 11, 2026
2bf0d2a
Small renaming related to index offset/transformation
msimberg Feb 11, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from icon4py.model.common.metrics import metrics_attributes, metrics_factory
from icon4py.model.common.states import prognostic_state as prognostics
from icon4py.model.common.utils import data_allocation as data_alloc
from icon4py.model.testing import grid_utils
from icon4py.model.testing.fixtures.benchmark import (
geometry_field_source,
interpolation_field_source,
Expand Down Expand Up @@ -62,8 +61,6 @@ def solve_nonhydro(

nonhydro_params = solve_nh.NonHydrostaticParams(config)

decomposition_info = grid_utils.construct_decomposition_info(mesh, allocator)

vertical_config = v_grid.VerticalGridConfig(
mesh.num_levels,
lowest_layer_thickness=50,
Expand Down Expand Up @@ -205,11 +202,7 @@ def solve_nonhydro(
vertical_params=vertical_grid,
edge_geometry=edge_geometry,
cell_geometry=cell_geometry,
owner_mask=gtx.as_field(
(dims.CellDim,),
decomposition_info.owner_mask(dims.CellDim), # type: ignore[arg-type] # mypy not take the type of owner_mask
allocator=allocator,
),
owner_mask=geometry_field_source.get("cell_owner_mask"),
backend=backend_like,
)

Expand Down
1 change: 1 addition & 0 deletions model/common/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ io = [
"netcdf4>=1.6.1",
"numpy>=1.23.3",
"scikit-learn>=1.4.0",
"pymetis>2022.1",
# TODO(halungge): there are failing tests starting from uxarray==2024.4.0: when a data file does not have
# fields of a given dimension (eg 'edge') then something in uxarray goes wrong with the dimension
# mapping. It is not yet clear whether this is a uxarray bug or on our side.
Expand Down
82 changes: 82 additions & 0 deletions model/common/src/icon4py/model/common/decomposition/decomposer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# ICON4Py - ICON inspired code in Python and GT4Py
#
# Copyright (c) 2022-2024, ETH Zurich and MeteoSwiss
# All rights reserved.
#
# Please, refer to the LICENSE file in the root directory.
# SPDX-License-Identifier: BSD-3-Clause

from typing import Protocol, runtime_checkable

import gt4py.next as gtx

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


@runtime_checkable
class Decomposer(Protocol):
def __call__(
self, adjacency_matrix: data_alloc.NDArray, num_partitions: int
) -> data_alloc.NDArray:
"""
Call the decomposition.

Args:
adjacency_matrix: cell-to-cell connectivity matrix on the global (undecomposed) grid. In the Icon4py context this C2E2C
n_part: number of nodes
"""
...


class MetisDecomposer(Decomposer):
"""
A simple decomposer using METIS for partitioning a grid topology.

We use the simple pythonic interface to pymetis: just passing the adjacency matrix, which for ICON is
the full grid C2E2C neigbhor table.
if more control is needed (for example by using weights we need to switch to the C like interface)
https://documen.tician.de/pymetis/functionality.html
"""

def __call__(
self, adjacency_matrix: data_alloc.NDArray, num_partitions: int
) -> data_alloc.NDArray:
"""
Generate partition labels for this grid topology using METIS:
https://github.com/KarypisLab/METIS

This method utilizes the pymetis Python bindings:
https://github.com/inducer/pymetis

Args:
n_part: int, number of partitions to create
adjacency_matrix: nd array: neighbor table describing of the main dimension object to be distributed: for example cell -> cell neighbors
Returns: data_alloc.NDArray: array with partition label (int, rank number) for each cell
"""

import pymetis # type: ignore [import-untyped]

# Invalid indices are not allowed here. Metis will segfault or fail if
# there are any invalid indices in the adjacency matrix.
assert (adjacency_matrix >= 0).all()

# The partitioning is done on all ranks, and this assumes that the
# partitioning is deterministic.
_, partition_index = pymetis.part_graph(nparts=num_partitions, adjacency=adjacency_matrix)
return data_alloc.array_ns_from_array(adjacency_matrix).array(partition_index)


class SingleNodeDecomposer(Decomposer):
def __call__(
self, adjacency_matrix: data_alloc.NDArray, num_partitions: int
) -> data_alloc.NDArray:
"""Dummy decomposer for single node: assigns all cells to rank = 0"""
if num_partitions != 1:
raise ValueError(
f"SingleNodeDecomposer can only be used for num_partitions=1, but got {num_partitions}"
)

return data_alloc.array_ns_from_array(adjacency_matrix).zeros(
adjacency_matrix.shape[0],
dtype=gtx.int32, # type: ignore [attr-defined]
)
108 changes: 74 additions & 34 deletions model/common/src/icon4py/model/common/decomposition/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import gt4py.next as gtx
import numpy as np

from icon4py.model.common import utils
from icon4py.model.common import dimension as dims, utils
from icon4py.model.common.grid import base
from icon4py.model.common.orchestration.halo_exchange import DummyNestedSDFG
from icon4py.model.common.states import utils as state_utils
from icon4py.model.common.utils import data_allocation as data_alloc
Expand All @@ -35,6 +36,9 @@ class ProcessProperties(Protocol):
comm_name: str
comm_size: int

def is_single_rank(self) -> bool:
return self.comm_size == 1


@dataclasses.dataclass(frozen=True, init=False)
class SingleNodeProcessProperties(ProcessProperties):
Expand Down Expand Up @@ -71,41 +75,32 @@ def __call__(self) -> int:


class DecompositionInfo:
def __init__(
self,
) -> None:
self._global_index: dict[gtx.Dimension, data_alloc.NDArray] = {}
self._halo_levels: dict[gtx.Dimension, data_alloc.NDArray] = {}
self._owner_mask: dict[gtx.Dimension, data_alloc.NDArray] = {}

class EntryType(int, Enum):
ALL = 0
OWNED = 1
HALO = 2

@utils.chainable
def with_dimension(
self, dim: gtx.Dimension, global_index: data_alloc.NDArray, owner_mask: data_alloc.NDArray
def set_dimension(
self,
dim: gtx.Dimension,
global_index: data_alloc.NDArray,
owner_mask: data_alloc.NDArray,
halo_levels: data_alloc.NDArray,
) -> None:
self._global_index[dim] = global_index
self._owner_mask[dim] = owner_mask
self._halo_levels[dim] = halo_levels

def __init__(
self,
num_cells: int | None = None,
num_edges: int | None = None,
num_vertices: int | None = None,
):
self._global_index: dict[gtx.Dimension, data_alloc.NDArray] = {}
self._owner_mask: dict[gtx.Dimension, data_alloc.NDArray] = {}
self._num_vertices = num_vertices
self._num_cells = num_cells
self._num_edges = num_edges

@property
def num_cells(self) -> int | None:
return self._num_cells

@property
def num_edges(self) -> int | None:
return self._num_edges

@property
def num_vertices(self) -> int | None:
return self._num_vertices
def is_distributed(self) -> bool:
return max(self._halo_levels[dims.CellDim]).item() > DecompositionFlag.OWNED

def local_index(
self, dim: gtx.Dimension, entry_type: EntryType = EntryType.ALL
Expand All @@ -125,19 +120,15 @@ def local_index(
def _to_local_index(self, dim: gtx.Dimension) -> data_alloc.NDArray:
data = self._global_index[dim]
assert data.ndim == 1
if isinstance(data, np.ndarray):
import numpy as xp
else:
import cupy as xp # type: ignore[import-not-found, no-redef]

xp.arange(data.shape[0])
return xp.arange(data.shape[0])
return data_alloc.array_ns_from_array(data).arange(data.shape[0])

def owner_mask(self, dim: gtx.Dimension) -> data_alloc.NDArray:
return self._owner_mask[dim]

def global_index(
self, dim: gtx.Dimension, entry_type: EntryType = EntryType.ALL
self,
dim: gtx.Dimension,
entry_type: DecompositionInfo.EntryType = EntryType.ALL,
) -> data_alloc.NDArray:
match entry_type:
case DecompositionInfo.EntryType.ALL:
Expand All @@ -149,6 +140,24 @@ def global_index(
case _:
raise NotImplementedError()

def get_horizontal_size(self) -> base.HorizontalGridSize:
return base.HorizontalGridSize(
num_cells=self.global_index(dims.CellDim, self.EntryType.ALL).shape[0],
num_edges=self.global_index(dims.EdgeDim, self.EntryType.ALL).shape[0],
num_vertices=self.global_index(dims.VertexDim, self.EntryType.ALL).shape[0],
)

def get_halo_size(self, dim: gtx.Dimension, flag: DecompositionFlag) -> int:
level_mask = self.halo_level_mask(dim, flag)
return data_alloc.array_ns_from_array(level_mask).count_nonzero(level_mask)

def halo_levels(self, dim: gtx.Dimension) -> data_alloc.NDArray:
return self._halo_levels[dim]

def halo_level_mask(self, dim: gtx.Dimension, level: DecompositionFlag) -> data_alloc.NDArray:
levels = self._halo_levels[dim]
return data_alloc.array_ns_from_array(levels).where(levels == level.value, True, False)


class ExchangeResult(Protocol):
def wait(self) -> None: ...
Expand Down Expand Up @@ -414,5 +423,36 @@ def create_single_reduction_exchange(props: SingleNodeProcessProperties) -> Redu
return SingleNodeReductions()


class DecompositionFlag(int, Enum):
UNDEFINED = -1
OWNED = 0
"""used for locally owned cells, vertices, edges"""

FIRST_HALO_LEVEL = 1
"""
used for:
- cells that share 1 edge with an OWNED cell
- vertices that are on OWNED cell, but not owned
- edges that are on OWNED cell, but not owned
"""

SECOND_HALO_LEVEL = 2
"""
used for:
- cells that share one vertex with an OWNED cell
- vertices that are on a cell(FIRST_HALO_LINE) but not on an owned cell
- edges that have _exactly_ one vertex shared with and OWNED Cell
"""

THIRD_HALO_LEVEL = 3
"""
This type does not exist in ICON. It denotes the "closing/far" edges of the SECOND_HALO_LINE cells
used for:
- cells (NOT USED)
- vertices (NOT USED)
- edges that are only on the cell(SECOND_HALO_LINE)
"""


single_node_default = SingleNodeExchange()
single_node_reductions = SingleNodeReductions()
Loading
Loading