Repository navigation
Conversation
The AbstractDict method of evaluate_varmap! maps every element of an array variable to the array and substitutes the whole array, but it did so once per element. DAEProblem builds du0 from one D(u[i]) per scalar unknown, so its construction was quadratic in the array length. Skip arrays already visited. Agent-Harness: Claude Code 2.1.299 Agent-Model: claude-opus-5-5 Agent-Session: 644ed0ff-c8c9-4cc3-b4c6-f326231a4030 Agent-Review: unreviewed Co-authored-by: Claude Code <[email protected]>
xtalax
marked this pull request as ready for review
October 19, 2026 19:29
Member
Author
|
Closing in favour of #5190, which fixes the same quadratic One data point for #5190: a 46k-state MethodOfLines 2D TM DAE, where 🤖 Posted by an AI agent · harness: Claude Code 2.1.304 · model: claude-opus-5-5 |
This was referenced Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Constructing a
DAEProblemfor a system with a large array unknown takes time quadratic in the array length. This PR makes it linear: on a simple 46k-state array DAE, construction drops from 394 s and 316 GiB allocated to 2.6 s and 1.2 GiB.Cause
__process_SciMLProblemwithimplicit_daebuildsdu0withvarmap_to_vars(op, ddvs), whereddvsholds oneD(u[i])per scalar unknown and noiris passed. That selects theAbstractDictmethod ofevaluate_varmap!. For each scalar key it callssplit_indexed_varand then works on the whole array:get(varmap, arr)on theAtomicArrayDictSubstitutionWrapperscans every element for holes, andfixpoint_subthen substitutes the whole array value. Doing this once per element costs O(N²) for an array of length N.Change
evaluate_varmap!(::AbstractDict, vars)now records each array it has processed in aSetand skips it when another element of the same array comes up. Scalar variables map to themselves undersplit_indexed_var, so they are visited exactly once as before.The result is unchanged. Once an array value has been substituted to a fixpoint, substituting it again returns the same value, so the repeated passes did no useful work. The one case where they differed is a substitution that does not converge within
limit: before, an array was resubstituted up tolimittimes per element; now it is resubstituted up tolimittimes in total, which matches whatsubstitution_limitdocuments. Arrays that are only partly present in the varmap behave as before, becausegeton an array with holes returns nothing in both versions and the missing entries are reported in the same way. TheIRStructuremethod, used foru0, is not touched.Benchmark
DAEProblem(sys, op, (0.0, 1.0); build_initializeprob = false)forD(u) ~ -b .* uwithu(t)[1:n]plus one scalar unknown,opgivingD(u) => -b .* u. Times are for a warm call (compilation excluded), Julia 1.12.6.A log-log fit of time against state count gives an exponent of 2.05 before the change (3k to 46k, including a 3k point at 1.46 s and 1.41 GiB) and 1.13 after it (12k to 183k). For allocations the exponents are 1.98 before and 1.08 after. The 183k case was not run before the change; extrapolating the fit puts it at about 6600 s, which is an estimate, not a measurement.
This was found while building large MethodOfLines.jl systems (a 46M-state 2D FDTD discretization), where
du0construction dominated problem setup.Tests
Two testsets are added to
test/array_equation_dae.jl:DAEProblemwith an array unknown, a scalar unknown and two parameters, where the varmap gives symbolic values that chain through other entries (D(u[i]) => b * u[i] + D(w),D(w) => b * w,b => 2c,u => w .* (1:n)). It checksu0anddu0against hand-computed values, so it exercises the fixpoint substitution and not just constant values.DAEProblemconstruction atn = 500andn = 2000. The ratio is 3.9 with this change and 14.4 without it; the test requires it to be below 8. It counts bytes rather than wall-clock time, so it is not sensitive to machine load.array_equation_dae.jl,initial_values.jl,sciml_problem_inputs.jl,initializationsystem.jlandodesystem.jlpass locally (the only non-passing results are the existing@test_brokens). The complexity guard fails on current master, as expected.🤖 Posted by an AI agent · harness: Claude Code 2.1.299 · model: claude-opus-5-5
Review: unreviewed
Session: 644ed0ff-c8c9-4cc3-b4c6-f326231a4030