Skip to content

feat[next]: a concrete Dimension is a class, identified by its qualified name - #2899

Open
egparedes wants to merge 101 commits into
connectivities-as-types-1b-mechanical-renamesfrom
connectivities-as-types-2-dimension-classes
Open

egparedes wants to merge 101 commits into
connectivities-as-types-1b-mechanical-renamesfrom
connectivities-as-types-2-dimension-classes

Conversation

@egparedes

@egparedes egparedes commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

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 is identified by its qualified name and kind: its tag, the spelling in the IR and in generated code, is module: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

class IDim(gtx.CartesianAxisIndex): ...  # on a Cartesian axis: `IDim + 1`, `Staggered[IDim]`
class Cell(gtx.DimensionIndex): ...      # a mesh location: no index arithmetic, no staggering

field[IDim(3)]           # a point
field[IDim.at(0, 10)]    # a `DimensionRange`; `None` bounds clip to the domain
field[IDim(5):IDim(10)]  # slice syntax (`DimensionSlice[D]`), step 1 only
  • Staggered[Staggered[K]], Staggered[Cell] and Cell + 1 are errors for mypy and pyright, and they raise at runtime.
  • By convention, neighbor offsets and offset providers use the local dimension's tag: FieldOffset(V2EDim.tag, ...) and {V2EDim.tag: table}. symbolic_domain_sizes also accepts the class as a key.
  • NamedIndex is gone: a point is an instance of the dimension class, with the same .dim and .value as a DimensionRange.
  • symbolic_domain_sizes takes a dimension class or its tag, no longer a bare name.

Design

  • Two levels. Classes are used in user code, embedded execution and call arguments. Type specifications, the IR and the backends carry an interned DimensionRef (module, qualname, kind, whether it is a Cartesian axis, staggered base). Because AxisLiteral holds that ref, the IR is self-contained, and a compile task ships no user classes except those of the connectivities in the offset provider.
  • Cartesian axis. An oriented integer line with two cell classes: a CartesianAxisIndex names one, Staggered[...] the other.
  • Equality. Dimension classes compare and hash by their ref, so user code, embedded execution and the toolchain share one rule: a class redefined by re-running a notebook cell is the same dimension as before, and so is the stand-in the toolchain makes from a ref. Dimensions are declared with a class statement. 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.
  • Differences from feat[next]: make a concrete Dimension a class and its instances the indices #2844: equality uses the full ref (qualified name, kind, Cartesian axis flag, staggered base) instead of (name, kind). It needs no name-keyed registry and no blanket copyreg hook, only interned refs, a copyreg entry for Staggered[D] and a small fingerprint deconstructor.
  • Identifiers. Tags are mangled injectively into C++, DaCe and eve identifiers (common.codegen_name). Diagnostics and the printed IR use short names, and pformat spells each full tag once in a dim header.
  • Const lists. iterator.builtins.ConstList is a dimension class and replaces the CONST_LIST_DIM constant.

The changes that do not need dimension classes (open slice bounds, the NamedRange → DimensionRange rename, shared test dimensions and others) are in #3087 and #3088.

Implements egparedes/connectivities-as-types and gt4py_knowledge#36. Supersedes #2844 and subsumes the test migration of #2845.

🤖 Written by an agent on my behalf.

@tehrengruber

Copy link
Copy Markdown
Contributor

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.

Base automatically changed from connectivities-as-types-1-shift-tag to main September 23, 2026 14:31
@egparedes
egparedes force-pushed the connectivities-as-types-2-dimension-classes branch 2 times, most recently from d38784e to 91e24e2 Compare September 23, 2026 16:54
@egparedes
egparedes removed this pull request from stack #2900 September 24, 2026 10:14
@egparedes
egparedes added this pull request to stack #2917 September 24, 2026 10:14
@egparedes
egparedes requested a balanced review from Copilot September 24, 2026 19:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Medium severity · 1 Low severity

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.

