Skip to content

Support array unknowns in initialized DAE constructors - #5144

Draft
ChrisRackauckas-Claude wants to merge 2 commits into
SciML:array-dae-jacobian-residualsfrom
ChrisRackauckas-Claude:feat/dae-array-constructors
Draft

ChrisRackauckas-Claude wants to merge 2 commits into
SciML:array-dae-jacobian-residualsfrom
ChrisRackauckas-Claude:feat/dae-array-constructors

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

DAEProblem and DAEFunction now accept whole-array entries in unknowns(complete(sys)) with initialization enabled. Numerical states, derivatives, initialization updates, differential masks, and generated function arguments use a flat column-major layout; symbolic indexing retains array shapes. The existing DAE residual Jacobian machinery now differentiates with respect to those scalar entries.

This is an upstream prerequisite for SciML/MethodOfLines.jl#695. ModelingToolkitBase's minor version increases to 1.72.0, and the completed-system array DAE path is documented with an executable example.

Dependencies

This draft builds on #5136 and includes the initialization fix from #5132. Symbolic remake additionally requires SciML/SciMLBase.jl#1602. The local validation environment develops that exact SciMLBase patch; its first containing release must become the SciMLBase compatibility minimum before this feature is merged.

Regression evidence

The same official array_unknowns_dae.jl runs against the prerequisite stack with and without the constructor change. Before, both vector and matrix cases error in SetInitialUnknowns, which expects scalar initial-parameter indices:

TypeError: in typeassert, expected ModelingToolkitBase.ParameterIndex{SciMLStructures.Initials, Int64}, got a value of type ModelingToolkitBase.ParameterIndex{SciMLStructures.Initials, UnitRange{Int64}}
Test Summary:      | Error  Total     Time
DAE array unknowns |     2      2  1m44.1s
  shape (3,)       |     1      1  1m38.0s
  shape (2, 3)     |     1      1     6.0s
TMPDIR="$PWD/tmp" JULIA_PKG_PRECOMPILE_AUTO=0 julia +1.12 --compiled-modules=existing --project=dae_constructor_before_env -e 'using SciMLBase, Test; include("mtk-dae-array-constructors/lib/ModelingToolkitBase/test/array_unknowns_dae.jl")'

After, the final production source passes all 154 focused checks on Julia 1.10.12 with minimum dependency versions:

Array derivative initialization |    6      6  2m15.8s
Array DAE Unknowns              |   52     52    52.0s
Array unknown DAE Jacobians     |   96     96    10.5s
TMPDIR="$PWD/tmp" JULIA_PKG_PRECOMPILE_AUTO=0 julia +1.10.12 --project=array_constructors_downgrade_env array_constructors_downgrade_tests.jl

The script runs the official array_initialization.jl, array_unknowns_dae.jl, and array_unknowns_dae_jacobian.jl files in separate SafeTestsets. All dependencies are pinned to the downgrade CI versions except the intended MTKBase and SciMLBase source replacements: Symbolics 7.37.0, SymbolicUtils 4.37.0, NonlinearSolveBase 2.49.4, OrdinaryDiffEqBDF 2.0.0, and SymbolicIndexingInterface 0.3.46.

That environment also exposed an integer-index bound error: is_variable(sys, i) counted parent symbols instead of numerical states. Completed systems now cache the numerical count; systems without a cache compute it from the unknown lengths. In a separate process, restoring only the original is_variable method with Base.include_string makes the earlier 46-assertion official file report 34 passes, 4 failed bounds assertions, and 8 indexing errors. The production method passed all 46 assertions in that control; the final expanded file passes 52/52. This control uses a runtime method override, not a clean-base checkout.

The constructor test covers two arrays separated by a scalar algebraic unknown, vector and matrix shapes, flat u0/du0/masks, shaped symbolic indexing, residual values, DFBDF solutions against analytic exponentials, and symbolic remake. Initialization infers array derivative initial values and computes algebraic array states from guesses. The Jacobian cases cover scalar/array unknown and equation representations, algebraic constraints, dense/sparse and analytic/numerical modes, and in-place/out-of-place evaluation.

