Skip to content

feat[next]: staggered fields#2667

Draft
tehrengruber wants to merge 7 commits into
GridTools:mainfrom
tehrengruber:staggered_fields
Draft

feat[next]: staggered fields#2667
tehrengruber wants to merge 7 commits into
GridTools:mainfrom
tehrengruber:staggered_fields

Conversation

@tehrengruber

Copy link
Copy Markdown
Contributor

Add support for staggered fields (replaces #2339), where half-grid dimensions sit half a cell offset from the full grid.

@tehrengruber tehrengruber marked this pull request as draft June 18, 2026 03:50
Comment thread src/gt4py/next/ffront/foast_to_gtir.py Outdated
Comment thread src/gt4py/next/iterator/ir_utils/domain_utils.py Outdated
Comment thread src/gt4py/next/iterator/type_system/type_synthesizer.py Outdated
Comment thread src/gt4py/next/iterator/type_system/type_synthesizer.py Outdated
Comment thread src/gt4py/next/iterator/type_system/type_synthesizer.py Outdated
Comment thread src/gt4py/next/iterator/embedded.py Outdated
Comment thread src/gt4py/next/program_processors/codegens/gtfn/gtfn_module.py Outdated
Comment thread src/gt4py/next/program_processors/codegens/gtfn/itir_to_gtfn_ir.py Outdated
Comment thread src/gt4py/next/common.py
Comment thread tests/next_tests/integration_tests/feature_tests/ffront_tests/test_basic.py Outdated
@tehrengruber tehrengruber force-pushed the staggered_fields branch 2 times, most recently from d40bb43 to 38714de Compare June 19, 2026 01:36
Add support for staggered cartesian fields (GridTools#2339), where half-grid
dimensions sit half a cell offset from the full grid.

- `Dimension +/- 0.5` lowers to a `CartesianConnectivity` relocation onto
  the flipped staggered dimension (`is_staggered`/`flip_staggered`,
  `connectivity_for_cartesian_shift`); integer shifts stay translations.
- Embedded field path (`nd_array_field`) handles the relocation domain
  remap; iterator embedded `execute_shift` moves the position from the
  connectivity's `domain_dim` to its `codomain` (translation is the
  degenerate equal-dim case), replacing the previous relocation assert.
- type_deduction: the `Dimension + offset` cartesian-shift branch is gated
  on `op in {ADD, SUB}` so e.g. `TDim % 2.0` reports an unsupported operand.
- Tests for plus/minus/back/half2center half-shifts across embedded and
  roundtrip.

Rebased on top of GridTools#2411 (cartesian shift as self-describing CartesianOffset
node, gather-only offset providers).
Cartesian offsets are self-describing CartesianOffset IR nodes and no longer
appear in the offset provider, so 'common.get_offset(...)' for a FieldOffset can
only return a (neighbor) Connectivity, never a Dimension. Drop the dead
'isinstance(offset_definition, common.Dimension)' branch (flagged with a
'# TODO: dead-code remove' comment), leaving the Connectivity path as in the
sibling 'as_connectivity_field' method.
Restore Connectivity to a @runtime_checkable Protocol (as on main) instead of a
Generic abc. Field is already a runtime_checkable Protocol, so abstractmethod
enforcement is unchanged; this re-enables structural isinstance checks (relied on
by is_neighbor_table) and matches the 'Connectivity Protocol' workaround comment
in CartesianConnectivity.
Two defects from the staggered-fields restructuring of LambdaToDataflow._visit_shift:

- ~20 lines of unreachable dead code after the if/else (both branches already
  return), including a stale call to '_make_cartesian_shift' with its old
  'Dimension' signature (it now takes a 'CartesianConnectivityType'). Removed.

- An over-strict 'assert isinstance(offset_value_arg, gtir.OffsetLiteral)' in the
  unstructured branch that broke dynamic neighbor offsets: the offset value may be
  a dynamic expression (the pre-existing code and '_make_unstructured_shift' both
  handle this via '_make_dynamic_neighbor_offset'). Removed; the offset *provider*
  asserts (it must be a named string OffsetLiteral) are kept.
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.

2 participants