Comment thread src/gt4py/next/common.py Resolved
Comment thread src/gt4py/next/otf/runners.py Resolved
Comment thread src/gt4py/next/type_system/type_info.py Resolved
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
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 5 🔵🔵🔵🔵🔵
✅ Merge recommendation: Needs review
🔎 Failure modes

What: A program or field-operator object created before a dimension class was redefined (e.g. a notebook cell re-run) caches `_declared_dimension_classes` on first use, so afterwards calls with correctly re-created arguments are rejected with a DSLError until the program/operator itself is redefined.
Where: src/gt4py/next/ffront/decorator.py:_declared_dimension_classes/_check_dimension_identity
Trigger: Re-run the notebook cell that defines a dimension used by an already-created program, then call that same program object with arguments built on the new class.
Detected by: The raised DSLError message guides the user to re-define the program; tests/next_tests/unit_tests/ffront_tests/test_dimension_identity_at_call.py covers the stale-argument direction but not the stale-program direction.
Covered in this PR: No

What: The roundtrip backend raises ValueError at call time when the call's fields and connectivities use two different classes for the same dimension tag, so a program whose arguments mix pre- and post-redefinition fields fails instead of running.
Where: src/gt4py/next/program_processors/runners/roundtrip.py:_bind_dimensions
Trigger: A dimension is redefined (notebook cell re-run) and a roundtrip-backend program is called with a mix of fields built on the old and the new class.
Detected by: nothing (no roundtrip-specific test exercising this path is visible in the diff)
Covered in this PR: No

What: Unstructured programs declared with interactive `__main__` dimensions still ship the dimension classes inside the runtime offset provider, so a ProcessRunner spawn worker cannot import them and compilation falls back to the calling thread (with a warning) instead of compiling in the worker pool.
Where: tests/next_tests/unit_tests/otf_tests/test_compilation_task_dimension_classes.py:test_unstructured_task_still_references_connectivity_dimensions
Trigger: An unstructured program whose dimensions are declared in a notebook/REPL `__main__` is compiled through `ProcessRunner`.
Detected by: The test above asserts the shipped payload references `__main__` classes (the fallback precondition); the fallback execution itself is not shown as tested.
Covered in this PR: No

🏅 Score: 88
🧪 PR contains tests
🔒 No security concerns identified
🔀 No multiple PR themes
⚡ No major issues detected

ℹ️ Chunked review: the diff exceeded the model token budget, so it was reviewed in 2 chunks and the per-chunk results were merged.


⚙️ Agent run details
  • Model: openai/zai-org/GLM-5.3-Flash
  • Tokens: 304,124 in / 107,599 out / 411,723 total
  • Time cost: 318.1s
  • AI calls: 2

…without a global cache

`Staggered[K]` now returns the partner `K` got at declaration, so there is no module-level table and no race between threads. The rationale for the metaclass moves from the docstring to a comment.
…d is declared

The build cache is keyed by the gt4py version, so a tag that changes when `Staggered` moves is harmless; the literal module and the `__module__` pin go.
Comment on lines +103 to +117

1. **Nothing is imported from a tag.** The roundtrip backend, which runs the generated
program embedded, on classes, takes them from the fields and connectivities of each
call. It synthesizes a class from the ref only for a dimension that none of them
has: such a dimension exists only inside the program.

2. **Dimensions must be importable to be pickled**, i.e. declared at module level.
`__init_subclass__` rejects a `<locals>` qualname as an early heuristic; it is
neither necessary nor sufficient (`type("Dyn", ...)` inside a function passes,
a class deleted after creation passes), so the authoritative check remains
pickle's own `save_global`.

A spawn worker cannot re-import an **interactive `__main__`** (a notebook, the
REPL, `python -c`), so a compile job that holds a class declared there is compiled
in the calling thread, with a warning. Scripts keep parallel compilation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't these two points basically addressing the same question: what should we do if the actual dimension class is not importable from a using context which is different than the definition context? If yes, then shouldn't we use an unified approach to solve the two cases as the same core issue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, both come from the same cause: a compile worker has to find a dimension class by name, and it can't. Unified in 2d83b5c: a compile task ships every dimension class as its ref, and the worker synthesizes a stand-in from it, as the roundtrip backend already does. Fingerprints use only the ref, so the stand-in and the class agree. Dimensions declared in a notebook now compile in a worker; the fallback to the calling thread remains only for other classes declared in an interactive __main__. In the ADR this is now part of consequence 1 ("nothing is imported from a tag"). The <locals> rule stays for unique tags and pickling in user code, with a TODO to reconsider it.