The equivalent six-point heat model written with scalar differential equations isolates an additional constructor initialization bug without either slice prerequisite. Before the final bookkeeping correction it errors with missing interior derivative values:

Initial condition underdefined. Some are missing from the variable map.
(uˍt(t))[2], (uˍt(t))[3], (uˍt(t))[5], (uˍt(t))[4]
Heat equation with array unknown and scalar differential equations | Error 1/1 | 1m49.1s

Canonicalizing supplied derivative keys before filling inferred scalar derivative entries preserves boundary values and allows the interior values to be populated. In the isolated combined stack, that same test passes 6/6, the array-slice version passes 6/6, and all 46 earlier constructor checks pass. The scalar-equation case is now included in the official constructor test file.

Full validation

Final production source, normal Pkg.test("ModelingToolkitBase") runs on Julia 1.12.7, using --project=dae_constructor_env and each named GROUP:

Initialization: 825 passed, 12 pre-existing broken (1733.468702 seconds)
  Array derivative initialization: 6/6
  Array DAE Unknowns: 52/52
  Guess Propagation: 11/11
  InitializationSystem: 691 passed, 12 pre-existing broken
  Initial Values: 65/65
SymbolicIndexingInterface: 2059 passed (561.158999 seconds)
InterfaceI: 1777 passed, 5 pre-existing broken (2970.417340 seconds)
QA: JET 54/54; Aqua 20 passed, 1 failed

QA's only failure is the 234 existing Moshi unbound type-parameter reports tracked at #5063 (182 And, 52 Call). The separate clean-base investigation reproduces the same reports, and the upstream Moshi patch removes all 234. No QA assertion was changed.

Final InterfaceII validation completed: 7435 passed, 2 pre-existing broken; Testing ModelingToolkitBase tests passed, exit confirmed by the official harness completion message. The normal julia +1.12 --project=docs docs/make.jl build completed with exit 0: executable examples, doctests, strict document checks, link checking, and HTML rendering passed. Local deployment was skipped.

Runic, typos over the diff, and git diff --check pass. No new dependency is added.

The direct six-point heat-equation slice reproducer exposed two additional upstream prerequisites: Symbolics derivative renaming rejects array slices, and initialization guess writes assume scalar indices. The Symbolics fix is proposed at JuliaSymbolics/Symbolics.jl#1986; the initialization slice-write fix is proposed at #5143. With both slice fixes developed locally, the direct six-point heat system passes 6/6 with initialization enabled: flat states and inferred derivatives, differential mask, successful DFBDF solve, and the analytic discrete heat solution. A further probe wrapping the derivative in broadcast(+, 0, D(u[2:5])), matching the kind of residual MethodOfLines emits, still fails because the derivative remains in the time-independent initialization system. That separate defect is under investigation. MethodOfLines integration and the requested 100×100 construction timings remain unverified; this draft alone does not unblock the downstream issue. GPU and other downstream groups were not run locally. Initialization still performs scalar bookkeeping where required; these correctness tests establish no construction-speed improvement.

Please ignore this draft until reviewed by @ChrisRackauckas.

🤖 Generated with Codex CLI 0.154.0 (model: gpt-6-astra; local session ID: 01a099aa-308a-7fd3-91bd-9fb2dc357b91).

🤖 Automated review section from an AI agent running as Chris Rackauckas's account — not written or reviewed by Chris.

Risk assessment (independent review, Codex CLI 0.164.0 gpt-6.1-sol, slot 1, head 69dccf6)

  • Risk: medium-high (MH1: Changes System indexing, persistent index metadata, initialization mapping and flat DAE layout across core subsystems.)
  • Verdict: CHANGES
  • Session: 01a18da8-3a3a-7620-b234-342bf3d4309e
  • Blocking priorities: P2

