Skip to content

refactor: Convert *Problem constructors to accept SciMLProblemOptions - #4901

Open
AayushSabharwal wants to merge 1 commit into
masterfrom
as/scimlprob-opts
Open

refactor: Convert *Problem constructors to accept SciMLProblemOptions#4901
AayushSabharwal wants to merge 1 commit into
masterfrom
as/scimlprob-opts

Conversation

@AayushSabharwal

Copy link
Copy Markdown
Member

Extends the SciMLFunctionOptions options-struct pattern (already applied to *Function constructors) down through DiscreteProblem, ImplicitDiscreteProblem, IntervalNonlinearProblem, DAEProblem, ODEProblem, SteadyStateProblem, SDEProblem, DDEProblem, SDDEProblem, NonlinearProblem, NonlinearLeastSquaresProblem, HomotopyProblem, OptimizationProblem, BVProblem, and LinearProblem: each now has a public (sys, op, tspan, opts::SciMLProblemOptions) entry point alongside its kwargs-based wrapper.

__process_SciMLProblem gains an options_struct = Val(true) mode that calls the target *Function's own opts-accepting method directly instead of its permissive kwargs wrapper, fixing a latent bug where a *Problem constructor naming a SciMLFunctionOptions field explicitly (e.g. sparse) would consume it out of the kwargs pass-through before it reached the inner *Function (concretely: LinearProblem(...; sparse = true) never reached LinearFunction). Since the opts-accepting methods have no such catch-all, bespoke keywords that used to ride through harmlessly (steady_state, seed, noise, constant_lags, checkvars, _skip_tstops, ...) are now explicitly intercepted at each call site and either discarded or re-merged into the final constructor call as needed.

Also: BVProblem now stores check_compatibility/t in the options struct itself (via a new shared maybe_derive_t_from_tspan helper) rather than as bespoke keywords; removes the unused cse keyword from HomotopyProblem; fixes constant_lags on DDEProblem/SDDEProblem to resolve symbolic parameter references against the built p instead of silently dropping them; and removes the now-unnecessary kwargs... from maybe_build_initialization_problem, closing off a path where bespoke keywords could leak into the initialization subproblem's own Function construction.

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

Add any other context about the problem here.

Extends the SciMLFunctionOptions options-struct pattern (already applied to
*Function constructors) down through DiscreteProblem, ImplicitDiscreteProblem,
IntervalNonlinearProblem, DAEProblem, ODEProblem, SteadyStateProblem,
SDEProblem, DDEProblem, SDDEProblem, NonlinearProblem,
NonlinearLeastSquaresProblem, HomotopyProblem, OptimizationProblem, BVProblem,
and LinearProblem: each now has a public `(sys, op, tspan, opts::SciMLProblemOptions)`
entry point alongside its kwargs-based wrapper.

`__process_SciMLProblem` gains an `options_struct = Val(true)` mode that calls
the target `*Function`'s own opts-accepting method directly instead of its
permissive kwargs wrapper, fixing a latent bug where a `*Problem` constructor
naming a `SciMLFunctionOptions` field explicitly (e.g. `sparse`) would
consume it out of the kwargs pass-through before it reached the inner
`*Function` (concretely: `LinearProblem(...; sparse = true)` never reached
`LinearFunction`). Since the opts-accepting methods have no such catch-all,
bespoke keywords that used to ride through harmlessly (`steady_state`,
`seed`, `noise`, `constant_lags`, `checkvars`, `_skip_tstops`, ...) are now
explicitly intercepted at each call site and either discarded or re-merged
into the final constructor call as needed.

Also: BVProblem now stores `check_compatibility`/`t` in the options struct
itself (via a new shared `maybe_derive_t_from_tspan` helper) rather than as
bespoke keywords; removes the unused `cse` keyword from HomotopyProblem;
fixes `constant_lags` on DDEProblem/SDDEProblem to resolve symbolic parameter
references against the built `p` instead of silently dropping them; and
removes the now-unnecessary `kwargs...` from `maybe_build_initialization_problem`,
closing off a path where bespoke keywords could leak into the initialization
subproblem's own Function construction.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
args = (; f, u0, p)

maybe_codegen_scimlproblem(expression, SteadyStateProblem{_iip}, args; kwargs...)
maybe_codegen_scimlproblem(Val{E}, SteadyStateProblem{_iip}, args; kwargs...)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[Runic] reported by reviewdog 🐶

Suggested change
maybe_codegen_scimlproblem(Val{E}, SteadyStateProblem{_iip}, args; kwargs...)
return maybe_codegen_scimlproblem(Val{E}, SteadyStateProblem{_iip}, args; kwargs...)

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.

1 participant