-
Notifications
You must be signed in to change notification settings - Fork 55
feat[next]: Precompilation with static domains #2483
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
dc6dbb7
c3e0453
46a855e
57db00a
694d927
bf02bb8
c2d0e9d
3b6c14d
9bc34cd
bb49222
5a5adf5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |||||
| import itertools | ||||||
| import warnings | ||||||
| from collections.abc import Callable, Hashable, Sequence | ||||||
| from typing import Any, Generic, TypeAlias, TypeVar | ||||||
| from typing import Any, Generic, Optional, TypeAlias, TypeVar | ||||||
|
|
||||||
| from gt4py._core import definitions as core_defs | ||||||
| from gt4py.eve import extended_typing as xtyping, utils as eve_utils | ||||||
|
|
@@ -28,7 +28,7 @@ | |||||
| ) | ||||||
| from gt4py.next.instrumentation import hook_machinery, metrics | ||||||
| from gt4py.next.otf import arguments, stages | ||||||
| from gt4py.next.type_system import type_specifications as ts | ||||||
| from gt4py.next.type_system import type_info, type_specifications as ts | ||||||
| from gt4py.next.utils import tree_map | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -605,6 +605,7 @@ def _compile_variant( | |||||
| def compile( | ||||||
| self, | ||||||
| offset_providers: list[common.OffsetProvider | common.OffsetProviderType], | ||||||
| static_domains: Optional[dict[common.Domain, int] | None] = None, | ||||||
SF-N marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| **static_args: list[ScalarOrTupleOfScalars], | ||||||
| ) -> None: | ||||||
| """ | ||||||
|
|
@@ -619,17 +620,43 @@ def compile( | |||||
| pool.compile(static_arg0=[0], static_arg1=[2]).compile(static_arg=[1], static_arg1=[3]) | ||||||
| will compile for (0,2), (1,3) | ||||||
| """ | ||||||
|
|
||||||
| def _build_field_domain_descriptors(program_type, static_domains): | ||||||
| def _create_field_descriptor(field_type): | ||||||
| domain_ranges = { | ||||||
| dim: static_domains[dim] for dim in field_type.dims | ||||||
| } # TODO: improve error message | ||||||
| return arguments.FieldDomainDescriptor(common.domain(domain_ranges)) | ||||||
|
|
||||||
| field_domain_descriptors = {} | ||||||
| for arg_name, arg_type_ in program_type.definition.pos_or_kw_args.items(): | ||||||
| for el_type_, path in type_info.primitive_constituents( | ||||||
| arg_type_, with_path_arg=True | ||||||
| ): | ||||||
| if isinstance(el_type_, ts.FieldType): | ||||||
SF-N marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| path_as_expr = "".join(map(lambda idx: f"[{idx}]", path)) | ||||||
| field_domain_descriptors[f"{arg_name}{path_as_expr}"] = ( | ||||||
| _create_field_descriptor(el_type_) | ||||||
| ) | ||||||
|
|
||||||
| return field_domain_descriptors | ||||||
|
|
||||||
| for offset_provider in offset_providers: # not included in product for better type checking | ||||||
| for static_values in itertools.product(*static_args.values()): | ||||||
| argument_descriptor_dict = { | ||||||
| arguments.StaticArg: dict( | ||||||
| zip( | ||||||
| static_args.keys(), | ||||||
| [arguments.StaticArg(value=v) for v in static_values], | ||||||
| strict=True, | ||||||
| ) | ||||||
| ), | ||||||
| } | ||||||
| if static_domains: | ||||||
|
||||||
| if static_domains: | |
| if static_domains is not None: |
SF-N marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Feb 20, 2026
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.
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.
Uh oh!
There was an error while loading. Please reload this page.