Review round 2, written by the reviewer named above (Codex CLI 0.164.0 / gpt-6.1-sol) in a session other than the PR author's, and copied here by the posting agent without change to its findings. The posting agent did not re-run the reviewer's commands.

Summary: Adds flat numerical layouts for initialized DAEs with array unknowns and symbolic indexing. Local runs on both current and floor SciMLBase versions reproduce symbolic remake errors, and the exact-head documentation job fails the new example, so CHANGES remains.

Blast radius: DAEProblem/DAEFunction, System integer indexing, IndexCache, observed extraction, initialization maps and symbolic remake.

Evidence: Julia 1.13.2: the exact three new files run on the head with SciMLBase 3.58.0 and again with SciMLBase 3.54.0 / Symbolics 7.45.0 / SymbolicUtils 4.46.4 / DFBDF 2.0.0. On each stack derivative initialization passes 6/6, the constructor file has 38 passes / 2 errors at symbolic remake, and Jacobians pass 96/96. The base constructor file has 34 passes / 4 failures / 2 errors; the head repairs the index assertions but still cannot remake either shape. Documentation run 34760406480 is verified to use this exact head and fails the new direct SciMLBase import. G1 analytic layout/residual/Jacobian checks pass where reached; G2 paths after the remake exceptions remain needs-verification until repaired; G3 separate shapes/instances execute without a new persistent cache. Core layout scope remains MH1.

Blocking findings

  1. [P2] docs/src/API/problems.md:33 — confirmed by running exact-head CI-log retrieval and checking run metadata: Documentation run 34760406480 belongs to head 69dccf6 and fails the new example with ArgumentError: Package SciMLBase not found in current path, followed by example_block. The example imports SciMLBase directly but docs/Project.toml does not declare it. Add the direct docs dependency or use an already available public reexport, then run the strict example build.

  2. [P2] lib/ModelingToolkitBase/test/array_unknowns_dae.jl:40 and lib/ModelingToolkitBase/Project.toml:185 — confirmed by running: symbolic remake errors for both shapes (3,) and (2,3), with KeyError key 5 and key 1 respectively, on both registered SciMLBase 3.58.0 and the permitted 3.54.0 floor. The constructor file stops with 38 passes / 2 errors; later assertions in those branches never run. The body validates using SciMLBase PR 1602, but no containing compatible registered release is required. Complete/register the upstream support and enforce its first compatible version, or implement the advertised remake contract through supported public APIs, then rerun this entire file on registered/current and floor dependencies. Do not ship the advertised contract or skip the failing cases without that repair.

Non-blocking findings

None.

What I ran

First-round read-only inspection, retained for this unchanged head. Repository commands below ran in the isolated checkout and exited 0; rev-parse HEAD matched the live head metadata. Base is the fetched target-branch tip at review time, while the three-dot diff uses the merge base. Newest non-merge commit trailers, rather than body attribution, supply AUTHOR_GRADE provenance.

git fetch origin +refs/pull/5144/head:refs/remotes/pr/5144 +refs/heads/array-dae-jacobian-residuals:refs/remotes/origin/array-dae-jacobian-residuals
git checkout --detach pr/5144
git rev-parse HEAD
git rev-parse origin/array-dae-jacobian-residuals
git diff --check origin/array-dae-jacobian-residuals...HEAD
git log -1 --no-merges --format=%B
git diff origin/array-dae-jacobian-residuals...HEAD

Read-only GitHub inspection (PR views exit 0; pr checks exits 1 because failures exist):

gh pr view 5144 --repo SciML/ModelingToolkit.jl --json number,url,state,isDraft,headRefOid,baseRefName,baseRefOid,title,files,commits,statusCheckRollup
gh pr view 5144 --repo SciML/ModelingToolkit.jl --json body,closingIssuesReferences
gh pr checks 5144 --repo SciML/ModelingToolkit.jl
gh issue view 5063 --repo SciML/ModelingToolkit.jl --json number,title,body,state,url
gh run view 34760406419 --repo SciML/ModelingToolkit.jl --log-failed
gh run view 34760406480 --repo SciML/ModelingToolkit.jl --log-failed
gh run list --repo SciML/ModelingToolkit.jl --branch array-dae-jacobian-residuals --event push --limit 5 --json databaseId,headSha,conclusion,url,name

