Skip to content

Commit 16ef998

Browse files
Pass an options struct to the generated map builders
The two `FullSpecialize` map builders forwarded `kwargs...` into `build_explicit_observed_function`, which routed through the keyword compat shim and funnelled whatever was left in the bag into a fresh `CodegenFunctionOptions`. Take a `GeneratedFunctionOptions` instead and call the struct method directly. `_fullspecialize_map_options` derives it from the problem's own `opts.fn_opts.codegen`, so the maps now inherit the same `checkbounds`/`cse` settings the rest of the problem was built with rather than whatever happened to survive in `kwargs`, while still emitting an `Expr` and compiling under `init_compiler_options`. `eval_expression` is now honoured too; previously the generated maps ignored it and were always `RuntimeGeneratedFunction`s, unlike the default map path. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Agent-Harness: Claude Code 2.0.14 Agent-Model: claude-opus-5[1m] Agent-Session: https://claude.ai/code/session_01GdSpCLd7NBZuuePJmcDzU7 Claude-Session: https://claude.ai/code/session_01GdSpCLd7NBZuuePJmcDzU7
1 parent b8c603d commit 16ef998

1 file changed

Lines changed: 33 additions & 22 deletions

File tree

‎lib/ModelingToolkitBase/src/systems/problem_utils.jl‎

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,13 +1674,11 @@ function _generated_map_sources(valp::Symbol, time_dependent::Bool)
16741674
end
16751675

16761676
function _construct_fullspecialize_initializeprobmap(
1677-
initsys::AbstractSystem, solved_unknowns;
1678-
iip::Bool, u0_constructor, floatT, eval_module,
1679-
compiler_options::CompilerOptions = CompilerOptions(), kwargs...
1677+
initsys::AbstractSystem, solved_unknowns, gen_opts::GeneratedFunctionOptions;
1678+
iip::Bool, u0_constructor, floatT
16801679
)
16811680
expr = build_explicit_observed_function(
1682-
initsys, solved_unknowns;
1683-
expression = Val(true), output_type = SVector, compiler_options, kwargs...
1681+
initsys, solved_unknowns, gen_opts; output_type = SVector
16841682
)
16851683
sol = INITMAP_SOLUTION
16861684
sources = _generated_map_sources(sol, is_time_dependent(initsys))
@@ -1701,7 +1699,9 @@ function _construct_fullspecialize_initializeprobmap(
17011699
end
17021700
return Expr(:block, :(local $T = $promoted), result)
17031701
end
1704-
return eval_or_rgf(map_expr; eval_module, compiler_options)
1702+
return eval_or_rgf(
1703+
map_expr; gen_opts.eval_expression, gen_opts.eval_module, gen_opts.compiler_options
1704+
)
17051705
end
17061706

17071707
function _static_initialization_buffer(prototype, values)
@@ -1729,9 +1729,8 @@ function _parameter_buffer_expr(prototype, raw::Symbol, idxs, p_constructor)
17291729
end
17301730

17311731
function _construct_fullspecialize_initializeprobpmap(
1732-
sys::AbstractSystem, initsys::AbstractSystem;
1733-
p_constructor, eval_module,
1734-
compiler_options::CompilerOptions = CompilerOptions(), kwargs...
1732+
sys::AbstractSystem, initsys::AbstractSystem, gen_opts::GeneratedFunctionOptions;
1733+
p_constructor
17351734
)
17361735
ps = parameters(sys; initial_parameters = true)
17371736
# One entry per `MTKParameters` portion, each holding that portion's buffers. Kept a
@@ -1754,10 +1753,7 @@ function _construct_fullspecialize_initializeprobpmap(
17541753
for group in groups, buffer in group
17551754
append!(flat_syms, buffer)
17561755
end
1757-
expr = build_explicit_observed_function(
1758-
initsys, Tuple(flat_syms);
1759-
expression = Val(true), compiler_options, kwargs...
1760-
)
1756+
expr = build_explicit_observed_function(initsys, Tuple(flat_syms), gen_opts)
17611757
prob = INITMAP_PROBLEM
17621758
sol = INITMAP_SOLUTION
17631759
sources = _generated_map_sources(sol, is_time_dependent(initsys))
@@ -1807,7 +1803,9 @@ function _construct_fullspecialize_initializeprobpmap(
18071803
push!(result.args, :($map($copy, $outer_p.caches)))
18081804
return Expr(:block, :(local $outer_p = $p), result)
18091805
end
1810-
return eval_or_rgf(map_expr; eval_module, compiler_options)
1806+
return eval_or_rgf(
1807+
map_expr; gen_opts.eval_expression, gen_opts.eval_module, gen_opts.compiler_options
1808+
)
18111809
end
18121810

18131811
"""
@@ -2065,6 +2063,23 @@ function SciMLProblemOptions(
20652063
)
20662064
end
20672065

2066+
"""
2067+
$(TYPEDSIGNATURES)
2068+
2069+
Code-generation options for the `FullSpecialize` initialization maps. Reuses the
2070+
problem's own codegen settings so the maps see the same `checkbounds`/`cse`/... the
2071+
rest of the problem was built with, but emits an `Expr` and compiles it under the
2072+
initialization system's `CompilerOptions`.
2073+
"""
2074+
function _fullspecialize_map_options(opts::SciMLProblemOptions)
2075+
codegen = opts.fn_opts.codegen
2076+
return GeneratedFunctionOptions(;
2077+
expression = Val{true}, codegen.eval_expression, codegen.eval_module,
2078+
compiler_options = opts.init_compiler_options,
2079+
codegen_function_options = codegen.codegen
2080+
)
2081+
end
2082+
20682083
"""
20692084
$(TYPEDSIGNATURES)
20702085
@@ -2091,7 +2106,7 @@ function maybe_build_initialization_problem(
20912106
warn_cyclic_dependency, circular_dependency_max_cycle_length,
20922107
circular_dependency_max_cycles, initsys_mtkcompile_kwargs, use_scc,
20932108
time_dependent_init, algebraic_only, missing_guess_value, allow_incomplete,
2094-
is_steadystateprob, init_compiler_options,
2109+
is_steadystateprob,
20952110
) = opts
20962111
(; eval_expression, eval_module) = opts.fn_opts.codegen
20972112

@@ -2175,10 +2190,8 @@ function maybe_build_initialization_problem(
21752190
initializeprobmap = nothing
21762191
elseif map_specialize === SciMLBase.FullSpecialize
21772192
initializeprobmap = _construct_fullspecialize_initializeprobmap(
2178-
initializeprob.f.sys, solved_unknowns;
2179-
iip, u0_constructor, floatT, eval_module,
2180-
compiler_options = init_compiler_options,
2181-
kwargs...
2193+
initializeprob.f.sys, solved_unknowns, _fullspecialize_map_options(opts);
2194+
iip, u0_constructor, floatT
21822195
)
21832196
else
21842197
initializeprobmap = InitializationMap{iip}(
@@ -2205,9 +2218,7 @@ function maybe_build_initialization_problem(
22052218
initializeprobpmap = nothing
22062219
elseif map_specialize === SciMLBase.FullSpecialize
22072220
initializeprobpmap = _construct_fullspecialize_initializeprobpmap(
2208-
sys, initsys;
2209-
p_constructor, eval_module, compiler_options = init_compiler_options,
2210-
kwargs...
2221+
sys, initsys, _fullspecialize_map_options(opts); p_constructor
22112222
)
22122223
else
22132224
initializeprobpmap = construct_initializeprobpmap(

0 commit comments

Comments
 (0)