Skip to content

Precompile ODEProblem construction and DAE initialization in the MTK workloads - #5061

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:precompile-workloads
Sep 4, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:precompile-workloads

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Draft — please ignore until reviewed by @ChrisRackauckas.

What changed and why

The OrdinaryDiffEq extensions each carried a private copy of a 2-state linear ODE and only solved it; model construction sat in @setup_workload, outside the compiled block, and nothing exercised a mass-matrix DAE, an initialization problem with unknowns, or an explicit solver. Measured in a fresh session, the first MTK model paid ~12 s in ODEProblem (mtkcompile + codegen), ~3 s in init with Tsit5, and for a DAE with a real initialization problem 5–13 s in init and 2–14 s in solve!, none of it model-specific.

This PR adds one small model per initialization kind ModelingToolkit emits, built inside ModelingToolkit's own @compile_workload and solved from the extensions:

helper initialization kind it produces solved by
precompile_ode_problem trivial (NonlinearProblem, no unknowns); tunable parameters, an observed variable Default, Tsit5, Rodas5P, FBDF
precompile_dae_problem mass-matrix DAE, NonlinearProblem (one nonlinear unknown) Default, Rodas5P (+NonlinearSolve), FBDF
precompile_scc_dae_problem mass-matrix DAE, two-block SCCNonlinearProblem same
precompile_nlls_problem overdetermined initial conditions, NonlinearLeastSquaresProblem same
precompile_implicit_dae_problem implicit DAEProblem built the way MethodOfLines does (not mtkcompiled, build_initializeprob = false) DFBDF + BrownFullBasicInit (BDF ext)

An affine constraint is eliminated by mtkcompile, so a "linear initialization" model ends up trivial and is covered by the ODE. New extensions: MTKOrdinaryDiffEqTsit5Ext (explicit-solver path) and MTKOrdinaryDiffEqRosenbrockNonlinearSolveExt (triggered by OrdinaryDiffEqRosenbrock + OrdinaryDiffEqNonlinearSolve, because OverrideInit has no nonlinear solver until the latter loads and OrdinaryDiffEqRosenbrock does not depend on it). The helpers are @public because the QA ExplicitImports check requires extensions to use public names; they are documented on the internals page. The QA harness now loads the two new trigger packages so the new extensions are actually checked.

Verification

