Skip to content

refactor[cartesian]: Separate horizontal and vertical interval parsers#2510

Merged
twicki merged 13 commits intoGridTools:mainfrom
twicki:removenewsyntax
Mar 18, 2026
Merged

refactor[cartesian]: Separate horizontal and vertical interval parsers#2510
twicki merged 13 commits intoGridTools:mainfrom
twicki:removenewsyntax

Conversation

@twicki
Copy link
Copy Markdown
Contributor

@twicki twicki commented Mar 4, 2026

Series on interval-parsing (1/3)

This PR is the first one in a series to simplify interval parsing in the front-end.

This entire series was triggered, because runtime-intervals and higher dimensional fields do not interact as intended right now. So here the summary of the slate of work

Current State:

  • The parser between horizontal and vertical intervals is shared
    • This leads to a lot of differentiation having to happen in the calls since what is and is not allowed is very different
  • There is a plethora of different syntaxes allowed for vertical intervals
  • With runtime-intervals now being part of the equation, differentiation became even harder.
  • Accessing higher-dimensional fields with []-operators did trigger exceptions

To tackle these problems, the following PR's are up:

current: split the parser for the horizontal and the vertical and specialize them as appropriate
next: remove all redundant syntax to go back to a more minimalistic language
next: fix how runtime-intervals interact with higher dimensional fields

Description

Split the parser for intervals into a horizontal and a vertical interval-parser.

@twicki twicki marked this pull request as ready for review March 12, 2026 16:04
raise range_error

if len(args) == 2:
if any(isinstance(arg, ast.Subscript) for arg in args):
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.

Note: This check is now inside the vertical parser where it belongs


def test_axisinterval(self):
def definition_func(field: gtscript.Field[float]):
with computation(PARALLEL), interval(K[1:-1]):
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.

note: This is the now disallowed syntax

@twicki twicki requested a review from romanc March 12, 2026 16:05
Copy link
Copy Markdown
Contributor

@romanc romanc left a comment

Choose a reason for hiding this comment

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

Thank you for cleaning this up and separating concerns here. 🧹 🧹 ✨

field_axes: Optional[Set[Literal["I", "J", "K"]]] = None,
) -> list[int] | nodes.AbsoluteKIndex | None:
tuple_or_expr = node.slice.value if isinstance(node.slice, ast.Index) else node.slice
tuple_or_expr = node.slice
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.

Does this change have a downstream effect that tuple_or_expr is now either tuple or an expression all the time?

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.

No, this stems from K[1:2] previously being legal syntax.

Comment thread src/gt4py/cartesian/frontend/gtscript_frontend.py Outdated
Comment thread src/gt4py/cartesian/frontend/gtscript_frontend.py Outdated
@romanc
Copy link
Copy Markdown
Contributor

romanc commented Mar 13, 2026

cscs-ci run

@twicki
Copy link
Copy Markdown
Contributor Author

twicki commented Mar 18, 2026

cscs-ci run

@twicki twicki merged commit b02c935 into GridTools:main Mar 18, 2026
20 checks passed
twicki added a commit that referenced this pull request Mar 27, 2026
## Series on interval-parsing (3/3)
This PR is one in a series to simplify interval parsing in the
front-end.

This entire series was triggered, because runtime-intervals and higher
dimensional fields do not interact as intended right now. So here the
summary of the slate of work

Current State:
- The parser between horizontal and vertical intervals is shared
- This leads to a lot of differentiation having to happen in the calls
since what is and is not allowed is very different
- There is a plethora of different syntaxes allowed for vertical
intervals
- With runtime-intervals now being part of the equation, differentiation
became even harder.
- Accessing higher-dimensional fields with `[]`-operators did trigger
exceptions

To tackle these problems, the following PR's are up:

[2510](#2510): split the parser
for the horizontal and the vertical and specialize them as appropriate
[2553](#2553): fix how
runtime-intervals interact with higher dimensional fields
current: remove all redundant syntax to go back to a more specific
language

## Description

The legal syntax for regions was very bloated and allowed for multiple
ways to express a single output. This PR trims this down to a more
minimalistic approach.
Previously allowed:
- `I[0:2]`
- `I[0] : I[2]`
- `I[0] : I[0] + 2`
- `0:2`

There is no clean way to completely avoiding the axis-access syntax, as
it is required to generate somewhat clean out-of-domain computations to
skip by going `I[0]- LARGENUMBER`. this is why axis-access is still
allowed additionally to plain offset syntax. but only to access the
start and end of the domain.

So this PR minimizes the syntax down to 
- `I[0] : I[0] + 2`
- `0:2`
twicki added a commit that referenced this pull request Apr 1, 2026
…als (#2553)

## Series on interval-parsing (2/3)
This PR is one in a series to simplify interval parsing in the
front-end.

This entire series was triggered, because runtime-intervals and higher
dimensional fields do not interact as intended right now. So here the
summary of the slate of work

Current State:
- The parser between horizontal and vertical intervals is shared
- This leads to a lot of differentiation having to happen in the calls
since what is and is not allowed is very different
- There is a plethora of different syntaxes allowed for vertical
intervals
- With runtime-intervals now being part of the equation, differentiation
became even harder.
- Accessing higher-dimensional fields with `[]`-operators did trigger
exceptions

To tackle these problems, the following PR's are up:

[2510](#2510): split the parser
for the horizontal and the vertical and specialize them as appropriate
current: fix how runtime-intervals interact with higher dimensional
fields
next: remove all redundant syntax to go back to a more minimalistic
language

## Description

Fix the behavior of runtime-intervals when accessing higher dimensional
fields with an offset in the higher dimension.

This additional offset was not caught properly and was always set to 0.
PR 2510 disabled all higher dimensional field accesses to prevent
illegal code.

This PR re-introduces this feature and fixes how the access in handled
to now be correct.
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