Skip to content

Conversation

@tehrengruber
Copy link
Contributor

@tehrengruber tehrengruber commented Feb 5, 2026

The following snippet broke after #2368

prg1 = prog.with_backend(gtfn.run_gtfn)
prg2 = prog.with_backend(gtfn.run_gtfn)

# compile with static args
prg1.compile(cond=[True], offset_provider={})

# compile without static args
prg2.compile(offset_provider={})

with the following error

ValueError: Argument descriptor StaticArg must be the same for all compiled programs, got [] expected ['cond'].

This PR avoids using object.__setattr__ on the CompilationOptions to pass information to the compiled program pool construction and instead explicitly constructs the pool on compile.

Note that the enable_jit argument to compile has been removed and replaced by:

prg.with_compilation_option(enable_jit=...)

as the same object.__setattr__ mechanism was used to pass the information.

Copy link
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

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

It looks good. Just some typos questions and code suggestions. It should be approved in the next round.

#: If the user requests static params, they will be used later to initialize CompiledPrograms.
#: By default the set of static params is set when compiling for the first time, e.g. on call
#: when jitting is enabled, or on a call to `compiled`.
static_params: Sequence[str] | None = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: wouldn't it be simpler to just default to an empty tuple?

Suggested change
static_params: Sequence[str] | None = None
static_params: Sequence[str] = ()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I first changed it to be (), but I found it hard to understand under which circumstances it is ok for this value to be different than what is inside the compiled programs pool. I therefore went back to None here and set the value to () in _compiled_programs when the value is actually selected. I'll change it back when you like.

else:
assert all(p is not None for p in static_params)
_static_params = typing.cast(tuple[str], static_params)
_static_params = typing.cast(tuple[str, ...], static_params)
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: do you understand why the cast is used/needed here after the assert?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unclear:

error: Incompatible types in assignment (expression has type "tuple[str | None, ...]", variable has type "tuple[str, ...]")

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I get it. mypy does not understand the all() inside the assert. A custom typeguard would be needed here, but it can be done in a different PR.

def with_connectivities(
self,
connectivities: common.OffsetProvider, # TODO(ricoh): replace with common.OffsetProviderType once the temporary pass doesn't require the runtime information
def with_compilation_option(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def with_compilation_option(
def with_compilation_options(

or compile_options() I don't care

Copy link
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

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

LGTM

@tehrengruber tehrengruber merged commit a4edab0 into GridTools:main Feb 6, 2026
23 checks passed
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