Repository navigation
Keep array equations through the compiled ODEProblem path - #688
ChrisRackauckas-Claude wants to merge 1 commit into
Conversation
`discretize` preserves the array (slice-form) equations by building a `DAEProblem` without `mtkcompile`, but the `ODEProblem` path needed by explicit Runge-Kutta methods still went through the scalarizing `mtkcompile`, so its compile time grew with the grid. ModelingToolkit can now keep array equations through compilation with `mtkcompile(sys; scalarize_arrays = false)`. Add `ode_compile(sys)`, which uses that when available and yields an explicit ODE, and falls back to the default `mtkcompile` otherwise (older ModelingToolkit, systems second order in time). Route `_ode_problem`, `ODEFunction` and `ODEFunctionExpr` through it, and add an `ODEProblem(pdesys, discretization)` constructor so the compiled path no longer needs `symbolic_discretize` by hand. Tests check that the compiled `ODEProblem` for the heat equation has one equation and a system size independent of the grid resolution (11 to 81 points), solves to second order accuracy with `Tsit5`, and that the wave equation falls back to scalarization. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Closing: this PR is built on What replaces it, in two steps:
The |
|
Checkpoint note: this PR still depends on the rejected Preferred stack going forward:
Please treat this MOL PR as needing a rewrite once those land (or close and reopen). Status doc: https://github.com/ChrisRackauckas-Claude/ModelingToolkit.jl/blob/array-aware-tearing/docs/src/internals/ARRAY_EQUATIONS_CHECKPOINT.md |
Summary
discretizepreserves the array (slice-form) equations by building aDAEProblemwithoutmtkcompile, but theODEProblempath needed by explicit Runge–Kutta methods (Tsit5,SSPRK54, ...) still went through the scalarizingmtkcompile, so its compile time grew with the grid.ModelingToolkit can now keep array equations through compilation with
mtkcompile(sys; scalarize_arrays = false)(SciML/ModelingToolkit.jl#5100 and SciML/ModelingToolkit.jl#5101). This PR uses that for the compiledODEProblempath, so the same O(1) examples work forODEProblem.What changes
ode_compile(sys)(exported):mtkcompile(sys; scalarize_arrays = false)when the installed ModelingToolkit supports it and the result is an explicit ODE (every remaining equation isD(x) ~ f); otherwise the defaultmtkcompile. The fallback covers older ModelingToolkit versions (detected withisdefined(ModelingToolkitBase, :arrays_scalarized)) and systems the tearing-free compiler cannot make explicit (second order in time, coupled algebraic equations)._ode_problem,ODEFunctionandODEFunctionExprgo throughode_compile.ODEProblem(pdesys, discretization; kwargs...)constructor, so the compiled path no longer requiressymbolic_discretize+mtkcompileby hand.MOLFiniteDifference.md,index.md,howitworks.md, FAQ, tutorials) no longer say the ODE path always scalarizes, and useode_compile/ODEProblem(pdesys, disc). NEWS entry for 1.5; version bumped to 1.5.0.Tests
test/Discretization/problem_construction.jl:ODEProblem(pdesys, disc)for the 1D heat equation solves withTsit5to the analytic solution;n - 2unknowns,mass_matrix === I, second-order accuracy, and — when ModelingToolkit preserves array equations — exactly one equation with a symbolic tree size independent ofn. With an older ModelingToolkit the test instead asserts the scalarized shape, so CI passes with the current release too;Run locally against the ModelingToolkit branches above:
problem_construction.jl81/81 pass (with the released ModelingToolkit the fallback branch of the tests is exercised).How to verify the O(1) scaling
Depends on SciML/ModelingToolkit.jl#5100 and SciML/ModelingToolkit.jl#5101 for the preserved path; degrades to the previous behaviour without them.
Made with Cursor