-
Notifications
You must be signed in to change notification settings - Fork 55
feat[next]: Embedded domain construction from dimension comparison #2532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
havogt
merged 9 commits into
GridTools:main
from
havogt:add_dim_operations_for_embedded
Mar 20, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
09dd736
feat[next]: Embedded domain construction from dimension comparison
havogt 5ec9bd3
remove tuple cases
havogt d62e51a
cleanup
havogt 9598eee
address review comments
havogt 7f6393d
simplify overloads
havogt 7205478
fix dimension comparison
havogt 991d93a
fix an assert doing wrong comparison with dimension
havogt 99a9935
Merge remote-tracking branch 'upstream/main' into add_dim_operations_…
havogt 08eaec3
cleanup type ignores
havogt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
docs/development/ADRs/next/0022-Limitations-of-embedded-concat_where.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| --- | ||
| tags: [] | ||
| --- | ||
|
|
||
| # Limitations of embedded concat_where | ||
|
|
||
| - **Status**: valid | ||
| - **Authors**: Hannes Vogt (@havogt) | ||
| - **Created**: 2026-03-12 | ||
| - **Updated**: 2026-03-17 | ||
|
|
||
| In embedded execution, `concat_where` is, for now, limited to simple but common cases. | ||
|
|
||
| We do not support `concat_where` in cases | ||
|
|
||
| - where the domain would be infinite and therefore can't be represented as an ndarray, e.g. `concat_where(I < 0, 0.0, somefield)` where the scalar 0.0 would be broadcasted to a field reaching to -infinity; | ||
| - with multi-dimensional domains, e.g. `concat_where(I > 0 | J > 0, a, b)`. These cases need to be represented by a nested `concat_where(I > 0, a, concat_where(J > 0, a, b))`; | ||
| - with non-contiguous (disjoint) domain conditions, e.g. `concat_where(I != 0, a, b)`. These cases need to be expressed using nested `concat_where`, e.g. `concat_where(I < 0, a, concat_where(I > 0, a, b))`. | ||
|
|
||
| ## Context | ||
|
|
||
| `concat_where` requires expressing conditions like `I != i`, which would produce two disjoint 1D domains (everything before index `i` and everything after). We need a way to represent these non-contiguous domains. | ||
|
|
||
| A complete implementation would require designing how to handle fields on non-hypercubic domains. Currently, `Domain` is a Cartesian product of per-dimension `UnitRange`s, which inherently describes hypercubic (rectangular) regions. Supporting arbitrary non-contiguous domains in multiple dimensions would mean fields could live on non-rectangular regions, requiring fundamental changes to field storage, slicing, and iteration. | ||
|
|
||
| ## Decision | ||
|
|
||
| Non-contiguous (disjoint) domains are **not supported** in the domain expression API: | ||
|
|
||
| - `Dimension.__ne__(value)` raises `NotImplementedError` when called with an integer value, since it would produce two disjoint domains. | ||
| - `Domain.__or__` raises `NotImplementedError` for both multidimensional domains and for 1D domains that are disjoint (non-overlapping and non-adjacent). | ||
|
|
||
| The domain expression API only supports operations that result in a single contiguous `Domain`. | ||
|
|
||
| ## Consequences | ||
|
|
||
| - `concat_where` with `I != i` must be rewritten as `concat_where(I < i, ..., concat_where(I > i, ..., ...))`. | ||
| - This keeps the domain expression API simple: all supported operations return a single `Domain`. | ||
|
|
||
| ## Alternatives considered | ||
|
|
||
| ### General `concat_where` with multi-dimensional domain conditions | ||
|
|
||
| Implementation for multi-dimensional domain conditions (e.g. `(I != 2) | (K != 5)`) and full support for domain operations in `concat_where` would require | ||
|
|
||
| 1. **A `DomainTuple` class** with full algebra: a `tuple` subclass carrying `__and__`, `__or__`, `__rand__`, `__ror__` operators so that expressions like `tuple & Domain`, `Domain & tuple`, and `tuple | tuple` all work. | ||
|
|
||
| 2. **Normalization of domain tuples**: We need to design `DomainTuple` invariants, e.g. | ||
|
|
||
| - Should all domains be promoted to the same rank (missing dimensions filled with infinite ranges)? | ||
| - Should we reduce overlapping domains to non-overlapping via box subtraction? | ||
|
|
||
| Before implementing a complex `DomainTuple`, we should conclude on (if we want) a concept of non-contiguous fields. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only place in the ADR where
contiguousis used. Everywhere elsenon-contiguousis used, is that on purpose?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah forgot to push the file, because my directory wasn't clean and my brain filtered .md files when adding stuff to commit...