CI check rollup at the captured head: {"FAILURE": 3, "SUCCESS": 27}. Log-retrieval exit codes are retrieval status, not test exit codes: successful retrieved jobs report tests passed; failed jobs remain failed. Failed-run logs were retrieved with a writable scratch XDG_CACHE_HOME. Unavailable logs are disclosed above. The recent default-branch five-run listing was also read; exact historical comparisons are identified in the evidence paragraph.

Inspected Documentation failure and both IntegrationTest failures (PDE-IV and Enzyme-through-init). The new docs import fails directly. There are no owning Tests/Sublibrary group checks on this target, and no push-run baseline for the stacked branch; local 154-check and full-group claims in the body were not reproduced.

Inspected CI URLs: https://github.com/SciML/ModelingToolkit.jl/actions/runs/34760406419, https://github.com/SciML/ModelingToolkit.jl/actions/runs/34760406480.

Round 2 local execution:

All 20 live PRs were checked OPEN with unchanged reviewed heads before Julia execution. Each run checked out the exact detached SHA shown below. Julia 1.13.2 ran directly inside the inherited resource scope, with one Julia invocation at a time, four Julia threads and one BLAS thread. The isolated environment was created with Pkg.activate(temp=true) and Pkg.develop(path=...) for the checkout and its MTKBase subpackage, then persisted outside the checkout for dependency reuse. No test project or source was edited in the checkout.

The driver activates that environment, resolves compatible registered dependencies without updating registries, and includes each selected script in a fresh module. It catches only at the test-file boundary to record every selected result, then exits nonzero if any selected case failed. Assertions and tolerances are unchanged. --compiled-modules=existing reuses available dependency caches and loads uncached PR source; it does not disable tests.

base-stacked-retry: detached b984e003fe3202b424625b05437df3bdadc49d62 (origin/array-dae-jacobian-residuals), process exit 1, 192.48 s.

git -C ModelingToolkit.jl checkout --detach origin/array-dae-jacobian-residuals
REVIEW_CASES='5142,5144-0,5144-1,5144-2' \
JULIA_DEPOT_PATH="$PWD/depot:" JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 \
TMPDIR="$PWD/tmp" JULIA_NUM_PRECOMPILE_TASKS=1 JULIA_PKG_PRECOMPILE_AUTO=0 \
timeout 3600 julia --startup-file=no --compiled-modules=existing --depwarn=yes tmp/rerun/driver.jl

Resolved versions: SymbolicUtils 4.54.0, Symbolics 7.47.0, SciMLBase 3.58.0, JumpProcesses 9.33.1, NonlinearSolve 4.32.0, ModelingToolkit 11.45.4, ModelingToolkitTearing 1.20.7, ModelingToolkitBase 1.77.4, OptimizationBase 5.10.0.

head-5144: detached 69dccf6f411b4a5a88f9324c8190c635200f3305 (pr/5144), process exit 1, 170.59 s.

git -C ModelingToolkit.jl checkout --detach pr/5144
REVIEW_CASES='5144-0,5144-1,5144-2' \
JULIA_DEPOT_PATH="$PWD/depot:" JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 \
TMPDIR="$PWD/tmp" JULIA_NUM_PRECOMPILE_TASKS=1 JULIA_PKG_PRECOMPILE_AUTO=0 \
timeout 3600 julia --startup-file=no --compiled-modules=existing --depwarn=yes tmp/rerun/driver.jl

Resolved versions: SymbolicUtils 4.54.0, Symbolics 7.47.0, SciMLBase 3.58.0, JumpProcesses 9.33.1, NonlinearSolve 4.32.0, ModelingToolkit 11.43.1, ModelingToolkitTearing 1.20.7, ModelingToolkitBase 1.72.0, OptimizationBase 5.10.0.