All numbers: x86-64, Julia 1.12.7, --startup-file=no, fresh process per row, OrdinaryDiffEq 7.8.1, master (22cb5b0a21) vs this branch Pkg.developed into the same environment. Timings on the branch were taken together with the CommonWorldInvalidations canary PR (SciML/CommonWorldInvalidations.jl#45); without it, using OrdinaryDiffEq invalidates the construction workload (see the section below) and only the init/solve! columns improve.

First model in a session, @timed compile seconds, models that are not the workload models:

model (initialization kind) master: ODEProblem / init / solve! branch
ODE, trivial, Tsit5 11.9 / 3.0 / 1.2 1.6 / 1.1 / 0.01
ODE, trivial, default alg – / 2.0 / 0.01 – / 1.0 / 0.01
DAE, NonlinearProblem init, Rodas5P / FBDF 17.3 / 5.3 / 4.4 · 1.7 / 2.2 2.2 / 0.6 / 0.01 · 0.04 / 0.01
DAE, 2-block SCC init, Rodas5P 17.3 / 12.8 / 4.4 1.4 / 2.4 / 0.14
DAE, least-squares init, Rodas5P / default 5.4 / 3.1 · 3.6 2.3 / 0.7 · 0.36
implicit DAEProblem (MethodOfLines shape), DFBDF 6.7 / 2.6 / 3.0 3.3 / 1.2 / 4.0*

* DFBDF still recompiles per state size because the chunk size is part of the nonlinear-solver cache type: SciML/OrdinaryDiffEq.jl#4458. Not fixable by a workload.

Per-solver init / solve! compile on the first model of each kind (branch): Tsit5 0.12 / 0.01, Rodas5P 0.1–0.7 / 0.01–0.11, FBDF 0.04–0.12 / 0.01, default algorithm 0.35–1.3 / 0.01. Second and later models in the same session are unchanged (≈1 s ODEProblem, ≈0.9 s init for an ODE); that is per-model specialization, which no workload can remove.

Extension precompile times (Pkg.precompile output, this machine): Rosenbrock 61 → 34 s (it now only solves the ODE), BDF 61 → 59 s, Default 69 → 77 s, new Tsit5 28 s, new RosenbrockNonlinearSolve 48 s.

Local checks before pushing:

  • Runic (julia -m Runic --check) and typos: clean on every touched file.
  • GROUP=QA on the final commit: 41 pass, 1 fail. All six extensions load (Extensions loaded | 6 6) and ExplicitImports/Aqua are clean for the new public names and extensions; the one failure is Aqua's persistent-tasks check, whose own fresh environment resolves AMD 0.5.4, which removed the unexported SS_Int that SparseColumnPivotedQR's extension used, so LinearSolve fails to precompile there. That breaks master the same way as of today; fix in Fix AMD extension for AMD.jl 0.5.4 (SS_Int removed) SparseColumnPivotedQR.jl#71. (The first QA run on the first commit failed all_qualified_accesses_are_public on the helpers, which is why they are @public.)
  • GROUP=InterfaceI on the first commit: InterfaceI | 1491 pass, 3 broken (pre-existing) | 49m21s.
  • Docs: docs/make.jl ran Doctest, ExpandTemplates, CrossReferences and CheckDocument without errors on the first commit, then aborted at linkcheck on a GitHub HTTP 429; a linkcheck = false build of the final commit is reported in a comment.

What is not fixed here

  • solve(prob) with the default algorithm on any mass-matrix problem was never despecialized at all: the resolved default is DefaultODEAlgorithm(autodiff = AutoFiniteDiff()), which sends concretization down DiffEqBase's non-ForwardDiff promote_f path, and that path refused to wrap problems whose mass matrix is not UniformScaling. Every MTK DAE therefore recompiled the whole composite solve (11–13 s) under the default algorithm regardless of workload. Fixed in DiffEqBase: DiffEqBase: wrap mass-matrix problems on the finite-difference promote_f path (default algorithm was never despecialized) OrdinaryDiffEq.jl#4459. With that, the default-algorithm rows above drop to the Rodas5P-like numbers.
  • N-block SCC initialization is per-N by type (NTuple{N}); a 3-block model still pays ~1.2 s in init with Rodas5P. Concretize initialization problems once at construction #5062 shares the block types so only the outer tuple specialization remains.
  • Without Add axes(::AbstractArray, ::Integer) canaries CommonWorldInvalidations.jl#45, using OrdinaryDiffEq after ModelingToolkit inserts Base.axes(::SparseMatrixColorings.SparsityPatternCSC, ::Integer), which invalidates 2,049 ModelingToolkit/ModelingToolkitBase/Symbolics instances (__mtkcompile, maybe_build_initialization_problem, process_SciMLProblem, …) through abstractly typed axes(A, d) call sites, so the construction part of this workload only survives with that PR (or with the redundant method removed upstream in SparseMatrixColorings).

Not verified

  • Initialization, Extensions, Downstream, FMI, Optimization groups and Julia 1.10 were not run locally.
  • Precompile-time cost on the 4 vCPU CI runners.

Reviewer notes

  • Five helpers are public only so the extensions can call them under the QA rules; they are documented under Internals and are not user API. The alternative is duplicating each model in five extensions.
  • The two-trigger extension is the honest way to get Rodas5P + OverrideInit into a pkgimage; solve(daeprob, Rodas5P()) inside the plain Rosenbrock extension throws OverrideInitMissingAlgorithm at precompile time.

Measurements and scripts: https://github.com/ChrisRackauckas/InternalJunk/issues/88

🤖 Generated with Claude Code (model: claude-fable-5-1)
https://claude.ai/code/session_01FeJYXni9MkJhPFA9yxYvfn

…loads

Add two small model constructors, `precompile_ode_problem` (tunable parameters,
an observed variable, trivial initialization) and `precompile_dae_problem`
(mass-matrix DAE with a nonlinear algebraic constraint, so `ODEProblem` builds
an SCC initialization problem), and use them in every workload. MTK's own
workload now runs `mtkcompile` + `ODEProblem` for both; the OrdinaryDiffEq
extensions solve them instead of each carrying its own copy of a 2-state ODE.

New extensions: `MTKOrdinaryDiffEqTsit5Ext` (explicit-solver path, previously
uncovered) and `MTKOrdinaryDiffEqRosenbrockNonlinearSolveExt`, which solves
the DAE with `Rodas5P` only once `OrdinaryDiffEqNonlinearSolve` is loaded,
since `OverrideInit` has no nonlinear solver without it.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Agent-Harness: Claude Code 2.1.259
Agent-Model: claude-fable-5-1
Agent-Session: https://claude.ai/code/session_01FeJYXni9MkJhPFA9yxYvfn
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 4, 2026 12:55
@ChrisRackauckas
ChrisRackauckas merged commit 109307e into SciML:master Sep 4, 2026
80 of 84 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 4, 2026
Re-cut as a minor. 11.40.1 never registered: its registration PR (JuliaRegistries/General#166107) has been open since 2026-08-26 carrying a failed AutoMerge verdict, and re-triggering updated the tree without producing a fresh evaluation. Moving to a new version leaves that stale PR behind.

Contents: precompile ODEProblem construction and DAE initialization in the MTK workloads (#5061).

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R
@ChrisRackauckas ChrisRackauckas mentioned this pull request Sep 4, 2026
ChrisRackauckas added a commit that referenced this pull request Sep 4, 2026
Re-cut as a minor. 11.40.1 never registered: its registration PR (JuliaRegistries/General#166107) has been open since 2026-08-26 carrying a failed AutoMerge verdict, and re-triggering updated the tree without producing a fresh evaluation. Moving to a new version leaves that stale PR behind.

Contents: precompile ODEProblem construction and DAE initialization in the MTK workloads (#5061).



Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude <[email protected]>
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Docs build of the final commit (0646cff8f5): docs/make.jl with linkcheck = false (the link check itself hits a GitHub HTTP 429 from this machine, unrelated), Julia 1.12.7. All stages ran:

[ Info: SetupBuildDirectory: setting up build directory.
[ Info: Doctest: running doctests.
[ Info: ExpandTemplates: expanding markdown templates.
[ Info: CrossReferences: building cross-references.
[ Info: CheckDocument: running document checks.
[ Info: Populate: populating indices.
[ Info: RenderDocument: rendering document.
[ Info: HTMLWriter: rendering HTML pages.

Rendered site: 58 HTML pages; docs/build/internals.html contains the five new entries (precompile_ode_problem, precompile_dae_problem, precompile_scc_dae_problem, precompile_nlls_problem, precompile_implicit_dae_problem). No docs errors.

🤖 Claude Code (model: claude-fable-5-1) — https://claude.ai/code/session_01FeJYXni9MkJhPFA9yxYvfn

ChrisRackauckas added a commit that referenced this pull request Sep 7, 2026
- qa: approve newly exported Symbolics API (#5050)
- Update redirected documentation links (#5054)
- qa: fix ModelingToolkitBase import checks (#5028)
- docs: replace stale Pantelides link (#5056)
- Precompile ODEProblem construction and DAE initialization in MTK workloads (#5061)
- Release 11.41.0 (#5069)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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