Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ statically meaningful.

**`(name, kind)` value equality with an interning registry** (the design of
[[shared/dimensions-as-types|dimensions as types]] and GridTools/gt4py#2844).
Keeps independently declared same-named dimensions interchangeable and
avoids the importability rule. Rejected because it decouples the Python
type's identity from the IR's, needs a registry plus `copyreg` plus a custom
fingerprint deconstructor to paper over that gap, and cannot give a nested
Keeps independently declared same-named dimensions interchangeable.
Rejected because same-named dimensions from two modules become one, it needs a
name-keyed registry, and it cannot give a nested
`V2E.Local` a unique name without further convention. See [[personal/egparedes/connectivities-as-types/connectivities-as-types#identity-is-the-qualified-python-name|Identity]].

**Integer type parameters for `max_neighbors`** (`LocalDimensionIndex[F: int, M: int]`).
Expand All @@ -52,6 +51,12 @@ because skip-value presence is configuration-dependent in ICON, so a static
`min_neighbors` forces either duplicate classes or always-on skip handling.
Declared counts stay available as a constraint; see [[personal/egparedes/connectivities-as-types/connectivities-as-types#binding-model|Binding model]].

**Owner-less local axes as non-LOCAL dimensions.** Rejected: they would
**Owner, sharers and counts on the local dimension** (`Local.owner`,
`Local.sharers`, `LocalDimensionIndex(size=3)`), written when a declaration is
created. It lets a declaration check its sharers on the spot, but makes a local
dimension mutable state that a re-run notebook cell has to re-own, and puts data on
a dimension that a synthesized stand-in (ADR 0030) cannot carry (ADR 0031).

**Local axes declared on their own as non-LOCAL dimensions.** Rejected: they would
become domain dimensions with a range in every program domain and lose the
sparse storage treatment, changing ICON4Py's layout for `LsqUnkDim` fields.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ enumerates as 2ⁿ location names, and it does not stop at three axes.
| Convention feature | This design | Verdict |
| --- | --- | --- |
| Connectivities named by entity pair (`face_node_connectivity`) | `NeighborConnectivity[Domain, Codomain]` — `face_node_connectivity` ≡ `NeighborConnectivity[Face, Node]` | isomorphic. The `Domain`/`Codomain` naming matches UGRID's reading direction, where `source`/`target` did not |
| `_FillValue` required wherever an entry may be absent — ragged valence, but also a missing boundary neighbour in `edge_face_connectivity` / `face_face_connectivity`; `nMaxMesh2_face_nodes` | `skip_value` and `max_neighbors` on `NeighborTableType`, and the optional `min_neighbors` on the declaration's `Local` | strictly more informative. ICON's icosahedron carries 12 pentagons among hexagons, so `V2E` is `min_neighbors=5, max_neighbors=6`; UGRID can only record max 6 plus fill. That is the sketch's example verbatim |
| `_FillValue` required wherever an entry may be absent — ragged valence, but also a missing boundary neighbour in `edge_face_connectivity` / `face_face_connectivity`; `nMaxMesh2_face_nodes` | `skip_value` and `max_neighbors` on `NeighborTableType`, and the optional `min_neighbors` on the declaration | strictly more informative. ICON's icosahedron carries 12 pentagons among hexagons, so `V2E` is `min_neighbors=5, max_neighbors=6`; UGRID can only record max 6 plus fill. That is the sketch's example verbatim |
| `vertical_dimensions` uses **the same** padding syntax as `face_dimensions` | — | the vertical is just another axis pair. SGRID needs no "vertical kind", which supports the conclusion that `DimensionKind.VERTICAL` is a layout and scan artefact, not geometry (main note, open question 6) |
| `face_dimensions` specifies a padding **per axis** | a per-axis alignment, never grid-wide | supports the shape of the alignment follow-up (open question 5): a class keyword on the axis |
| 3D topology forbidden for layered grids; use 2D + `vertical_dimensions` | horizontal topology plus a separate vertical axis | validates the existing split |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ proved.
| --- | --- | --- |
| `Vert<g>` — index type of a mesh entity | `Dimension("Vertex")`, identity by `(value, kind)` | the class `V(DimensionIndex)`; identity is the class (a **brand**, §7) |
| `Fin<degree(g, v)>` — local slot, depends on `g` *and* `v` | `V2EDim = Dimension("V2E", LOCAL)`, a free name | `V2E.Local`: depends on the **declaration** `V2E` (nominally, by nesting), not on `g` or `v` |
| `degree(g, v)` bounded by the padded row length | `max_neighbors` on the table's type | `max_neighbors` / `min_neighbors`: optional class keywords stored on `V2E.Local`, else taken from the table |
| `degree(g, v)` bounded by the padded row length | `max_neighbors` on the table's type | `max_neighbors` / `min_neighbors`: optional class keywords on the declaration (its `ConnectivityRef`), else taken from the table |
| `Option`-valued slots of a padded ragged row | `skip_value` (−1) in the table | same; if `min_neighbors` is declared, skip values must be present iff `min_neighbors < max_neighbors` |
| `NeighborOrder<g>` — the enumeration | a `NeighborTable` / `NdArrayConnectivityField` | unchanged: the table *is* the enumeration and, in §6's inverted presentation, the graph |
| `(v : Vert<g>) -> Fin<degree(g, v)> -> double` — slot-addressed field | `Field[Dims[V, V2EDim], float]` | `Field[Dims[V, V2E.Local], float]` |
Expand Down Expand Up @@ -366,13 +366,14 @@ relaxation of "one table per declaration per binding context". `C2CE` (cell →
`C2E.Local` so that its results combine with `C2E`-shaped sparse fields.
Sharing a slot type across two connectivities is only sound if both tables
enumerate each cell's fiber in the same order and pad it in the same places.
The type checker cannot see this; the bind-time check (`check_offset_provider`)
requires tables over one shared local dimension to have the same width and
skip-value presence and — where a program is compiled — skip values at the
same positions, and reductions over the shared axis take that structure from any
bound table over it. Note what this does *not* check: that the two tables list
each cell's neighbors in the same *order* — §6's bijection — which is again a
property of the mesh generator.
The type checker cannot see this; the bind-time check
(`check_shared_local_dimensions`, run by `offset_provider_to_type` and
`connectivity_key_over`) requires tables over one shared local dimension to have
the same domain, width and skip-value presence, and reductions over the shared axis
take that structure from any bound table over it. Note what this does *not* check:
where the skip values are, and that the two tables list each cell's neighbors in
the same *order* — §6's bijection — which are again properties of the mesh
generator (ADR 0031 leaves them to the user).

### Evidence lifetime

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,57 @@ status: draft

> **Appendix** to [[personal/egparedes/connectivities-as-types/connectivities-as-types|Connectivities as types]].
> The mechanics behind rules 1 and 3-6 of *Identity is the qualified Python name*:
> reconstruction by import, the one `copyreg` hook, fingerprinting, the injective
> `DimensionRef`, pickling as a ref, fingerprinting, the injective
> codegen mangling, and the `Staggered[D]` tag grammar.

## Rule 1 — reconstruction from the IR is an import
## Rule 1 — two levels

1. **Reconstruction from the IR is an import.** `resolve(tag)` imports the
longest importable module prefix and walks the rest as attributes (nested
classes like `V2E.Local` resolve naturally), the way `pickle` references a
class. Only where the module path ends is memoized: the attribute walk is
repeated, so a declaration redefined under the same name (a re-run
notebook cell) resolves to the new class. `AxisLiteral` stores only the tag
and derives `kind` and `dim` from it as read-only properties (the `TODO` at
`iterator/ir.py:93`); the derived `kind` is optional, since a local
dimension's is `None`;
printing IR never imports (`resolve_loaded`). `Staggered[D]` tags use the
small grammar `<owner tag>[<base tag>]`, resolved by subscripting the owner.
1. **Nothing is imported from a tag.** `DimensionRef(module, qualname, kind,
is_cartesian_axis, base)` is frozen, interned and pickled by value. Comparing a ref
with a dimension class raises `TypeError`, since one side missed its conversion;
hash-based lookups cannot be checked and are misses. `AxisLiteral` stores the ref.
`DimensionRef.from_tag(tag, kind, is_cartesian_axis=...)` rebuilds one from text:
the pretty printer prints short names plus a header with each dimension's tag, kind
and axis flag, from which the parser rebuilds the refs. The roundtrip backend, which
runs on classes, declares each dimension in its generated source with
`common.synthesize_dimension(DimensionRef(...))`, a class equal to the original.
`Staggered[D]` tags use the small grammar `<owner tag>[<base tag>]`.

## Rules 3-6 — registry, fingerprints, mangling, staggering

3. **No registry.** Classes pickle by reference. One narrow `copyreg` hook
exists, for `Staggered[D]`, whose bracketed qualname `save_global` cannot
look up; it reduces to the base dimension and re-interns.
4. **Fingerprints depend on qualified names, plus `kind`.** A dimension is
deconstructed as its by-reference name *and* its declaration-time `kind`, which
decides a field's layout order and the scan axis — so a dimension redefined under
the same name with another kind does *not* reuse artifacts. `Staggered[D]` goes
3. **No registry.** A `copyreg` reduction on both dimension metaclasses pickles every
dimension class, `Staggered[D]` included, as its `DimensionRef`; loading returns the
loaded class with that ref (a `sys.modules` lookup, no import), else
`synthesize_dimension(ref)`. By-value picklers such as `cloudpickle` bypass it and
cannot rebuild a dimension.
4. **Fingerprints are the `DimensionRef`.** A dimension is deconstructed as its ref
only, so a synthesized stand-in fingerprints like the class. The ref has the `kind`, which
decides a field's layout order and the scan axis, and the axis level
(`CartesianAxisIndex` versus `DimensionIndex`), on which index arithmetic depends —
so a dimension redefined under the same name with another of either does *not* reuse
cached stages or artifacts. `Staggered[D]` goes
through its base and inherits this; its base cannot be flipped in place, since
the class is interned by base identity and its tag embeds the base tag. The axis
level (`CartesianAxisIndex` versus `DimensionIndex`) is deliberately *not*
fingerprinted: it changes what is accepted, never what is emitted. A connectivity
declaration is fingerprinted *additionally* by its domain, codomain, `Local` and
counts. Consequently the ADR 0023 build cache invalidates on module renames.
the class is built from its base and its tag embeds the base tag. A connectivity
declaration is fingerprinted by its `ConnectivityRef`: qualified name, the refs of
its domain, codomain and local dimension, and its counts. Consequently the ADR 0023 build cache invalidates on module renames.
5. **Codegen names need injective mangling.** `codegen_name(tag)` is a prefix
escape — `_`→`_u`, `.`→`_d`, `[`→`_l`, `]`→`_r` — used by gtfn, DaCe, the
roundtrip backend and the nanobind bindings; its inverse
`from_codegen_name` is used by DaCe to parse names back. The simpler
escape — `_`→`_u`, `.`→`_d`, `:`→`_c`, `[`→`_l`, `]`→`_r` — used by gtfn, DaCe, the
roundtrip backend and the nanobind bindings. There is no inverse: DaCe gets the
provider keys of its connectivities passed in. The simpler
"escape `__`, then replace `.`" is **not** injective (`".."` and `"_"`
collide); the prefix escape is tested exhaustively over its alphabet up
to length 4.
6. **Staggering is part of the dimension change.** The `_Staggered` name
prefix needs the name→class lookup that type identity removes, so
`Staggered[D]` is a real class and part of ADR 0029 (PR A), together with
prefix needs a name→class lookup that qualified-name identity removes, so
`Staggered[D]` is a real class and part of ADR 0030 (PR A), together with
the [[personal/egparedes/connectivities-as-types/connectivities-as-types#cartesian-axis-dimensions|Cartesian axis dimensions]] its parameter is bounded on; see
[[personal/egparedes/connectivities-as-types/connectivities-as-types#staggeredd|`Staggered[D]`]].

## The `Staggered[D]` tag

- **IR and serialization.** The tag is
`gt4py.next.common.Staggered[<base tag>]` — the one tag that is not a
qualified name. `resolve` parses the `<owner>[<base>]` grammar and
subscripts the owner, the IR pretty-parser accepts it, and `codegen_name`
escapes the brackets. `pickle` cannot look up a bracketed qualname, so one
`copyreg` hook reduces a staggered class to its base and re-subscripts on
load; fingerprints are likewise taken through the base.
`gt4py.next.common.dimensions:Staggered[<base tag>]` — the one tag that is not a
qualified name. `DimensionRef.from_tag` parses the `<owner>[<base>]` grammar
without importing the base, the IR pretty-parser accepts it, and `codegen_name`
escapes the brackets. Pickling goes through the ref, whose `base` rebuilds the
partner on load; fingerprints are likewise taken through the base.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ npx -y @marp-team/marp-cli@4 --no-stdin \

One declaration for offset, local dimension and provider key

ADR 0029 (dimensions) · ADR 0030 (connectivities)
ADR 0030 (dimensions) · ADR 0031 (connectivities)

> **Appendix** to [Connectivities as types](connectivities-as-types), summarising the note it is published alongside; where the two disagree the note is authoritative. Every slide links the section it compresses, and the deck adds no facts of its own. Rendering instructions are on the slide before this one.

Expand Down Expand Up @@ -81,12 +81,13 @@ The class *contains* its local dimension and *is* its own provider key. Nothing

## Identity is the qualified Python name

`tag = f"{cls.__module__}.{cls.__qualname__}"`
`tag = f"{cls.__module__}:{cls.__qualname__}"`

- the static view (nominal types) and the runtime view (`is`) agree by construction
- reconstruction from the IR is an **import**, the way `pickle` references a class
- so `<locals>` dimensions are rejected, and a redefinition is a *different* connectivity
- the IR names a connectivity by its `offset_tag` = its local dimension's tag, so shifts, reductions and sparse arguments find one table under **one** string
- dimension classes with equal `DimensionRef`s are the same dimension: a re-run cell is no new dimension
- below the frontend a dimension is a **`DimensionRef` value**: nothing is imported from a tag
- a dimension pickles as its ref, so notebook dimensions reach compile workers; `<locals>` dimensions are rejected
- a connectivity compares by its `ConnectivityRef`: re-run unchanged it is the same connectivity, with other dimensions or counts a different one
- the IR names a connectivity by its `offset_tag` = the tag of its nested `Local` (a sharer: its own tag), so shifts, reductions and sparse arguments find one table under **one** string

→ [Identity](connectivities-as-types#identity-is-the-qualified-python-name)

Expand Down Expand Up @@ -152,7 +153,7 @@ In *n* dimensions the grid is the product complex, so `Dims[...]` is one stagger

## What it deletes

`FieldOffset` · bare-name provider keys · the `_Staggered` name prefix · `_CONST_DIM` as a magic name · `SparseTag` · `NamedIndex` · the dimension half of the mypy plugin · `DimensionKind.LOCAL` · the `V2EDim`-next-to-`V2E` convention
`FieldOffset` · bare-name provider keys · the `_Staggered` name prefix · `_CONST_DIM` as a magic name · `SparseTag` · `NamedIndex` · the dimension half of the mypy plugin · the `V2EDim`-next-to-`V2E` convention

Of ten cross-object identity constraints: **six dissolve**, three collapse into one bind-time check, one remains.

Expand All @@ -164,8 +165,9 @@ Of ten cross-object identity constraints: **six dissolve**, three collapse into

| PR | Contents |
| --- | --- |
| A #2899 | dimensions as classes, `Staggered[D]`, ADR 0029 |
| B #2907 | `NeighborConnectivity`, `LocalDimensionIndex`, ADR 0030 |
| #3087, #3088 | preparations, `NamedRange` → `DimensionRange` |
| A #2899 | dimensions as classes, `DimensionRef`, `Staggered[D]`, ADR 0030 |
| B #2907 | `NeighborConnectivity`, `ConnectivityRef`, `LocalDimensionIndex` (kind `LOCAL` stays), shared local dimensions, ADR 0031 |
| C #2910 | class-keyed providers, `FieldOffset` removed, migration script |
| D #2912 | `MultiDimensionIndex`, typed embedded positions |

Expand Down
Loading