Included all three unchanged new files: lib/ModelingToolkitBase/test/array_initialization.jl, array_unknowns_dae.jl, and array_unknowns_dae_jacobian.jl. Base: 6 passes; 34 passes / 4 failures / 2 errors; 96 passes. Head on SciMLBase 3.58.0: 6 passes; 38 passes / 2 errors; 96 passes. Each constructor branch errors at its first symbolic remake, so later assertions are not claimed as executed. Both processes exit 1 for constructor failures. Read-only run metadata command gh run view 34760406480 --repo SciML/ModelingToolkit.jl --json headSha,conclusion,url confirms the existing docs failure is on the exact reviewed head.

Supported older dependency run head-5144-min: detached 69dccf6f411b4a5a88f9324c8190c635200f3305, process exit 1, 286.28 s. The setup creates a fresh temporary environment, develops only the local MTKBase package, and requests Symbolics 7.45.0, SymbolicUtils 4.46.4, SciMLBase 3.54.0 and OrdinaryDiffEqBDF 2.0.0, plus the test imports. No package source is patched.

git -C ModelingToolkit.jl checkout --detach pr/5144
MIN_SCIMLBASE=3.54.0 REVIEW_CASES='5144-0,5144-1,5144-2' \
JULIA_DEPOT_PATH="$PWD/depot:" JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 \
TMPDIR="$PWD/tmp" JULIA_NUM_PRECOMPILE_TASKS=1 JULIA_PKG_PRECOMPILE_AUTO=0 \
timeout 3600 julia --startup-file=no --compiled-modules=existing tmp/rerun/setup-min.jl
MIN_SCIMLBASE=3.54.0 REVIEW_CASES='5144-0,5144-1,5144-2' \
JULIA_DEPOT_PATH="$PWD/depot:" JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 \
TMPDIR="$PWD/tmp" JULIA_NUM_PRECOMPILE_TASKS=1 JULIA_PKG_PRECOMPILE_AUTO=0 \
timeout 3600 julia --startup-file=no --compiled-modules=existing tmp/rerun/driver-min.jl

The same three files are run unchanged with SciMLBase 3.54.0. Results again are 6/6 derivative-initialization assertions, 38 passes / 2 errors in array constructors (KeyError 5 for vector shape and KeyError 1 for matrix shape), and 96/96 Jacobian assertions. FAILED_CASES=5144-1, process exit 1.

What I did not verify

The strict documentation build was not rerun locally; its failure is from verified exact-head CI and is corroborated by the missing direct dependency in source. Assertions after each symbolic remake exception were not reached and remain needs-verification after the dependency/API repair. No whole suite, GPU, Reactant, MPI or exhaustive dependency matrix was run. Both latest and explicitly supported floor SciMLBase stacks were tested without a development dependency patch. A clean native-precompile cycle was not verified: the initial batch dependency workload errored during NonlinearSolveFirstOrder AD-backend selection. The recorded test commands use existing caches and JIT-load uncached PR source; no assertion was disabled.

🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5
Conversation: https://claude.ai/code/session_01379heiiB35TtywhR7uSU74

ChrisRackauckas and others added 2 commits September 13, 2026 06:28
Fixes SciML#5093

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Codex <[email protected]>
Agent-Harness: Codex CLI 0.154.0
Agent-Model: gpt-6-astra
Agent-Session: local session ID 01a099aa-308a-7fd3-91bd-9fb2dc357b91
Flatten state entries consistently across initialization, generated DAE
functions and symbolic indexing while preserving array-shaped getters.
Cache the numerical unknown count for constant-time integer bounds checks.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Codex <[email protected]>
Agent-Harness: Codex CLI 0.154.0
Agent-Model: gpt-6-astra
Agent-Session: local session ID 01a099aa-308a-7fd3-91bd-9fb2dc357b91

This branch has not been deployed

No deployments
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