Repository navigation
feat[next]: NeighborConnectivity[Domain, Codomain] declarations, NeighborTableType, and shared local dimensions on every backend - #2907
Draft
egparedes wants to merge 24 commits into
Conversation
This was referenced Sep 21, 2026
egparedes
force-pushed
the
connectivities-as-types-3-neighbor-connectivity
branch
from
September 23, 2026 16:09
d1e1aeb to
8c55110
Compare
egparedes
force-pushed
the
connectivities-as-types-3-neighbor-connectivity
branch
2 times, most recently
from
September 24, 2026 10:12
bf5c950 to
90252b3
Compare
This was referenced Sep 24, 2026
havogt
reviewed
Sep 25, 2026
| /, | ||
| *, | ||
| max_neighbors: Optional[int] = None, | ||
| min_neighbors: Optional[int] = None, |
Contributor
There was a problem hiding this comment.
Why not has_skip_values. Feels like the better concept, because there might not be a natural minimum (e.g. if you use it to express missing values close to the boundary).
…at know their owner
- check_neighbor_table: min_neighbors exceeding the table, bool tables - descriptive errors for non-integer indices, the undeclared base, DSL attributes - FieldOffset.Local, so the spelling works for legacy offsets in embedded too - fingerprint a declaration by its dimensions and counts, not only its name - negative counts are a ValueError
…mension Flattened sparse patterns (ICON4Py's C2CE, E2ECV, ...) index the same neighbor axis as another connectivity. A declaration can now adopt an owned local dimension; it is then named in the IR by its own tag (offset_tag), since the local dimension's tag already names the owner's table.
An annotated 'Local' -- on 'NeighborConnectivity' or on its metaclass -- makes every declaration's local dimension a *variable*: pyright then rejects 'Field[Dims[V, V2E.Local], float]', and mypy rejects an adopted or shared one. Annotate it nowhere; library code reads it through 'common.local_dimension_of', and adoption and sharing are written 'Local: TypeAlias = ...'. Also from the review: a redefined declaration re-owns an adopted local dimension instead of becoming a sharer, and its counts are checked against the local dimension's own 'size='. The missing-'Local' error names both spellings. Adds pyright over 'typing_tests/pyright_probes.py' to the typing session, which is what catches a regression here: the mypy cases cannot.
Now that local dimensions can state their size, the local dimension of 'make_const_list' results is one; a declaration cannot adopt it, since it belongs to no connectivity.
Reductions, sparse arguments and list materialization used to find a connectivity by the local dimension's tag, which only names the owner's table. They now look up a table over the local dimension (common.connectivity_key_over), so a connectivity sharing another one's local dimension works on every backend, bound on its own or together with its owner. DaCe sizes a connectivity array's local dimension from its own table. Lifts the PR 1 xfail markers.
- DaCe if/scan/concat_where/const-list sites find the table over the local dimension - connectivity_key_over takes a tag, avoids resolve, and picks deterministically - embedded map_list compares lists by local dimension, not by offset - a sharer must have its owner's origin; counts are compared one by one - ADR 0029: sharers must have the owner's neighbor structure
…Type and ts.ShiftType
- 'NeighborConnectivity[Origin, Codomain]' becomes '[Domain, Codomain]', and
the class attribute 'origin' becomes 'domain': a bound table is a field over
(Domain, Local) with values in Codomain. 'origin' already names a buffer
origin ('__gt_origin__').
- 'NeighborConnectivityType' becomes 'NeighborTableType': the declaration the
table is bound to, dtype, skip value and max_neighbors, with domain and
codomain derived from the declaration. It is built from the offset-provider
key ('offset_provider_to_type', 'check_neighbor_table', which now returns
it), since a sharer's table looks like its owner's; local dimensions record
their sharers for that. A table under a key no declaration answers to keeps
its structural 'ConnectivityType', which is also what
'NeighborTable.__gt_type__()' returns now. 'OffsetProviderType' becomes
'TableTypes'.
- 'ts.OffsetType(source, target)' becomes 'ts.ShiftType(codomain, domain)',
printed 'Shift[<tag>: <codomain> -> <domain>]'.
- ADR 0029 describes the result; ADR 0019 names the new record.
ADR 0028 on main is now 'Plain Builders Instead of factory-boy Factories' (#2808), so the two ADRs of this stack move up by one.
A dimension is local if and only if it subclasses `LocalDimensionIndex` (`common.is_local_dimension`), so `DimensionKind` loses its `LOCAL` member and is `HORIZONTAL | VERTICAL`. A local dimension's `kind` is `None`, and declaring one with `kind=` is a `TypeError`; `None` rather than `HORIZONTAL` keeps every backend comparison against `HORIZONTAL` / `VERTICAL` meaning what it meant. `order_dimensions` sorts by an explicit rank (horizontal, local, vertical), so sparse-field layouts do not move. Displays derive the label from the class: `Local[local]`, the `ₗ` IR suffix and DaCe's `_gtx_localdim` map variables are unchanged. The tree's `DimensionIndex(kind=LOCAL)` declarations become owner-less `LocalDimensionIndex` subclasses. pyright probes pin the Cartesian axis levels of ADR 0029, including staggering and shifting a local dimension, with `reportUnnecessaryTypeIgnoreComment` so a rejection that stops firing fails the session. ADR 0030 records the change.
egparedes
force-pushed
the
connectivities-as-types-3-neighbor-connectivity
branch
from
October 2, 2026 02:14
90252b3 to
e565d9c
Compare
…ctivities-as-types-3-neighbor-connectivity Takes #2899's tree as is: #2899 now compares, hashes and pickles dimension classes by their ref and keeps DimensionKind.LOCAL, which the old implementation of this branch contradicts. Its features are ported again on top of this merge, in the following commits.
NeighborConnectivityType becomes NeighborTableType, OffsetProviderType becomes TableTypes (is_offset_provider_type becomes is_table_types, OffsetProviderTypeElem is dropped), and ts.OffsetType(source, target) becomes ts.ShiftType(codomain, domain), printed 'Shift[<tag>: <codomain> -> <domain>]'. The source_dim and neighbor_dim properties give way to domain[0] and domain[1].
…lasses Add `NeighborConnectivity[Domain, Codomain]` declarations with a nested `Local` dimension, `LocalDimensionIndex`, the immutable `ConnectivityRef` that stands for a declaration below the frontend, and `check_neighbor_table` to bind a table to its declaration. A declaration owns its local dimension when `Local` is nested in it and is then named in the IR by the local dimension's tag; one that shares or adopts a local dimension is named by its own tag. `offset_provider_to_type` binds tables to the declarations the program references; elsewhere a table keeps its structural type. Declarations compare, hash, pickle and fingerprint by their ref.
Reductions, sparse arguments and list materialization used to find a table by the local dimension's tag, which only names the table of the connectivity declaring it. They now take a table over the local dimension (`common.connectivity_key_over`), so a connectivity sharing another one's local dimension works on every backend, bound on its own or together with the other one. DaCe sizes a field's local dimension from such a table. Lifts the `uses_offset_tag_differing_from_local_dim*` markers, which every backend now passes.
The two checkers disagree about what counts as a type: an annotated `Local` would make a declaration's local dimension a variable for pyright. Probes in `typing_tests/pyright_probes.py` run under pyright in `test_typing_exports`, and the mypy cases in `test_next.yaml` cover declarations too.
Records the `NeighborConnectivity` declarations: data on the connectivity and its ref, owner and sharers by nesting, tables bound to the declarations a program references, and structural table types below the frontend.
…or structure Reductions and sparse fields take the neighbor count and skip values from any table over their local dimension, so a sharer's table with another count or skip flag than its owner's silently gave wrong results. `check_shared_local_dimensions` rejects that structurally, without declarations: `offset_provider_to_type` checks every local dimension, and `connectivity_key_over` the one it looks up, which is how embedded execution notices. UnrollReduce takes the table of a `neighbors` argument from its own offset.
`a(mesh.V2E)` names a declaration that is not a closure variable, so its table was never checked. The declarations a program references now also include those its field operators reach through an attribute of a module or another namespace.
ADR 0031 said that a declaration pickles by its ref, but it has no reducer: it is pickled by reference, like any class, so a declaration that has since been redefined cannot be pickled. The toolchain carries refs, which pickle by value. Say so, and test it.
- A `LocalDimensionIndex` subclass cannot set another kind in its body. - `V2E[i]` outside embedded execution raises a clear error instead of an assertion, as does `FieldOffset[i]`. - A structural `NeighborTableType` must have a two-dimensional domain, and its dtype and skip value must agree with its structure. - `test_local_dimension_size` uses different counts, so that it tells its branches apart.
…ctivities-as-types-3-neighbor-connectivity
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #2899 (native stack #3089). Design: ADR 0031 in this PR.
This is a new implementation of the PR on top of the current #2899, where dimension classes compare, hash and pickle by their
DimensionRef. The merge commit takes #2899's tree as is, and the commits after it port this PR's features again. The earlier implementation is still in the history before that merge.What
A neighbor connectivity can be declared as a class, with its local dimension nested in it:
Additive for user code:
FieldOffsetand string-keyed offset providers keep working; #2910 removes them. The following public names are renamed without aliases:NeighborConnectivityType→NeighborTableType,OffsetProviderType→TableTypes,is_offset_provider_type→is_table_types,ts.OffsetType(source, target)→ts.ShiftType(codomain, domain, tag).NeighborConnectivity(metaclassConnectivityMeta) carries the domain, codomain, local dimension and the optionalmax_neighbors/min_neighbors. Below the frontend these travel as an immutableConnectivityRef. Declarations compare, hash and are fingerprinted by that ref, like dimensions (ADR 0030). A local dimension stays a plain dimension class: a class rebuilt from its ref would lose anything stored on it.LocalDimensionIndexis a dimension of kindLOCAL.DimensionKind.LOCALstays, and a dimension is local if its kind isLOCAL, also for refs and synthesized classes.Localnested in its own body. It is named in the IR by the local dimension's tag (offset_tag). A declaration that shares another one's local dimension (Local: typing.TypeAlias = C2E.Local, as ICON4Py'sC2CEneeds) is named by its own tag.check_neighbor_tablechecks a table against a declaration (domain, codomain, integral dtype, counts, skip values). A program checks its tables against the declarations it references, also through a module (mesh.V2E). Tables over one local dimension must have the same domain, count and skip-value flag, on every backend, embedded included.NeighborTableTypeholds theConnectivityRefof the declaration a table is bound to, or the table's structuralConnectivityTypewhen it has none (hand-written IR,FieldOffset).connectivity_key_over(provider, local_dim)finds a table over a local dimension (the owner's, else a sharer's), so shared local dimensions work on embedded, roundtrip, gtfn, iterator embedded and DaCe. DaCe sizes a connectivity array from its own table (local_dimension_size). Theuses_offset_tag_differing_from_local_dim*markers are removed.Localis annotated nowhere, soField[Dims[V, V2E.Local], float]type-checks under both mypy and pyright. pyright now runs in the typing session overtyping_tests/pyright_probes.py.Not in this PR
ConnectivityRefs.Verification
Local, CPU, Python 3.12. Before the merge of #2899's docs-only
0daf07ea2:unit_tests: 3136 passed. Feature, iterator and regression tests plus the toy-connectivity tests: 3471 passed, 0 failed.integration_testsandregression_tests, notrequires_gpu, 4 workers);commondoctests 14 passed.tach checkand pre-commit on the changed files: clean.🤖 Written by an agent on my behalf.