Skip to content

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

Open
AayushSabharwal wants to merge 2 commits into
masterfrom
as/scimlprob-opts
Open

refactor: Convert *Problem constructors to accept SciMLProblemOptions#4901
AayushSabharwal wants to merge 2 commits 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.

@AayushSabharwal
AayushSabharwal force-pushed the as/scimlprob-opts branch 2 times, most recently from 52bd30c to 0732ad5 Compare August 12, 2026 13:18
@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Benchmark Results (Julia vlts)

Time benchmarks
master 7912043... master / 7912043...
ODEProblem 5.36 ± 0.18 ms 5.48 ± 0.25 ms 0.978 ± 0.056
init 0.068 ± 0.019 ms 0.0685 ± 0.018 ms 0.993 ± 0.39
large_parameter_init/ODEProblem 16.7 ± 0.79 ms 17.5 ± 0.82 ms 0.952 ± 0.064
large_parameter_init/init 0.0771 ± 0.024 ms 0.083 ± 0.023 ms 0.93 ± 0.38
mtkcompile 9.38 ± 0.32 ms 9.35 ± 0.42 ms 1 ± 0.056
sparse_analytical_jacobian/ODEProblem 19.1 ± 0.69 ms 19.2 ± 0.62 ms 0.993 ± 0.048
sparse_analytical_jacobian/f_iip 0.064 ± 0.001 μs 0.07 ± 0.001 μs 0.914 ± 0.019
sparse_analytical_jacobian/f_oop 0.376 ± 0.012 ms 0.379 ± 0.012 ms 0.992 ± 0.043
time_to_load 6.04 ± 0.071 s 6.05 ± 0.087 s 0.999 ± 0.019
Memory benchmarks
master 7912043... master / 7912043...
ODEProblem 0.0373 M allocs: 2.01 MB 0.0373 M allocs: 2.01 MB 1
init 0.433 k allocs: 0.0721 MB 0.433 k allocs: 0.0721 MB 1
large_parameter_init/ODEProblem 0.159 M allocs: 5.99 MB 0.159 M allocs: 5.99 MB 1
large_parameter_init/init 0.621 k allocs: 0.175 MB 0.621 k allocs: 0.175 MB 1
mtkcompile 0.059 M allocs: 3.34 MB 0.059 M allocs: 3.34 MB 1
sparse_analytical_jacobian/ODEProblem 0.115 M allocs: 5.55 MB 0.115 M allocs: 5.55 MB 1
sparse_analytical_jacobian/f_iip 0 allocs: 0 B 0 allocs: 0 B
sparse_analytical_jacobian/f_oop 0.634 k allocs: 19.6 kB 0.634 k allocs: 19.6 kB 1
time_to_load 0.153 k allocs: 14.5 kB 0.153 k allocs: 14.5 kB 1

@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Benchmark Results (Julia v1)

Time benchmarks
master 7912043... master / 7912043...
ODEProblem 3.72 ± 0.13 ms 3.74 ± 0.14 ms 0.993 ± 0.051
init 0.0346 ± 0.017 ms 0.0344 ± 0.018 ms 1.01 ± 0.73
large_parameter_init/ODEProblem 11.3 ± 2 ms 11.7 ± 1.4 ms 0.961 ± 0.21
large_parameter_init/init 0.057 ± 0.032 ms 0.0557 ± 0.027 ms 1.02 ± 0.75
mtkcompile 6.19 ± 0.3 ms 6.29 ± 0.49 ms 0.983 ± 0.09
sparse_analytical_jacobian/ODEProblem 13.2 ± 1.5 ms 14.6 ± 1.6 ms 0.908 ± 0.14
sparse_analytical_jacobian/f_iip 0.081 ± 0.01 μs 0.061 ± 0.01 μs 1.33 ± 0.27
sparse_analytical_jacobian/f_oop 0.0924 ± 0.011 ms 0.0925 ± 0.011 ms 0.999 ± 0.17
time_to_load 4.89 ± 0.027 s 4.94 ± 0.045 s 0.991 ± 0.011
Memory benchmarks
master 7912043... master / 7912043...
ODEProblem 0.0363 M allocs: 1.66 MB 0.0363 M allocs: 1.64 MB 1.01
init 0.436 k allocs: 0.0542 MB 0.436 k allocs: 0.0542 MB 1
large_parameter_init/ODEProblem 0.151 M allocs: 4.95 MB 0.151 M allocs: 4.95 MB 1
large_parameter_init/init 0.819 k allocs: 0.154 MB 0.819 k allocs: 0.154 MB 1
mtkcompile 0.0559 M allocs: 2.6 MB 0.0559 M allocs: 2.6 MB 1
sparse_analytical_jacobian/ODEProblem 0.115 M allocs: 4.6 MB 0.115 M allocs: 4.6 MB 1
sparse_analytical_jacobian/f_iip 0 allocs: 0 B 0 allocs: 0 B
sparse_analytical_jacobian/f_oop 0.848 k allocs: 27 kB 0.848 k allocs: 27 kB 1
time_to_load 0.145 k allocs: 11 kB 0.145 k allocs: 11 kB 1

AayushSabharwal and others added 2 commits August 14, 2026 14:48
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>
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