Skip to content

fix[cartesian]: Fix higher dimensional field access in runtime-intervals#2553

Open
twicki wants to merge 7 commits intoGridTools:mainfrom
twicki:fix_high_dim_intervals
Open

fix[cartesian]: Fix higher dimensional field access in runtime-intervals#2553
twicki wants to merge 7 commits intoGridTools:mainfrom
twicki:fix_high_dim_intervals

Conversation

@twicki
Copy link
Copy Markdown
Contributor

@twicki twicki commented Mar 26, 2026

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: 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.

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.

Looks good in general. I just have a couple of questions inline for my understanding.

else:
higher_dim_offset = [self.visit(node.slice)]
literal_index = [
nodes.ScalarLiteral(value=i, data_type=nodes.DataType.INT32)
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.

Should we make this dependent on the literal precision?

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

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`
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.

I think we should enforce passing the literal_int_precision to the VerticalIntervalParser. Otherwise looks good to me.

axis_name: str,
fields: dict[str, nodes.FieldDecl],
loc: Optional[nodes.Location] = None,
literal_precision: Optional[int] = None,
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.

I think the literal precision shouldn't be optional and I would put it as a member of VerticalIntervalParser instead of IntervalParser because the member is unused in the HorizontalIntervalParser. Adding it as a required argument also allows you to avoid having literal precision default value in the interval parser.

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