Repository navigation
Conversation
2881fa4 to
a127841
Compare
|
I like the approach much more than the one in #2844. Maybe we can avoid the biggest downside, the many changes everywhere and the long names, by just defining a common set of dimensions in some module and avoiding the long name for them. |
d38784e to
91e24e2
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Interactive dimension resolution can retain stale classes, and the fallback scan performs avoidable connectivity-file I/O.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 2
Open (3)
What changed in this PR
Makes gt4py.next dimensions nominal Python classes, with qualified-name tags used across IR, code generation, serialization, and backends.
Changes:
- Introduces
DimensionIndex, nominal identity, resolution, mangling, and staggered dimensions. - Migrates frontend, iterator, DaCe, GTFN, embedded execution, docs, and examples.
- Updates tests and adds interactive compilation fallback coverage.
| File | Description |
|---|---|
docs/development/ADRs/next/0026-Staggered_Dimensions.md |
Updates staggered encoding. |
docs/development/ADRs/next/0028-Dimensions_As_Nominal_Types.md |
Records the architecture. |
docs/development/ADRs/next/README.md |
Lists ADR 0028. |
docs/user/next/QuickstartGuide.md |
Migrates dimension examples. |
docs/user/next/workshop/exercises/1_simple_addition.ipynb |
Migrates notebook dimensions. |
docs/user/next/workshop/exercises/1_simple_addition_solution.ipynb |
Migrates solution dimensions. |
docs/user/next/workshop/exercises/helpers.py |
Migrates workshop helpers. |
docs/user/next/workshop/slides/slides_1.ipynb |
Migrates slide examples. |
docs/user/next/workshop/slides/slides_2.ipynb |
Migrates connectivity examples. |
docs/user/next/workshop/slides/slides_3.ipynb |
Migrates slide dimensions. |
docs/user/next/workshop/slides/slides_4.ipynb |
Migrates slide dimensions. |
examples/lap_cartesian_vs_next.ipynb |
Migrates example dimensions. |
src/gt4py/next/__init__.py |
Exports the new API. |
src/gt4py/next/common.py |
Implements nominal dimensions. |
src/gt4py/next/constructors.py |
Accepts dimension classes. |
src/gt4py/next/custom_layout_allocators.py |
Uses typed dimension indices. |
src/gt4py/next/embedded/common.py |
Migrates indexing helpers. |
src/gt4py/next/embedded/nd_array_field.py |
Migrates field indexing. |
src/gt4py/next/embedded/operators.py |
Migrates scan positions. |
src/gt4py/next/ffront/decorator.py |
Updates scan documentation. |
src/gt4py/next/ffront/fbuiltins.py |
Constructs nominal indices. |
src/gt4py/next/ffront/foast_passes/type_deduction.py |
Updates dimension diagnostics. |
src/gt4py/next/ffront/foast_pretty_printer.py |
Updates examples. |
src/gt4py/next/ffront/foast_to_gtir.py |
Emits qualified tags. |
src/gt4py/next/ffront/foast_to_past.py |
Updates examples. |
src/gt4py/next/ffront/func_to_foast.py |
Updates examples. |
src/gt4py/next/ffront/func_to_past.py |
Updates examples. |
src/gt4py/next/ffront/past_to_itir.py |
Lowers qualified dimensions. |
src/gt4py/next/ffront/transform_utils.py |
Detects dimension metaclasses. |
src/gt4py/next/ffront/type_info.py |
Adds unknown-dimension placeholder. |
src/gt4py/next/field_utils.py |
Updates field examples. |
src/gt4py/next/fingerprinting.py |
Fingerprints staggered classes. |
src/gt4py/next/iterator/embedded.py |
Uses shared ConstList. |
src/gt4py/next/iterator/ir.py |
Derives axis dimensions from tags. |
src/gt4py/next/iterator/ir_utils/domain_utils.py |
Resolves axis tags. |
src/gt4py/next/iterator/ir_utils/ir_makers.py |
Emits tagged axes. |
src/gt4py/next/iterator/ir_utils/misc.py |
Resolves axis literals. |
src/gt4py/next/iterator/pretty_parser.py |
Parses qualified tags. |
src/gt4py/next/iterator/pretty_printer.py |
Prints derived axis kinds. |
src/gt4py/next/iterator/tracing.py |
Traces dimension classes. |
src/gt4py/next/iterator/transforms/fuse_as_fieldop.py |
Updates doctests. |
src/gt4py/next/iterator/transforms/inline_fundefs.py |
Updates doctests. |
src/gt4py/next/iterator/transforms/pass_manager.py |
Uses qualified dimension keys. |
src/gt4py/next/iterator/transforms/prune_empty_concat_where.py |
Updates doctests. |
src/gt4py/next/iterator/transforms/remove_broadcast.py |
Updates doctests. |
src/gt4py/next/iterator/transforms/replace_get_domain_range_with_constants.py |
Matches dimensions by tag. |
src/gt4py/next/iterator/transforms/unroll_reduce.py |
Uses local-dimension tags. |
src/gt4py/next/iterator/type_system/inference.py |
Resolves axis dimensions. |
src/gt4py/next/iterator/type_system/type_synthesizer.py |
Migrates inferred dimensions. |
src/gt4py/next/otf/binding/nanobind.py |
Mangles binding dimensions. |
src/gt4py/next/otf/compilation_tasks.py |
Preserves dimension providers. |
src/gt4py/next/otf/runners.py |
Adds interactive fallback. |
src/gt4py/next/program_processors/codegens/gtfn/codegen.py |
Mangles generated tags. |
src/gt4py/next/program_processors/codegens/gtfn/gtfn_module.py |
Migrates connectivity tags. |
src/gt4py/next/program_processors/codegens/gtfn/itir_to_gtfn_ir.py |
Declares qualified tag types. |
src/gt4py/next/program_processors/runners/dace/lowering/gtir_python_codegen.py |
Mangles DaCe symbols. |
src/gt4py/next/program_processors/runners/dace/lowering/gtir_to_sdfg.py |
Uses local tags. |
src/gt4py/next/program_processors/runners/dace/lowering/gtir_to_sdfg_concat_where.py |
Resolves local providers. |
src/gt4py/next/program_processors/runners/dace/lowering/gtir_to_sdfg_lambda.py |
Uses nominal local dimensions. |
src/gt4py/next/program_processors/runners/dace/lowering/gtir_to_sdfg_primitives.py |
Uses local tags. |
src/gt4py/next/program_processors/runners/dace/lowering/gtir_to_sdfg_scan.py |
Uses local tags. |
src/gt4py/next/program_processors/runners/dace/lowering/gtir_to_sdfg_utils.py |
Mangles map variables. |
src/gt4py/next/program_processors/runners/dace/sdfg_args.py |
Mangles SDFG arguments. |
src/gt4py/next/program_processors/runners/dace/transformations/loop_blocking.py |
Accepts dimension classes. |
src/gt4py/next/program_processors/runners/dace/transformations/map_orderer.py |
Accepts dimension classes. |
src/gt4py/next/program_processors/runners/dace/workflow/bindings.py |
Unmangles provider keys. |
src/gt4py/next/program_processors/runners/roundtrip.py |
Resolves generated dimensions. |
src/gt4py/next/type_system/mypy_plugin.py |
Removes dimension hooks. |
src/gt4py/next/type_system/type_info.py |
Updates dimension diagnostics. |
src/gt4py/next/type_system/type_specifications.py |
Displays class dimensions. |
src/gt4py/next/type_system/type_translation.py |
Recognizes dimension classes. |
tests/next_tests/artifacts/custom_named_collections.py |
Migrates fixture dimensions. |
tests/next_tests/benchmarks/benchmark_program_call.py |
Migrates benchmark dimensions. |
tests/next_tests/fixtures/past_common.py |
Reuses canonical dimensions. |
tests/next_tests/integration_tests/cases_utils.py |
Centralizes test dimensions. |
tests/next_tests/integration_tests/feature_tests/dace_tests/test_orchestration.py |
Updates mangled connectivity arguments. |
tests/next_tests/integration_tests/feature_tests/dace_tests/test_write_back_buffer_elimination_lowering.py |
Migrates connectivity declarations. |
tests/next_tests/integration_tests/feature_tests/ffront_tests/test_concat_where.py |
Uses qualified provider keys. |
tests/next_tests/integration_tests/feature_tests/ffront_tests/test_external_local_field.py |
Uses qualified provider keys. |
tests/next_tests/integration_tests/feature_tests/ffront_tests/test_foast_pretty_printer.py |
Migrates dimensions. |
tests/next_tests/integration_tests/feature_tests/ffront_tests/test_import_from_mod.py |
Uses qualified provider keys. |
tests/next_tests/integration_tests/feature_tests/ffront_tests/test_named_collections.py |
Uses qualified provider keys. |
tests/next_tests/integration_tests/feature_tests/ffront_tests/test_reductions.py |
Migrates reduction coverage. |
tests/next_tests/integration_tests/feature_tests/ffront_tests/test_staggered.py |
Updates staggered coverage. |
tests/next_tests/integration_tests/feature_tests/ffront_tests/test_temporaries_with_sizes.py |
Uses qualified symbolic sizes. |
tests/next_tests/integration_tests/feature_tests/ffront_tests/test_tuples.py |
Uses qualified provider keys. |
tests/next_tests/integration_tests/feature_tests/ffront_tests/test_type_conversion.py |
Uses qualified provider keys. |
tests/next_tests/integration_tests/feature_tests/instrumentation_tests/test_hooks.py |
Migrates dimensions. |
tests/next_tests/integration_tests/feature_tests/iterator_tests/test_builtins.py |
Migrates local dimensions. |
tests/next_tests/integration_tests/feature_tests/iterator_tests/test_conditional.py |
Migrates dimensions. |
tests/next_tests/integration_tests/feature_tests/iterator_tests/test_implicit_fencil.py |
Migrates dimensions. |
tests/next_tests/integration_tests/feature_tests/iterator_tests/test_program.py |
Migrates dimensions. |
tests/next_tests/integration_tests/feature_tests/iterator_tests/test_strided_offset_provider.py |
Migrates connectivity dimensions. |
tests/next_tests/integration_tests/feature_tests/iterator_tests/test_tuple.py |
Migrates dimensions. |
tests/next_tests/integration_tests/multi_feature_tests/ffront_tests/test_ffront_fvm_nabla.py |
Uses qualified provider keys. |
tests/next_tests/integration_tests/multi_feature_tests/ffront_tests/test_icon_like_scan.py |
Reuses canonical dimensions. |
tests/next_tests/integration_tests/multi_feature_tests/ffront_tests/test_multiple_output_domains.py |
Uses qualified provider keys. |
tests/next_tests/integration_tests/multi_feature_tests/fvm_nabla_setup.py |
Reuses canonical dimensions. |
tests/next_tests/integration_tests/multi_feature_tests/iterator_tests/test_anton_toy.py |
Migrates dimensions. |
tests/next_tests/integration_tests/multi_feature_tests/iterator_tests/test_fvm_nabla.py |
Reuses canonical dimensions. |
tests/next_tests/integration_tests/multi_feature_tests/iterator_tests/test_if_stmt.py |
Migrates dimensions. |
tests/next_tests/integration_tests/multi_feature_tests/iterator_tests/test_temporaries.py |
Migrates dimensions. |
tests/next_tests/integration_tests/multi_feature_tests/iterator_tests/test_with_toy_connectivity.py |
Uses qualified provider keys. |
tests/next_tests/regression_tests/embedded_tests/test_domain_pickle.py |
Migrates pickle dimensions. |
tests/next_tests/regression_tests/ffront_tests/test_offset_dimensions_names.py |
Updates tag regressions. |
tests/next_tests/toy_connectivity.py |
Defines canonical connectivity dimensions. |
tests/next_tests/unit_tests/conftest.py |
Migrates dummy dimensions. |
tests/next_tests/unit_tests/embedded_tests/test_basic_program.py |
Migrates dimensions. |
tests/next_tests/unit_tests/embedded_tests/test_common.py |
Migrates index tests. |
tests/next_tests/unit_tests/embedded_tests/test_context.py |
Migrates range dimensions. |
tests/next_tests/unit_tests/embedded_tests/test_nd_array_field.py |
Tests nominal field behavior. |
tests/next_tests/unit_tests/ffront_tests/test_decorator_domain_deduction.py |
Migrates grid deduction tests. |
tests/next_tests/unit_tests/ffront_tests/test_diagnostic_messages.py |
Migrates diagnostic fixtures. |
tests/next_tests/unit_tests/ffront_tests/test_fbuiltins.py |
Migrates builtin fixtures. |
tests/next_tests/unit_tests/ffront_tests/test_foast_to_gtir.py |
Verifies qualified lowering. |
tests/next_tests/unit_tests/ffront_tests/test_func_to_foast.py |
Migrates parser fixtures. |
tests/next_tests/unit_tests/ffront_tests/test_func_to_foast_error_line_number.py |
Migrates line-sensitive fixture. |
tests/next_tests/unit_tests/ffront_tests/test_past_to_gtir.py |
Expects qualified axes. |
tests/next_tests/unit_tests/ffront_tests/test_source_utils.py |
Migrates closure fixtures. |
tests/next_tests/unit_tests/ffront_tests/test_stages.py |
Migrates stage fixtures. |
tests/next_tests/unit_tests/ffront_tests/test_type_deduction.py |
Tests nominal deduction. |
tests/next_tests/unit_tests/iterator_tests/ir_utils_tests/test_domain_utils.py |
Tests tagged domains. |
tests/next_tests/unit_tests/iterator_tests/test_embedded_field_with_list.py |
Tests shared ConstList. |
tests/next_tests/unit_tests/iterator_tests/test_embedded_internals.py |
Migrates dimensions. |
tests/next_tests/unit_tests/iterator_tests/test_inline_dynamic_shifts.py |
Migrates dimensions. |
tests/next_tests/unit_tests/iterator_tests/test_pretty_parser.py |
Tests ignored kind suffixes. |
tests/next_tests/unit_tests/iterator_tests/test_pretty_printer.py |
Tests derived kind suffixes. |
tests/next_tests/unit_tests/iterator_tests/test_pretty_roundtrip.py |
Updates axis round trips. |
tests/next_tests/unit_tests/iterator_tests/test_runtime_domain.py |
Migrates connectivity types. |
tests/next_tests/unit_tests/iterator_tests/test_type_inference.py |
Tests resolved dimensions. |
tests/next_tests/unit_tests/iterator_tests/transforms_tests/test_collapse_tuple.py |
Migrates dimensions. |
tests/next_tests/unit_tests/iterator_tests/transforms_tests/test_concat_where_canonicalize_domain_args.py |
Migrates dimensions. |
tests/next_tests/unit_tests/iterator_tests/transforms_tests/test_concat_where_expand_tuple_args.py |
Migrates dimensions. |
tests/next_tests/unit_tests/iterator_tests/transforms_tests/test_concat_where_transform_to_as_fieldop.py |
Migrates dimensions. |
tests/next_tests/unit_tests/iterator_tests/transforms_tests/test_cse.py |
Migrates provider types. |
tests/next_tests/unit_tests/iterator_tests/transforms_tests/test_dead_code_elimination.py |
Migrates dimensions. |
tests/next_tests/unit_tests/iterator_tests/transforms_tests/test_domain_inference.py |
Uses qualified axis tags. |
tests/next_tests/unit_tests/iterator_tests/transforms_tests/test_expand_tuple_maps.py |
Migrates dimensions. |
tests/next_tests/unit_tests/iterator_tests/transforms_tests/test_fuse_as_fieldop.py |
Migrates local list dimensions. |
tests/next_tests/unit_tests/iterator_tests/transforms_tests/test_global_tmps.py |
Migrates dimensions. |
tests/next_tests/unit_tests/iterator_tests/transforms_tests/test_inline_scalar.py |
Migrates dimensions. |
tests/next_tests/unit_tests/iterator_tests/transforms_tests/test_prune_casts.py |
Migrates dimensions. |
tests/next_tests/unit_tests/iterator_tests/transforms_tests/test_prune_empty_concat_where.py |
Uses qualified provider keys. |
tests/next_tests/unit_tests/iterator_tests/transforms_tests/test_unroll_reduce.py |
Tests qualified local tags. |
tests/next_tests/unit_tests/otf_tests/binding_tests/test_cpp_interface.py |
Migrates binding dimensions. |
tests/next_tests/unit_tests/otf_tests/compilation_tests/build_systems_tests/conftest.py |
Generates mangled fixture tags. |
tests/next_tests/unit_tests/otf_tests/test_compiled_program.py |
Migrates dimensions. |
tests/next_tests/unit_tests/otf_tests/test_runners.py |
Tests interactive fallback. |
tests/next_tests/unit_tests/program_processor_tests/codegens_tests/gtfn_tests/test_gtfn_module.py |
Uses qualified axis tags. |
tests/next_tests/unit_tests/program_processor_tests/runners_tests/dace_tests/test_dace.py |
Uses qualified provider keys. |
tests/next_tests/unit_tests/program_processor_tests/runners_tests/dace_tests/test_dace_bindings.py |
Tests mangled bindings. |
tests/next_tests/unit_tests/program_processor_tests/runners_tests/dace_tests/test_dace_translation.py |
Builds symbolic names through helpers. |
tests/next_tests/unit_tests/program_processor_tests/runners_tests/dace_tests/test_gtir_to_sdfg.py |
Tests nominal DaCe lowering. |
tests/next_tests/unit_tests/program_processor_tests/runners_tests/dace_tests/transformation_tests/test_map_promoter.py |
Migrates map dimensions. |
tests/next_tests/unit_tests/test_common.py |
Tests nominal dimension semantics. |
tests/next_tests/unit_tests/test_constructors.py |
Uses typed indices. |
tests/next_tests/unit_tests/test_custom_layout_allocators.py |
Tests typed alignment indices. |
tests/next_tests/unit_tests/test_field_utils.py |
Migrates dimensions. |
tests/next_tests/unit_tests/test_utils.py |
Tests dimension-key fingerprints. |
tests/next_tests/unit_tests/type_system_tests/test_type_info.py |
Migrates type fixtures. |
tests/next_tests/unit_tests/type_system_tests/test_type_translation.py |
Tests class-based translation. |
typing_tests/test_next.yaml |
Verifies PEP 484 dimensions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Records the design this stack implements, ahead of the code, because it reverses
decisions that are easier to argue about as prose than as a 150-file diff.
A concrete dimension becomes a class and an index an instance of it, so
`Field[Dims[IDim], float64]` type-checks with no gt4py mypy plugin. A
dimension's identity is the Python type and its tag is the qualified Python
name, which is also a unique, valid IR spelling.
The decisions worth reviewing first, each with the reason it is not the obvious
choice:
* Nominal identity, not `(name, kind)` value equality with an interning
registry. The registry decouples the Python type's identity from the IR's
and needs `copyreg` plus a custom fingerprint deconstructor to bridge the
gap. Under value equality the `typing` subscription cache already aliases
`Field[Dims[I]]` and `Field[Dims[I2]]` for two distinct same-named classes,
so the static and runtime views disagree exactly there.
* `resolve(tag)` is an import, so types reaching the IR must be declared at
module level. Interactive `__main__` is a documented limitation; `spawn`
workers re-execute the main script, so file-based `__main__` resolves.
* Generated identifiers need a *prefix* escape (`_` -> `_u`, `.` -> `_d`).
The obvious `_` -> `__` then `.` -> `_` is not injective: a dot becomes a
single underscore, so `".."` collides with an escaped `"_"`.
* `Staggered[D]` supersedes ADR 0026's `_Staggered` name prefix, which cannot
survive type identity. It cannot be a PEP 695 generic either -- that yields
a `_GenericAlias`, not a class -- so it is an interning metaclass paired
with a `TYPE_CHECKING` declaration.
* `DimensionMeta` must declare `__hash__` explicitly, since `__eq__` stays for
the `I == 5` overload and Python would otherwise make every dimension class
unhashable.
Consequence recorded for ADR 0023: a dimension is fingerprinted by qualified
name, so moving a declaration between modules invalidates compiled artifacts.
A dimension tag becomes a qualified Python name in this stack, so it contains
dots -- illegal in a C++ identifier, in a DaCe symbol, and in `eve`'s
`SymbolName` (`^[a-zA-Z_]\w*$`). `codegen_name` mangles a tag into a valid
identifier and `from_codegen_name` recovers it, for the backends that parse a
generated name back into the dimension it refers to.
The escape is a *prefix* escape (`_` -> `_u`, `.` -> `_d`). The obvious
alternative -- double every underscore, then turn dots into single underscores --
is **not injective**: a dot becomes a single underscore, so `'..'` and `'_'` both
map to `'__'`. Exhaustively: 686 collisions in 1092 inputs over `{a, ., _}` up to
length 6. A collision here would mean two distinct dimensions silently sharing
one generated symbol, i.e. wrong results rather than a crash, so the test is
exhaustive rather than example-based: every string over `{a, ., _, u, d}` up to
length 5 mangles uniquely and round-trips, and the adversarial cases that look
like the escape sequences themselves (`_u`, `_d`, `a_ud.b`) are pinned
separately.
No caller yet; the sites that need it arrive with the dimension classes.
The core of ADR 0028. NOT green: `Dimension("X")` now raises, so every
declaration in the tree has to become a class statement. That sweep is the next
commit; this one is the mechanism it depends on.
* `DimensionMeta` / `DimensionIndex`: a dimension is a class, an index an
instance. Identity is the type; `tag` is the qualified Python name and is a
metaclass *property*, so it cannot drift from what it names. `__hash__` is
declared explicitly because `__eq__` stays for the `I == 5` overload.
Dimension-vs-dimension `__eq__` is deliberately *not* overridden -- identity
is the correct answer, and overriding it is what the ADR rejects.
* `type Dimension = type[DimensionIndex]`, a PEP 695 alias so the removed
`Dimension("I")` raises instead of silently evaluating to `str`.
* Display uses `__qualname__`, not `tag`: 148 tests assert on message text like
`Field[[IDim], float64]`, and a qualified name there is noise. `repr` carries
the module.
* `resolve(tag)` imports and walks the qualname, memoized, with a grammar for
the parametrized `<owner>[<base>]` form.
* `Staggered[D]` replaces ADR 0026's `_Staggered` name prefix, which cannot
survive type identity. An interning metaclass builds a *real* class, paired
with a `TYPE_CHECKING` declaration -- a PEP 695 generic yields a
`_GenericAlias`, which is not a class and fails eve's `type[...]` validation.
Bases are `(Staggered,)` and deliberately not `(Staggered, base)`, so a
staggered field is not accepted where its base is required. Verified: real
class, interning stable, kind inherited, tag resolvable, instances work,
`copyreg` round-trips both the parametrized class and the bare base, and all
three escape routes (subclassing either level, double subscript) are blocked.
* `ConstListDim` is declared **once** in `common`. It used to be built
independently in `iterator/embedded.py` and in the DaCe lowering, which was
harmless while dimensions compared by `(name, kind)`. Under nominal identity
those would be two different dimensions and the `offset_type == _CONST_DIM`
checks in the DaCe lowering would stop matching `ListType`s built by embedded
execution.
Continues the dimension-classes core. `tests/next_tests/unit_tests` is green (1752 passed); integration and DaCe suites not yet run. Source: * `.value` -> `.tag` on dimensions, replayed from #2844 by exact line match (88 sites) plus the lines that had drifted since its base. * `isinstance(x, Dimension)` and `case Dimension()` -> `DimensionMeta`, since `Dimension` is a PEP 695 alias that neither accepts. * `resolve()` at the IR boundaries that rebuild a dimension from a tag. * `NamedIndex` removed: an index is an instance of its dimension. Four sites tuple-unpacked an index and now read `.dim` / `.value`. * Injective mangling applied to generated identifiers in gtfn (the declared `TagDefinition`s and the references to them), nanobind, DaCe and the roundtrip emitter -- declarations and references must mangle identically, or the bindings name a C++ type that was never declared. * DaCe no longer synthesizes a local dimension from the offset tag; it uses the connectivity's own `neighbor_dim`. Display vs identity, now applied uniformly: diagnostics print `__qualname__`, IR and codegen use `tag`. `Staggered` overrides `tag` so its `__qualname__` can stay short. `order_dimensions` sorts by `__qualname__` too: sorting by the qualified tag made a field's canonical dimension order depend on *which module* declared each dimension (recorded in ADR 0028). Tests: * Every `Dimension(...)` declaration became a class (codemod); the 132 function-local ones were hoisted. No hoist changed behaviour: same-variable locals merge into one class, and every same-name/different-variable pair already differed in kind. * Inline `Dimension("X")` expressions map to one shared class per (name, kind) per file, because two such calls used to be equal. * One string per connectivity: a local dimension's tag is now qualified, so the `V2EDim = Dimension("V2E")` convention that made the offset tag, the local dimension and the provider key one string is gone. Restored symbolically -- `FieldOffset(V2EDim.tag, ...)`, `{V2EDim.tag: table}` -- so PR 4 changes only the declaration. * Cross-module duplicates: dimensions that were value-equal across modules are distinct now. `cases_utils` imports the six unstructured dimensions it shared with `toy_connectivity` instead of redeclaring them, and four tests import rather than redeclare. A same-*variable* check was not enough: the original *strings* decide equality, and `test_gtfn_module`'s `IDim` was `"I"` while `cases_utils`' was `"IDim"`, so those stay distinct.
It was committed by accident, via a broad `git add` of `docs/`. It is a working artifact for planning this stack -- with four rounds of review notes folded in -- not documentation for the repository, and ADR 0028 already records the decisions that need to live here. It stays available outside the PR.
…reen
`tests/next_tests/unit_tests` green on every backend: 1760 passed without DaCe,
451 with. Integration suite not yet re-run.
The main fix is a consequence of the previous commit that it did not follow
through. Pulling the one-string-per-connectivity invariant into this PR makes
the *offset* keys qualified here too, so the offset-name mangling the plan
scheduled for PR 4 is needed now:
* gtfn: connectivity parameter names and `generated::<name>_t` keys, the
`SymRef` to each connectivity, and `axis_literal` literals.
* DaCe: `connectivity_identifier` mangles, and all three places that parse an
identifier back (`is_connectivity_identifier`, `_field_symbol`, and the
generated binding code) unmangle -- the binding uses the mangled name as a
Python variable but must look the table up by the real tag.
* DaCe `visit_AxisLiteral`: a dotted tag in a symbol name gets re-parsed as an
attribute access, leaving bare sympy symbols (no `dtype`) in an array's free
symbols.
* `IndexConnectorFmt` was mangled at one of its three uses, so a connector was
declared under one name and referenced under another.
`codegen_name` also escapes `[` and `]`: `Staggered[pkg.K]` has them and they
survived into identifiers (Python read the emitted name as a subscript). The
exhaustive injectivity test now covers `{a . _ [ ] u d l r}`.
Tests: the DaCe tests that hard-coded symbol names -- 190 in one file -- now
compute them from `sdfg_args`, so they stop depending on a naming scheme they
are not testing. The binding golden test formats both sides, since the longer
names make lines wrap. More dimensions that were value-equal across library
modules are unified: `past_common` and `fvm_nabla_setup` import theirs, and
`test_dace_bindings` takes the `cases` dimensions its fixture is sized on.
…n names * Strict fingerprinter: `Staggered[K]` has no importable qualified name, so the by-reference `type` deconstruction rejected it. Registered on `StaggeredMeta`, it is fingerprinted by its base dimension (importable), the same reduction its `copyreg` hook uses; the bare `Staggered` stays by reference. * IR text format: the pretty parser read axis and offset literals as `CNAME`, so a qualified tag (dots, and brackets for `Staggered[pkg.K]`) did not round-trip. A `TAG` terminal describes a qualified name; unambiguous, since a tag starts with a letter and the literal's suffix terminates it. * gtfn: the scan column axis and sparse-argument tuple-like dimensions still named `generated::<tag>_t` with the raw tag. * The sparse-argument path read `.tag` off a legacy `FieldOffset`, which only has `.value` -- a leftover of the #2844 `.value -> .tag` replay.
Everything now passes: unit 1764 + 451 (DaCe), integration and regression
2745 + DaCe, and every notebook `test_examples` runs.
* Notebooks. Compilation runs in `spawn` workers by default, and a class declared
in an interactive `__main__` (a notebook, the REPL, `python -c`) pickles in the
parent but cannot be unpickled in a worker, which has no such `__main__` to
import. Reproduced with CI's own mechanism (`nbmake`):
"Can't get attribute 'IDim' on <module '__main__'>". The project's own
Quickstart and workshop do exactly this, so a documented limitation was not
enough. The process runner now falls back to the calling thread, with a
warning, when a job references a class from an interactive `__main__` -- the
same fallback it already takes for an unpicklable executor. Scripts keep
parallel compilation: spawn re-imports a script's `__main__`. ADR 0028 updated.
* `__gt_dims__` is the interop protocol with `gt4py.cartesian`, which names axes
by bare name ("I", "J", "K"), so it returns `__qualname__`, not the qualified
tag -- otherwise cartesian transposes the array wrongly. No test covered it;
one does now, and fails with the fix reverted.
* Docs, workshop notebooks and `examples/` migrated; notebook code cells only,
stored outputs untouched. Both the Quickstart and `slides_2` declared the cell
dimension twice, harmless while declarations compared equal; the second one is
dropped, since the Quickstart later combined fields built on each.
* mypy clean on `src/`. `_is_field_axis` called `isinstance` on a PEP 695 alias,
which raises at runtime; only an `assert` reaches it. `TYPE_BUILTINS` keeps the
`common.Dimension` alias: its `__name__` is "Dimension", the DSL builtin's
name. (#2844 swapped in `DimensionIndex`, which would rename the builtin.)
* DaCe orchestration test and two diagnostics that joined tags into messages.
The `src/` doctests were the one suite not covered locally: `pytest tests/` does
not collect them, and nox runs them last, after the main suite. The Python 3.13
and 3.14 nox sessions caught 40 failures there -- all `Dimension("I")` calls on
what is now a non-callable alias. They pass now on 3.12, 3.13 and 3.14 (116).
* 60 doctest declarations become `class X(DimensionIndex): ...`, and 8 inline
`Dimension("I")` expressions get a declaration hoisted in front of them.
* Expected outputs showing the old `Dimension(value='I', ...)` repr are updated to
the actual output. Applied only where the difference is purely a dimension's
spelling, checked mechanically; one update the check refused was a false
positive and was verified by eye.
* A class declared in a doctest runs in a *copy* of the module's globals, so it
is not an attribute of the real module and `resolve()` cannot import it. Four
doctests run an IR pass that resolves a dimension; they bind the class onto the
module explicitly, with a comment -- the same consequence of nominal identity
as interactive `__main__`, confined to doctests.
* Those bindings are separate `>>>` statements: written as `import sys; ...` on
one line, ruff's docstring formatter split them into a continuation that
doctest compiles as a single statement.
With the dimension half of the mypy plugin gone, a dimension bound to a variable
(`IDim = gtx.Dimension("I")`) is no longer valid in an annotation: only a class
is. `test_typing_exports` runs these snippets in CI and was not covered by any
local suite.
Taken from #2844 unchanged. Static typing depends only on dimensions being
classes, which both designs share; nothing in these snippets touches identity
semantics, and main has not changed the file since #2844's base. 16 passed.
`pre-commit run --all-files` (what CI runs) reformats four lines that now fit on one line after `.value` -> `.tag`; the per-commit runs only covered staged files.
- a dimension cannot be staggered twice: the check reads the *argument* - intern staggered dimensions with 'setdefault', since compilation runs in threads - 'resolve' rejects a bracketed tag whose owner is not a parametrized dimension - the 'Dim + offset' hint quotes the dimension's display name, not '.value' - ADR 0026: the name-prefix encoding is superseded by ADR 0028 - drop the FieldOffset tag/name analysis: the knowledge base keeps that record - 'runtimes': say where an unpicklable job is actually reported
…t, settle the Dimension operators TODO The roundtrip artifact stores the ref of each axis instead of its tag, so `load` rejects a dimension redefined with another kind, category or staggered base.
…s error-message parameter
|
cscs-ci run default 🤖 Written by an agent on my behalf. |
It only served the roundtrip backend, for a program first loaded after its dimensions were redefined. The limitation is documented in `dimension_tags.resolve`.
| ) | ||
|
|
||
|
|
||
| def from_codegen_name(name: str) -> Tag: |
There was a problem hiding this comment.
Only in the DaCe backend: connectivity_offset in dace/sdfg_args.py uses it to recover the offset-provider key from the name of a connectivity array in the SDFG.
🤖 Written by an agent on my behalf.
There was a problem hiding this comment.
Yes, removed in d93891d, see my reply on from_codegen_name in dimensions.py.
🤖 Written by an agent on my behalf.
|
cscs-ci run default 🤖 Written by an agent on my behalf. |
havogt
left a comment
There was a problem hiding this comment.
Next round of ADR comments.
| so `gtx.Field[gtx.Dims[IDim], gtx.float64]` is valid for any PEP 484 checker with | ||
| no GT4Py mypy plugin. | ||
|
|
||
| A dimension's **identity is the Python type** at the Python edge, i.e. in user code, |
There was a problem hiding this comment.
Can we not replace "Python edge" by user code or frontend an other established term?
There was a problem hiding this comment.
Replaced with "user code, embedded execution and program calls", also in the code comments and the PR description (992e7c7). The section title now reads "classes in user code, DimensionRef values in the toolchain".
🤖 Written by an agent on my behalf.
| dedicated mypy plugin that substituted at most four distinct placeholders per run | ||
| (`_DimA`..`_DimD`, then `_AnyDim` for everything after), made `TypeVar`s over | ||
| dimensions impossible, and served only mypy — no other checker. See #2503. |
There was a problem hiding this comment.
| dedicated mypy plugin that substituted at most four distinct placeholders per run | |
| (`_DimA`..`_DimD`, then `_AnyDim` for everything after), made `TypeVar`s over | |
| dimensions impossible, and served only mypy — no other checker. See #2503. | |
| dedicated mypy plugin that substituted at most four distinct placeholders per run, | |
| made `TypeVar`s over dimensions impossible, and served only mypy — no other checker. See #2503. |
There was a problem hiding this comment.
Applied in e7cdbea.
🤖 Written by an agent on my behalf.
| The alternative — `(name, kind)` value equality plus an interning registry, so | ||
| that independently declared same-named dimensions stay interchangeable — was | ||
| considered and rejected. It decouples the Python type's identity from the IR's, | ||
| and needs a name-keyed registry and a blanket `copyreg` hook to paper over that gap. It also cannot give a dimension nested inside another |
There was a problem hiding this comment.
| and needs a name-keyed registry and a blanket `copyreg` hook to paper over that gap. It also cannot give a dimension nested inside another | |
| and needs a name-keyed registry. | |
| It also cannot give a dimension nested inside another |
There was a problem hiding this comment.
Applied in e7cdbea.
🤖 Written by an agent on my behalf.
| One concrete argument in favour of nominal identity: under `(name, kind)` | ||
| equality the `typing` subscription cache aliases `Field[Dims[I]]` and | ||
| `Field[Dims[I2]]` for two *distinct* same-named classes, so the static and | ||
| runtime views disagree exactly there. Under type identity that aliasing | ||
| disappears. | ||
|
|
There was a problem hiding this comment.
Maybe I am tired, but I have problems comprehending this long sentence.
There was a problem hiding this comment.
Rewritten as a short example with two classes both named I, in e7cdbea.
🤖 Written by an agent on my behalf.
| Below the frontend, two refs are equal if all their fields are: the same qualified | ||
| name, `kind`, Cartesian axis flag and staggered base is the same dimension. The IR is therefore | ||
| self-contained and a compile task ships no user classes (except, for now, inside the | ||
| offset provider, see below). |
There was a problem hiding this comment.
It pointed to the interactive __main__ paragraph. The sentence now says it directly: the connectivities of the offset provider still hold dimension classes. In e7cdbea.
🤖 Written by an agent on my behalf.
| is rejected, embedded or compiled. Dimensions the definition does not declare and a | ||
| field operator's `domain` argument are not compared, and `python -O` disables the check. |
There was a problem hiding this comment.
| is rejected, embedded or compiled. Dimensions the definition does not declare and a | |
| field operator's `domain` argument are not compared, and `python -O` disables the check. | |
| is rejected, embedded or compiled. |
that's not architecture but implementation
There was a problem hiding this comment.
Applied in e7cdbea.
🤖 Written by an agent on my behalf.
| **Interactive `__main__`** -- a notebook, the REPL, `python -c` -- has no | ||
| `__file__` for a worker to re-import, so a class declared there pickles in the | ||
| parent (which has it) and then fails to unpickle in a spawn worker. This is not | ||
| left as a documented limitation: the repository's own Quickstart and workshop | ||
| notebooks declare dimensions interactively and are run in CI. Instead the | ||
| process runner detects a job that references a class from an interactive | ||
| `__main__` and compiles it in the calling thread, with a warning -- the same | ||
| fallback it already takes for an executor that cannot be pickled. With refs | ||
| below the frontend this only triggers for programs whose offset provider holds | ||
| connectivities, which carry their dimension classes. A *script's* `__main__` is | ||
| re-imported by spawn workers as `__mp_main__`. A dimension created there takes | ||
| `__main__` as its module, so its tag and fingerprint are the parent's and scripts keep | ||
| parallel compilation, provided they have the `if __name__ == "__main__":` guard the | ||
| worker pool already requires: while a worker imports the script, its dimensions cannot | ||
| be pickled. `(tag, kind)` value identity with a registry | ||
| avoided this by pickling dimensions by value; that is the one case where it | ||
| was strictly more convenient. |
There was a problem hiding this comment.
Cut to three lines in e7cdbea.
🤖 Written by an agent on my behalf.
| reference, which is correct. A *narrow* `copyreg` registration is still | ||
| required for parametrized dimensions — see Staggered below. |
There was a problem hiding this comment.
Is the "narrow copyreg" really still required?
There was a problem hiding this comment.
Not by the toolchain, which ships refs. It is needed to pickle Staggered[K] itself, or a field over it: pickle stores a class by its __qualname__, and Staggered[K] cannot be looked up by that name. Nothing tested it, so 992e7c7 adds a test. It is an implementation detail, so the ADR no longer mentions it (e7cdbea).
🤖 Written by an agent on my behalf.
| 5. **Generated identifiers need injective mangling.** A tag is not a valid C++, | ||
| DaCe or `eve` identifier, so all backends share one reversible escape | ||
| (`common.codegen_name` / `from_codegen_name`). | ||
|
|
There was a problem hiding this comment.
Is the reversible thing still needed? If not, there is no requirement to share this. They might still share, but it can be removed as implementation detail from this adr.
There was a problem hiding this comment.
Only injectivity is a requirement, and the ADR now says only that (e7cdbea). For the code, see my reply on from_codegen_name in dimensions.py.
🤖 Written by an agent on my behalf.
| DaCe or `eve` identifier, so all backends share one reversible escape | ||
| (`common.codegen_name` / `from_codegen_name`). | ||
|
|
||
| 6. **Staggered dimensions become a real parametrized type.** ADR 0026's |
There was a problem hiding this comment.
How much of point 6 is implementation detail not needed at ADR level?
There was a problem hiding this comment.
Cut to the decision in e7cdbea: Staggered[K] is a real interned class, not a subclass of K, with tag <owner tag>[<base tag>].
🤖 Written by an agent on my behalf.
|
|
||
| E2C = gtx.FieldOffset("E2C", source=Cell, target=(Edge, E2CDim)) | ||
| C2E = gtx.FieldOffset("C2E", source=Edge, target=(Cell, C2EDim)) | ||
| E2C = gtx.FieldOffset(E2CDim.tag, source=Cell, target=(Edge, E2CDim)) |
There was a problem hiding this comment.
Cannot we just use the dimension itself here instead of .tag? Or is that cleanup a follow up?
There was a problem hiding this comment.
A follow-up. Here FieldOffset still takes the offset-provider key, a string. Passing the declaration itself is part of the connectivity change.
🤖 Written by an agent on my behalf.
| #: The module in every staggered tag. A literal, not `__name__`: tags must not depend on the | ||
| #: submodule that declares `Staggered`. | ||
| _STAGGERED_MODULE: Final = "gt4py.next.common" |
There was a problem hiding this comment.
The docstring is not very clear. It describes what but the why is a not obvious.
There was a problem hiding this comment.
Rewritten with the why: tags end up in the IR, the generated code and the fingerprints, so they must not change when Staggered moves within common.
🤖 Written by an agent on my behalf.
|
|
||
| #: Interned refs: equal refs are the identical object, because pickle memoizes by identity and | ||
| #: `pickle`-based content hashes (`eve.utils.content_hash`) would differ otherwise. | ||
| _DIMENSION_REF_INTERN: weakref.WeakValueDictionary[tuple[Any, ...], DimensionRef] = ( |
There was a problem hiding this comment.
can we not override the pickling behavior? in DimensionRef...
There was a problem hiding this comment.
That does not help. pickle memoizes by object identity, so two equal but distinct refs give different bytes, and so a different content_hash, whatever __reduce__ returns. I checked: content_hash([a, a]) != content_hash([a, b]) for a == b, a is not b. Interning makes equal refs the same object. The comment now says this.
🤖 Written by an agent on my behalf.
| ) | ||
|
|
||
|
|
||
| _DIMENSION_REF_INTERN_LOCK: Final = threading.RLock() |
There was a problem hiding this comment.
Gone. A plain dict with setdefault gives racing threads the same ref, like the Staggered cache.
🤖 Written by an agent on my behalf.
| object.__setattr__(self, "_hash", hash(self._identity_key())) | ||
|
|
||
| def __reduce__(self) -> tuple[Any, ...]: | ||
| # By value, through the constructor, so an unpickled ref is interned too. |
There was a problem hiding this comment.
I am not sure what the comment is trying to tell me?
There was a problem hiding this comment.
Reworded: the hash is cached because refs are hashed often, and as an attribute rather than a field it stays out of the pickle and the fingerprint.
🤖 Written by an agent on my behalf.
| ) | ||
|
|
||
|
|
||
| def from_codegen_name(name: str) -> Tag: |
There was a problem hiding this comment.
Why is this still here? When do we need to demangle?
There was a problem hiding this comment.
Removed in d93891d. Its only user was the DaCe backend, which decoded the offset-provider key from the connectivity array name. The translation step now passes the keys to the bindings in SDFGCodeSpec, and the other places match a name by encoding the keys of the offset-provider type.
🤖 Written by an agent on my behalf.
| _CODEGEN_UNESCAPE: Final = {"u": "_", "d": ".", "c": ":", "l": "[", "r": "]"} | ||
|
|
||
|
|
||
| def codegen_name(tag: Tag) -> str: |
There was a problem hiding this comment.
Why here and not in some util?
There was a problem hiding this comment.
It encodes the tag format this module defines (module:qualname, Staggered[...]), so it sits next to it. I looked for an existing helper that could replace it: the ones in the repo (cartesian.utils.slugify, the flag mangling in compiledb.py) drop characters, so two tags could end up with the same identifier.
🤖 Written by an agent on my behalf.
|
|
||
|
|
||
| #: Interned staggered dimensions, by base dimension class (not by name, see ADR 0030). | ||
| _STAGGERED_CACHE: dict[Dimension, Dimension] = {} |
There was a problem hiding this comment.
Staggered[K] has to return the same class every time, since dimensions compare by identity. The comment now says so.
🤖 Written by an agent on my behalf.
|
|
||
| With a PEP 695 generic, `Staggered[K]` would not be a class. See ADR 0030. |
There was a problem hiding this comment.
Rewritten: Staggered[K] creates a dimension class, once per base; a typing generic would give an alias, which is not a class.
🤖 Written by an agent on my behalf.
| @dataclasses.dataclass(frozen=True) | ||
| class _AnyDim(Dimension): ... | ||
|
|
||
| copyreg.pickle(StaggeredMeta, _reduce_staggered) |
There was a problem hiding this comment.
pickle stores a class by its __qualname__, which it cannot look up for Staggered[K]. There is now a comment and a test.
🤖 Written by an agent on my behalf.
| ... ) | ||
| >>> domain.slice_at[2:3, 2:5] | ||
| Domain(dims=(Dimension(value='I', kind=<DimensionKind.HORIZONTAL: 'horizontal'>), Dimension(value='J', kind=<DimensionKind.HORIZONTAL: 'horizontal'>)), ranges=(UnitRange(2, 3), UnitRange(7, 10))) | ||
| Domain(dims=(gt4py.next.common.domains:I[horizontal], gt4py.next.common.domains:J[horizontal]), ranges=(UnitRange(2, 3), UnitRange(7, 10))) |
There was a problem hiding this comment.
What is this:
gt4py.next.common.domains:I[horizontal]
```?
Explain better
…the DaCe bindings The DaCe backend no longer recovers offset-provider keys from mangled array names. The translation step records the keys of the connectivity arrays in `SDFGCodeSpec`, and the bindings look each table up by its key. Elsewhere, a connectivity name is matched by encoding the keys of the offset-provider type. Also reword the module-level error for dimensions: a dimension's tag is its qualified name, which must be unique and lets the class be pickled.
A dimension's repr is its full tag, so a docstring example showed the module of the doctest on every dimension. The examples now print the short form, and the `DimensionIndex` docstring explains the repr once.
…es-2-dimension-classes # Conflicts: # src/gt4py/next/ffront/type_info.py


A concrete dimension is a class, and an index along it an instance of that class.
Field[Dims[IDim], float64]therefore type-checks with any PEP 484 checker and needs no gt4py mypy plugin (#2503). A dimension's identity is its Python class. Itstag, the spelling in the IR and in generated code, ismodule:qualname.Review the ADR first (
docs/development/ADRs/next/0030-Dimensions_As_Nominal_Types.md). It records the decisions and their consequences. Once those are accepted, most of the rest of the diff is mechanical.API
Staggered[Staggered[K]],Staggered[Cell]andCell + 1are errors for mypy and pyright, and they raise at runtime.FieldOffset(V2EDim.tag, ...)and{V2EDim.tag: table}. Dimension-keyed configuration also accepts the class as a key.DimensionRange.unit_rangeis now.value.NamedIndexis gone: a point is an instance of the dimension class, with the same.dimand.value.symbolic_domain_sizestakes a dimension class or its tag, no longer a bare name.Design
DimensionRef(module, qualname, kind, whether it is a Cartesian axis, staggered base). BecauseAxisLiteralholds that ref, the IR is self-contained, and a compile task ships no user classes except those of the connectivities in the offset provider.CartesianAxisIndexnames one,Staggered[...]the other.__debug__only). Comparing a ref with a class is always a missed conversion, so it raises. Two different refs with the same tag in one program are an error.(name, kind)equality. It needs no name-keyed registry and no blanketcopyreghook, only interning and acopyregentry forStaggered[D], interned refs, and a small fingerprint deconstructor.eveidentifiers (common.codegen_name). Diagnostics and the printed IR use short names, andpformatspells each full tag once in adimheader.iterator.builtins.ConstListreplaces two_CONST_DIMaliases.AxisLiteralnow round-trips through the textual IR.Implements
egparedes/connectivities-as-typesand gt4py_knowledge#36. Supersedes #2844 and subsumes the test migration of #2845.🤖 Written by an agent on my behalf.