🤖 Written by an agent on my behalf.

A compile worker may not be able to import a dimension class, e.g. one declared in a
notebook. `ProcessRunner` now pickles each dimension class as its ref and the worker
synthesizes a stand-in, as the roundtrip backend does, so such tasks no longer fall
back to the calling thread. Dimensions are fingerprinted by their ref alone, so the
stand-in and the class agree. The `<locals>` rule stays, with a TODO to reconsider it.
_V = TypeVar("_V")


def normalize_offset_provider(offset_provider: Mapping[Any, _V]) -> dict[str, _V]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this? Where do we get a non-normalized offset provider?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need it. Nothing in gt4py produces a provider with dimension keys: I made such keys raise and only the three tests written for them failed. It was a convenience so that users could write {V2EDim: table} instead of {V2EDim.tag: table}, and the docs already teach the .tag form. Removed in 2c44fa3a5, with its six call sites and tests: offset providers are keyed by strings only, as on main.

🤖 Written by an agent on my behalf.

return {_dimension_tag_key(k): v for k, v in offset_provider.items()}


def normalize_symbolic_domain_sizes(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same questions here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one I kept, because here the keys change in this PR. On main symbolic_domain_sizes is keyed by dim.value, e.g. "Cell"; now the key is the tag. Without the normalization an existing {"Cell": ...} would be silently ignored, since it never matches a tag. The function accepts the class as key and raises on a string that is not a tag. It is called where the option enters (gtfn translation step, pass manager, domain inference).

🤖 Written by an agent on my behalf.

idx = named_idx.value
if isinstance(idx, common.UnitRange):
if not idx <= rng:
clipped = _clip_open_bounds(idx, rng)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a bugfix orthogonal to the dimension change? Then lets extract it...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is orthogonal. It moved to #3087 (4ef31ac), which is now below this PR in the stack, so it no longer shows in this diff.

🤖 Written by an agent on my behalf.

start = (
rng.start - domain.ranges[pos].start
if common.UnitRange.is_left_finite(domain.ranges[pos])
and common.UnitRange.is_left_finite(rng)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

existing bug fix or belongs to this PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An existing gap, not part of this PR: a named slice with a missing bound raised on main. It moved to #3087 (4ef31ac) together with the change in embedded/common.py.

🤖 Written by an agent on my behalf.

Comment thread src/gt4py/next/ffront/decorator.py Outdated
),
)

@functools.cached_property

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can the chagne in this file become cleaner or ideally removed? This seems another fight of identity vs equality via refs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 3f87ecb: this file is back to what it is on main. Two dimension classes with equal refs now compare equal, so a redefined dimension needs no check at the call and no capture at decoration. ADR 0030 has the rule under "Identity is the qualified name; classes compare by ref".

🤖 Written by an agent on my behalf.

FLOAT_LITERAL: SIGNED_FLOAT
OFFSET_LITERAL: ( INT_LITERAL | CNAME ) "ₒ"
AXIS_LITERAL: CNAME ("ᵥ" | "ₕ")
// A dimension tag is `module:qualname` (ADR 0030), and -- for a parametrized dimension

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this long comment shouild be outside of the string?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in the merge 04d024f: the comments are now above the grammar string, and the grammar uses AXIS_KIND_SUFFIX. The round-trip fixes themselves moved to #3087 (c89d73e).

🤖 Written by an agent on my behalf.

return root


def _dimension_header(tree: lark_tree.Tree) -> dict[str, common.DimensionRef]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we introducing a dimension declaration in this PR? If yes, lets extract it and do it first.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this PR introduces it, but only because of this PR: a tag is now module:qualname, and the header lets the printed IR use short names in the body. On main a dimension is printed by its short value, so a header would have nothing to abbreviate there, and extracted it would be an unused feature in the lower PR. I would keep it here.

