Repository navigation
Support array unknowns in initialized DAE constructors - #5144
Draft
ChrisRackauckas-Claude wants to merge 2 commits into
Draft
ChrisRackauckas-Claude wants to merge 2 commits into
ChrisRackauckas-Claude wants to merge 2 commits into
Conversation
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
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.
DAEProblemandDAEFunctionnow accept whole-array entries inunknowns(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
remakeadditionally 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.jlruns against the prerequisite stack with and without the constructor change. Before, both vector and matrix cases error inSetInitialUnknowns, which expects scalar initial-parameter indices:After, the final production source passes all 154 focused checks on Julia 1.10.12 with minimum dependency versions:
TMPDIR="$PWD/tmp" JULIA_PKG_PRECOMPILE_AUTO=0 julia +1.10.12 --project=array_constructors_downgrade_env array_constructors_downgrade_tests.jlThe script runs the official
array_initialization.jl,array_unknowns_dae.jl, andarray_unknowns_dae_jacobian.jlfiles 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 originalis_variablemethod withBase.include_stringmakes 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:
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_envand each namedGROUP:QA's only failure is the 234 existing Moshi unbound type-parameter reports tracked at #5063 (182
And, 52Call). 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 normaljulia +1.12 --project=docs docs/make.jlbuild 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 --checkpass. 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).
Risk assessment (independent review, Codex CLI 0.164.0 gpt-6.1-sol, slot 1, head 69dccf6)
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
[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.[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.
Read-only GitHub inspection (PR views exit 0; pr checks exits 1 because failures exist):
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)andPkg.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=existingreuses available dependency caches and loads uncached PR source; it does not disable tests.base-stacked-retry: detachedb984e003fe3202b424625b05437df3bdadc49d62(origin/array-dae-jacobian-residuals), process exit 1, 192.48 s.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: detached69dccf6f411b4a5a88f9324c8190c635200f3305(pr/5144), process exit 1, 170.59 s.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, andarray_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 commandgh run view 34760406480 --repo SciML/ModelingToolkit.jl --json headSha,conclusion,urlconfirms the existing docs failure is on the exact reviewed head.Supported older dependency run
head-5144-min: detached69dccf6f411b4a5a88f9324c8190c635200f3305, 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.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