Skip to content

feat[next]: Precompilation with static domains - #2483

Draft
SF-N wants to merge 18 commits into
GridTools:mainfrom
SF-N:static_domain_precompilation
Draft

SF-N wants to merge 18 commits into
GridTools:mainfrom
SF-N:static_domain_precompilation

Conversation

@SF-N

@SF-N SF-N commented Feb 17, 2026 •

Copy link
Copy Markdown
Contributor

Adds support for precompilation of programs with static domains.
Previously, static_domains=True was only usable in the JIT path, where field domains are available from the runtime arguments.
This change lets callers provide the static field domains explicitly during compile(), allowing the precompile path to construct the same FieldDomainDescriptor inputs that JIT compilation would normally derive from runtime fields.
static_domains is specified per field argument:

     program.compile(                                                                                                                                                        
         ...,                                                                                                                                                                
         static_domains={                                                                                                                                                    
             "inp": {IDim: (0, nx), JDim: (0, ny)},                                                                                                                          
             "out": {IDim: (1, nx - 1), JDim: (1, ny - 1)},                                                                                                                  
         },                                                                                                                                                                  
     )  

Tuple field arguments use indexed field expressions:

     static_domains={                                                                                                                                                        
         "out[0]": {IDim: (0, nx)},                                                                                                                                          
         "out[1]": {IDim: (0, nx)},                                                                                                                                          
     }  

Note that a consequence of this syntax is that it is not possible to have a parameter called static_domains and pass a static value to it, as static_domains is now a reserved keyword argument to compile().

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.

Pull request overview

Adds support for providing static domain ranges during ahead-of-time compilation so programs decorated with static_domains=True can be precompiled without needing runtime field instances.

Changes:

  • Extend CompiledProgramsPool.compile(...) to optionally construct FieldDomainDescriptor contexts from user-provided domain ranges.
  • Plumb a new static_domains argument through Program.compile(...) to the compiled-program pool.
  • Add an integration test covering precompilation with static domains for tuple arguments.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

File Description
tests/next_tests/integration_tests/feature_tests/ffront_tests/test_compiled_program.py Adjusts compilation parametrization and adds a new test for precompiling with provided static domains.
src/gt4py/next/otf/compiled_program.py Builds FieldDomainDescriptor argument descriptors from provided static domain ranges during precompilation.
src/gt4py/next/ffront/decorator.py Forwards a new static_domains argument through the public compile() API.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/gt4py/next/otf/compiled_program.py Outdated
Comment thread src/gt4py/next/otf/compiled_program.py Outdated
Comment thread src/gt4py/next/otf/compiled_program.py
Comment thread src/gt4py/next/ffront/decorator.py
Comment thread src/gt4py/next/ffront/decorator.py
@tehrengruber tehrengruber changed the title feat[next]: Add static_domains for pre-compilation feat[next]: Precompilation with static domains Feb 17, 2026
tehrengruber added a commit to tehrengruber/gt4py that referenced this pull request Feb 17, 2026
tehrengruber added a commit to tehrengruber/gt4py that referenced this pull request Feb 17, 2026
tehrengruber added a commit to tehrengruber/gt4py that referenced this pull request Feb 17, 2026
tehrengruber added a commit to tehrengruber/gt4py that referenced this pull request Feb 17, 2026

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 encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@SF-N
SF-N requested a review from Copilot February 20, 2026 14:41

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

)
),
}
if static_domains:

Copilot AI Feb 20, 2026

Copy link

Choose a reason for hiding this comment

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

static_domains is checked via truthiness (if static_domains:), so passing an empty dict (which is still a non-None value per the public API) will silently skip building FieldDomainDescriptors. This can lead to compiling a variant without any domain descriptors even though the caller explicitly provided static_domains. Consider switching this condition to if static_domains is not None: (and let _build_field_domain_descriptors raise for missing dims as needed).

Suggested change
if static_domains:
if static_domains is not None:

Copilot uses AI. Check for mistakes.
Comment thread src/gt4py/next/otf/compiled_program.py Outdated
Comment on lines +668 to +670
argument_descriptor_dict[arguments.FieldDomainDescriptor] = (
_build_field_domain_descriptors(self.program_type, static_domains) # type: ignore[assignment]
)

Copilot AI Feb 20, 2026

Copy link

Choose a reason for hiding this comment

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

There is a # type: ignore[assignment] on the FieldDomainDescriptor insertion because _build_field_domain_descriptors returns dict[str, FieldDomainDescriptor] while argument_descriptor_dict is typed as dict[str, ArgStaticDescriptor]. Consider widening the helper’s return type (e.g., to dict[str, arguments.ArgStaticDescriptor]) or casting at the assignment site to avoid relying on type: ignore here.

Copilot uses AI. Check for mistakes.
tehrengruber added a commit to tehrengruber/gt4py that referenced this pull request Mar 5, 2026
tehrengruber added a commit to tehrengruber/gt4py that referenced this pull request Mar 6, 2026
tehrengruber added a commit to tehrengruber/gt4py that referenced this pull request Mar 18, 2026
tehrengruber added a commit to tehrengruber/gt4py that referenced this pull request Apr 13, 2026
tehrengruber added a commit to tehrengruber/gt4py that referenced this pull request Apr 13, 2026
tehrengruber added a commit to tehrengruber/gt4py that referenced this pull request Apr 13, 2026
# Conflicts:
#	src/gt4py/next/otf/compiled_program.py
#	tests/next_tests/integration_tests/feature_tests/ffront_tests/test_compiled_program.py
tehrengruber added a commit to tehrengruber/gt4py that referenced this pull request Jul 29, 2026
@havogt

havogt commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Just dropping a few ideas to discuss:

  • I think tuples should just use normal tuple syntax, i.e. "out": ({IDim: (0, nx)}, {IDim: (0, nx)})
  • Not sure what to do in case of NamedCollections, maybe "out": {"x": {IDim: (0, nx)}, "y": {IDim: (0, nx)}

Just random thought:
class Point(NamedTuple):
x: Field
y: Field

"out": Domain[Point](x=domain1, y=domain2)

@havogt

havogt commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Feedback from a friend for discussion

static_domains=True also requires every scalar a domain depends on to be static. compute_rho_theta_pgrad_and_update_vn derives concat_where domains from start_edge/end_edge_/nflatlev; >when those stay runtime, domain inference asserts in domain_utils._unstructured_translate_range_statically (assert isinstance(start_expr, itir.Literal)) instead of falling back to the max-domain path the @program form used. So compile-time domains are all-or-nothing with the scalars that shape them — I now gate static_domains on the compile_time_domain variant. A corollary: the compile_time_vertical variant (vertical bounds static, horizontal dynamic) is not expressible for a direct call, since static_domains is a single per-program flag.

@havogt

havogt commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

And do we actually need to provide input sizes as well? Why?

tehrengruber added a commit to tehrengruber/gt4py that referenced this pull request Sep 24, 2026
tehrengruber added a commit to tehrengruber/gt4py that referenced this pull request Oct 15, 2026

This branch has not been deployed

No deployments
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