🤖 Written by an agent on my behalf.

return executor(compilable)


class _WorkerPickler(pickle.Pickler):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to extract this from this PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dimension part is gone: dimensions are pickled as refs now (3b8cd0c). What is left records other classes from an interactive __main__ to give a clear error, which has nothing to do with dimensions. Would you like it moved to the preparation PR (#3087)?

🤖 Written by an agent on my behalf.

offset_type: common.Dimension | None
#: The local dimension the list runs along. `None` where type inference does not know it,
#: which is how it spells the result of `make_const_list`; embedded execution and the DaCe
#: lowering use `iterator.builtins.ConstList` for the same thing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not do this!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this in this PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean replacing None by ConstList in type inference, so that offset_type is never None? main already uses None for the result of make_const_list; this PR only changed the field's type to DimensionRef and added the comment and the TODO. If that is what you mean, would you prefer it in the preparation PR (#3087) or in this one?

🤖 Written by an agent on my behalf.

localns: Optional[dict[str, Any]] = None,
) -> ts.TypeSpec:
"""Convert any kind of Python type hint to a GT4Py TypeSpec."""
# NOTE: cached together with the dimension classes the conversion captured, which are

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we get rid of this again

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, removed in 3f87ecb. from_type_hint is the plain cached function from main again, since nothing has to know which names an annotation was resolved from.

🤖 Written by an agent on my behalf.

Dimension classes compare and hash by their ref (qualified name, kind,
Cartesian axis flag, staggered base) instead of by identity, so user code,
embedded execution and the toolchain share one rule. A dimension redefined
by a re-run notebook cell, and the stand-in the toolchain synthesizes from a
ref, are the same dimension as the original class.

This removes the machinery that enforced class identity at program calls:
the capture of (ref, class) pairs in dimension_ref, the declared-dimensions
walk and the identity check in the decorators, the capture-aware cache of
type_translation.from_type_hint, and the binding of the roundtrip backend's
dimensions to the classes of the call arguments. The roundtrip source now
declares its dimensions itself, from their refs.

A dimension must be declared with a class statement: classes made by calling
the metaclass could share a tag while being meant as different dimensions.
A copyreg entry for the dimension metaclasses reduces a class to its
DimensionRef. Loading returns the loaded class with that ref if there is
one, and else a synthesized, equal one, so a dimension declared in an
interactive __main__ pickles across processes with the stdlib pickle.

Staggered[K] goes the same way, which replaces its own copyreg entry, and
the compile runner no longer reduces dimensions itself.
A dimension is what its ref holds, and a class rebuilt from the ref (after
pickling, or by the toolchain) has nothing else: methods, attributes and
annotations in the class body are rejected. A docstring and 'kind' are
allowed.
@egparedes
egparedes removed this pull request from stack #2917 December 4, 2026 11:49
@egparedes
egparedes changed the base branch from main to connectivities-as-types-1b-mechanical-renames December 4, 2026 11:49
@egparedes
egparedes added this pull request to stack #3089 December 4, 2026 11:49
@egparedes

Copy link
Copy Markdown
Contributor Author

cscs-ci run default

🤖 Written by an agent on my behalf.

@egparedes egparedes left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questions about DimensionRef implementation.

Comment thread src/gt4py/next/common/dimensions.py Resolved
Comment thread src/gt4py/next/common/dimensions.py Resolved
Comment thread src/gt4py/next/common/dimensions.py Resolved
@egparedes

Copy link
Copy Markdown
Contributor Author

cscs-ci run default

🤖 Written by an agent on my behalf.

@egparedes

Copy link
Copy Markdown
Contributor Author

cscs-ci run default

🤖 Written by an agent on my behalf.

egparedes added a commit that referenced this pull request Dec 4, 2026
…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.

This branch was successfully deployed

1 active (outdated) deployment
pr-agent — 67a115b8 Deployed Dec 4, 2026 by egparedes via pr-agent / pr-agent #309
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants