Repository navigation
Promote Dual inputs in out-of-place array DAE residuals - #5244
ChrisRackauckas-Claude wants to merge 87 commits into
Conversation
SCCNonlinearProblem on a compiled algebraic System with an independent variable indexed the parameter tuple out of bounds because the system was never normalized to a time-independent nonlinear system. Fixes SciML#5174. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Codex <noreply@openai.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Agent-Harness: Codex CLI 0.155.1 (patch and tests); Claude Code 2.1.278 (rebase, verification, PR) Agent-Model: gpt-6-astra; claude-fable-5-1 Agent-Session: https://claude.ai/code/session_01VJtEvCkHe9XafoMbYvR9No
Per review, do not silently re-mtkcompile; require mtkcompile(NonlinearSystem(sys)). Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Cursor Agent <noreply@cursor.com> Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/adopt/SciML_ModelingToolkit.jl-5182/log.txt on amdci2.julia.csail.mit.edu
Single-block time-dependent systems keep falling through to NonlinearProblem as on master. Multi-block gets a clear error (no check_compatibility=false hint); that opt-out converts safely instead. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Cursor Agent <noreply@cursor.com> Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/adopt/SciML_ModelingToolkit.jl-5182/log.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Cursor Agent <noreply@cursor.com> Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/adopt/SciML_ModelingToolkit.jl-5182/log.txt on amdci2.julia.csail.mit.edu
`generate_rhs` excluded `implicit_dae` from the `similar_for_residual`
allocator wrap, so `DAEProblem{false}` with array equations allocated its
residual through `ArrayMaker`'s default `Float64` buffer and failed on
`ForwardDiff.Dual` in `du`, `u`, `p`, or `t`. Apply the same wrap used by
the nonlinear and explicit ODE paths.
Fixes SciML#5053
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Agent-Harness: Claude Code 2.1.287
Agent-Model: claude-opus-5-5
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-ModelingToolkit.jl-5053/log.txt on amdci2.julia.csail.mit.edu
Address review of the Dual-promotion fix: - Implicit DAE residuals use `promoted_zeros`, a singleton allocator whose element type is `promote_type(Float64, ...)` over the numeric element types of the arguments, computed from types alone. Float64 inputs allocate exactly as master's `zeros(sz)`; non-numeric arguments such as callable parameters are ignored, so return-type inference is kept. - The allocator is only attached to residuals longer than 16 rows. Below that SymbolicUtils emits an `SArray` of the element values, which already follows the input eltype, and attaching an allocator would turn it into a heap `Vector`. - The nonlinear path keeps `similar_for_residual` unchanged. Tests cover n = 8 and 20, split and non-split parameters, Float64 bytes equal to a fixed-`Float64`-allocator build of the same expression, and `@inferred` with a callable parameter. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude <noreply@anthropic.com> Agent-Harness: Claude Code 2.1.287 Agent-Model: claude-opus-5-5 Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-ModelingToolkit.jl-5053/log.txt on amdci2.julia.csail.mit.edu
Do not predict SymbolicUtils' private static-array cutoff. The OOP
implicit-DAE residual is generated twice, with the default lowering and
with the `promoted_zeros` allocator, and the two bodies are joined as
if promoted_residual_eltype(args...) === Float64
<default lowering>
else
<promoted allocator>
end
The condition depends only on argument types, so the untaken branch is
removed at compile time. Float64 arguments run exactly master's code on
every SymbolicUtils version, and Dual arguments always get a promoted
buffer, whatever container the default lowering would have produced.
Tests cover n = 4, 5, 8, 16, 17, 20 with split and non-split parameters
(all four Jacobians) and pin the Float64 result type and allocations to
the default branch. They pass under SymbolicUtils 4.49.0 and 4.46.4, the
lowest version that resolves with this ModelingToolkitBase.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Agent-Harness: Claude Code 2.1.287
Agent-Model: claude-opus-5-5
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-ModelingToolkit.jl-5053/log.txt on amdci2.julia.csail.mit.edu
Bindings whose known size disagrees with an array parameter used to be accepted and only fail later during problem build with an error that did not name the parameter. check_bindings now throws early with both sizes. Fixes SciML#5259 Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Cursor Agent <noreply@cursor.com> Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9 Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-ModelingToolkit.jl-5259/log.txt on amdci2.julia.csail.mit.edu
State only why known sizes must match, without narrative history. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Cursor Agent <noreply@cursor.com> Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9 Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-ModelingToolkit.jl-5259/log.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Devin <noreply@cognition.ai> Agent-Harness: Devin CLI 3000.11.3 (conflict resolution), Claude Code 2.1.285 (orchestration) Agent-Model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium Agent-Session: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master); Devin log /Users/chrisrackauckas/sandbox/master/fusion-fixes/SciML_ModelingToolkit.jl-5182/log.txt # Conflicts: # src/problems/sccnonlinearproblem.jl # test/scc_nonlinear_problem.jl
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Devin <noreply@cognition.ai> Agent-Harness: Devin CLI 3000.11.3 (conflict resolution), Claude Code 2.1.285 (orchestration) Agent-Model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium Agent-Session: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master); Devin log /Users/chrisrackauckas/sandbox/master/fusion-fixes/SciML_ModelingToolkit.jl-5244/log.txt
Merged the default branch into this PR (clean merge, no conflicts; head c00e014) so CI runs on current master. 🤖 Posted by an AI agent — harness: Devin CLI 3000.11.3 (merge), Claude Code 2.1.285 (posting) · model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium |
…duals An implicit-DAE residual with array equations is assembled as a SymbolicUtils `ArrayMaker` with one region per equation. By default SymbolicUtils scalarizes a one-element region that holds an array expression, such as the residual of `u[1:1] ~ 0` or `D(u[1:1]) ~ -u[1:1]`, so the generated code reads its inputs element by element and stores into the output with `batched_setindex!`. Arrays that disallow scalar indexing, such as `CuArray` under `CUDA.allowscalar(false)`, reject that, which is what MethodOfLines' one-element boundary equations produce. Set Symbolics' `scalarize_single_element_regions = false` for implicit-DAE residuals, so those regions are written through a view of the output like every other array equation. Scalar equations are still written as scalars. Agent-Harness: Claude Code 2.1.296 Agent-Model: claude-opus-5-5 Agent-Session: aa65e380-52df-443a-9f57-8c20c56babb9 Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Registered Symbolics does not have the option yet, and `setproperties` would fail on the missing field, so guard on `hasfield`. With an older Symbolics the residual keeps the scalarized form, and the view write activates once a Symbolics release with the field is installed. The test expects the view write only when that field exists and SymbolicUtils is newer than 4.50.0 (needed for the rewrite to take effect), and today's scalar write otherwise. Agent-Harness: Claude Code 2.1.296 Agent-Model: claude-opus-5-5 Agent-Session: aa65e380-52df-443a-9f57-8c20c56babb9 Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
A callable parameter's shape is its return shape, while a binding through the `bindings` kwarg is the Julia function itself (shape ()). Comparing them rejects valid systems that master builds and solves, e.g. `@parameters foo(::Real)[1:2]` bound to a function. Skip the size check when `symtype(p) <: FnType`, matching `Symbolics.setdefaultval`. The regression test binds such a parameter and builds the System and an ODEProblem. `build_initializeprob = false` keeps the test off a separate pre-existing failure: after the bound function is substituted into the initialization system the call has symtype `Any`, which tearing cannot canonicalize into `0 ~ rhs - lhs` (ModelingToolkitTearing 1.20.7, also reproducible on the base commit). Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.92 Agent-Model: swe-2-high Agent-Session: local Devin CLI session, no public URL; transcript under ~/.local/share/devin/cli/transcripts/ on amdci2.julia.csail.mit.edu
…#5282 Replace the tautological `prob isa ODEProblem` assertion with a solve of the bound system (D(z) ~ 2z, z(0) = 1 => z(1) = e^2) using Tsit5, which is already in both test environments. Drop the comment that repeated the check's own comment, and point the `build_initializeprob = false` workaround at the now-filed initialization bug. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.92 Agent-Model: swe-2-high Agent-Session: local Devin CLI session, no public URL; transcript under ~/.local/share/devin/cli/transcripts/ on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Agent-Harness: Claude Code 2.1.301 Agent-Model: claude-opus-5-5 Agent-Session: local session ID ec3d0300-24c6-4a77-ba04-c1622ff0e24b (headless claude -p, no URL)
Throw SystemCompatibilityError from ModelingToolkit's own check_compatible_system method for SCCNonlinearProblem instead of adding `suggest_disable`/`msg` keywords to ModelingToolkitBase internals. The released ModelingToolkitBase versions allowed by ModelingToolkit's compat bound lack those keywords, so a release of this branch could have paired with them and thrown a MethodError on the multi-block path. `check_compatibility = false` now skips the check, as it does for every other problem constructor, instead of silently recompiling the system with `mtkcompile(NonlinearSystem(sys))`; the user does that conversion, which is what the error message names. `check_compatibility` is forwarded to `process_SciMLProblem` and the per-block functions, as it was through `kwargs...` before the keyword was captured. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Agent-Harness: Claude Code 2.1.301 Agent-Model: claude-opus-5-5 Agent-Session: local session ID ec3d0300-24c6-4a77-ba04-c1622ff0e24b (headless claude -p, no URL)
Agent-Harness: Claude Code 2.1.308 Agent-Model: claude-sonnet-5-5 Agent-Session: fbf12fae-28a4-496f-b740-3339fe3ac7a1 Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Codex <noreply@openai.com> Agent-Harness: Codex CLI 0.153.4 Agent-Model: gpt-6-astra Agent-Session: local session 01a08018-78ff-7e42-a964-f5174f3f763b
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Codex <noreply@openai.com> Agent-Harness: Codex CLI 0.153.4 Agent-Model: gpt-6-astra Agent-Session: local session 01a08018-78ff-7e42-a964-f5174f3f763b
Use IRStructureSearchBuffer for term collection, construct reshape via STerm/SArgsT, and apply substitutions with IRSubstituter. Document why contiguous du views are safe, when the scalar fallback runs, and what the sentinel collision check guards. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Cursor Agent <noreply@cursor.com> Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9 Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/orch-ibmtk/jobs/5097-cursor/log.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Cursor Agent <noreply@cursor.com> Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9 Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/orch-ibmtk/jobs/5097-cursor/log.txt on amdci2.julia.csail.mit.edu
Replace the getindex-copy + reshape binding with a real view so residual codegen matches the claimed non-copying path. Drop the unreachable array-shaped `dvs` guard (`flat_unknowns` is always scalar) and add a docstring for `array_derivative_arguments!`. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Cursor Agent <noreply@cursor.com> Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9 Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/orch-ibmtk/jobs/5097-cursor/log.txt on amdci2.julia.csail.mit.edu
Independent review (Codex CLI 0.166.0 / gpt-6.1-sol), session 01a19819-4498-7d63-80d6-46cf1c2899ed, reviewed head c3b8499
Review written by the reviewer named above 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: The PR promotes out-of-place implicit DAE array residuals for Dual arguments, and its regression tests fail on base and pass on head. Request changes because disabling OOP generation now breaks a previously working IIP-only configuration. Blast radius: Implicit array DAE residual generation, including IIP-only configurations; non-Float64 out-of-place residual allocation. Default Float64 residual tests pass. Evidence: Julia 1.13.2: the complete affected test file passes 214/214 on head; on merge-base the added Dual testset reports 74 passes, 8 structural failures and one genuine Blocking findings
Non-blocking findings
What I ran
JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 TMPDIR="$PWD/tmp" JULIA_DEPOT_PATH="$SHARED_DEPOT:" JULIA_PKG_PRECOMPILE_AUTO=0 timeout 3600 julia +1.13.2 --startup-file=no --compiled-modules=existing run-head.jl
JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 TMPDIR="$PWD/tmp" JULIA_DEPOT_PATH="$SHARED_DEPOT:" JULIA_PKG_PRECOMPILE_AUTO=0 timeout 3600 julia +1.13.2 --startup-file=no --compiled-modules=existing run-base.jl
JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 TMPDIR="$PWD/tmp" JULIA_DEPOT_PATH="$SHARED_DEPOT:" JULIA_PKG_PRECOMPILE_AUTO=0 timeout 3600 julia +1.13.2 --startup-file=no --compiled-modules=existing run-probe.jlHead runner includes The independent probe uses
What I did not verifyNo complete package suite, heavy downstream suite, alternate Julia/platform matrix, lowest-compatible SymbolicUtils run, code-generation timing benchmark, or end-to-end solver differentiation was run locally. Other AD engines and GPU/MPI execution were not tested; the changed ForwardDiff allocation path was exercised locally and in CI. The base callable-parameter testset was not reached after the expected earlier regression failure. Default Float64 equality/allocation comparisons were tested for the PR's matrix, not every possible residual container or user-supplied wrapper. 🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5 |
Export poissonians, like brownians and jumps
…rors `complete` asserted that every input keeps its position among the parameters. Only inputs in the tunable buffer have a defined order there; non-floating point inputs are stored in buffers grouped by type, so a system with a `Bool` and an `Int` input failed the assertion depending on the order of the buffers (observed with Julia 1.10). The check is now limited to tunable inputs. `underscore_to_D` called `getname` on every variable, which fails for operator terms such as `Hold(x)`, so `IncompleteInitializationError` could not be printed when such a term was uninitialized. These terms are now returned unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A literal such as `[x => 0.0, b => false]` promotes `false` to `0.0`, which breaks things. Convert values for variables declared with a concrete (`Integer`) type back to that type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A variable of integer type, such as `Bool` or `Int`, with no value or guess was given a fallback guess from `missing_guess_value`, which is a floating point number. Building the problem then failed with an `InexactError`, e.g. `Bool(0.0197...)`. Such a variable cannot be solved for numerically, so throw a `MissingIntegerValueError` naming it instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent-Harness: Claude Code 2.1.325 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Agent-Harness: Claude Code 2.1.325 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Write one-element slice equations without scalar indexing in DAE residuals
Agent-Harness: Claude Code 2.1.325 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tearing solved for `n`, so it was no longer an unknown. Change the test to use `n` only in a condition. Then tearing cannot solve for `n` and it remains an unknown. The check then sees it.
…rsede Preserve contiguous array derivative views in implicit residual codegen (supersedes SciML#5242)
Do not make non-floating point inputs solvable parameters
build: bump MTKBase minor, MTK minor, MTKBase compat
Instead of always throwing for a variable of integer type with no value or guess, follow `missing_guess_value`: `Constant` converts its value to the declared type or throws, `Random` and `HashedRandom` produce a value of that type, and `Error` throws as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Convert operating point values to declared integer types and do not make `Float64` guesses for integer type variables
Fix inverse matching size for empty equation rows Harness: codex Model: gpt-6.1-sol Factory-Task: e3f1613d-6951-4081-a0dd-b2458a268ff6 Co-Authored-By: Anshul Singhvi <anshul.singhvi@juliahub.com> Co-Authored-By: Codex <noreply@openai.com> Agent-Harness: Codex 0.164.0 Agent-Model: gpt-6.1-sol Agent-Session: factory task e3f1613d-6951-4081-a0dd-b2458a268ff6 on m_e7dafdb55d0afc98861a124723a9e3fd (no session URL)
Add `linearize_hybrid` for partition-wise linearization of clocked systems
Fix assertion residual sparsity tracing Harness: codex Model: gpt-6.1-sol Factory-Task: f7572faa-0835-48ee-9da1-4b37308336a3 Require tracer constant-branch support and fix Runic formatting Harness: codex Model: gpt-6.1-sol Factory-Task: 49602c3f-8993-4459-a43d-ca0e2c6a1383 Trim tests Harness: codex Model: gpt-6.1-sol Factory-Task: f97fe415-ceb4-45e1-9321-0c9c0362aa9d Merge remote-tracking branch 'upstream/master' into nan-condition-tra… …cers Co-Authored-By: Anshul Singhvi <anshul.singhvi@juliahub.com> Co-Authored-By: Codex <noreply@openai.com> Agent-Harness: Codex 0.164.0 Agent-Model: gpt-6.1-sol Agent-Session: factory task f7572faa-0835-48ee-9da1-4b37308336a3 on m_e7dafdb55d0afc98861a124723a9e3fd (no session URL) Agent-Session: factory task 49602c3f-8993-4459-a43d-ca0e2c6a1383 on m_3e9b2709b53bf4c4dade6cc909217625 (no session URL) Agent-Session: factory task f97fe415-ceb4-45e1-9321-0c9c0362aa9d on m_e7dafdb55d0afc98861a124723a9e3fd (no session URL)
…e) (SciML#5320) Prepare fully specialized linearization functions Add a specialize keyword to linearization_function. With FullSpecialize the system and observed functions are called directly instead of through FunctionWrappersWrappers, and eval_expression/eval_module reach the ODEProblem it builds. The call skips remake and get_initial_values when the algorithm is NoInit and u and p already have the problem's types, since NoInit returns them unchanged. Test fully specialized linearization functions Apply the eval options and the NoInit shortcut only with FullSpecialize Pass eval_expression and eval_module to the ODEProblem, and skip remake and get_initial_values for NoInit calls whose u and p have the problem's types, only when specialize = FullSpecialize. Calls without it build the same problem and take the same path as before. Test the FullSpecialize gating against analytic Jacobians and default… … calls The NoInit shortcut test uses FullSpecialize and checks that the default specialization still remakes the problem. Without FullSpecialize, the RHS stays a RuntimeGeneratedFunction with eval_expression = true. The scalar plant's Jacobians are checked against -k, 1, 1 and 0 for every specialization, initialization and evaluation setting, and the PI loop's sensitivity against the closed-loop trace, determinant and feedthrough. Test FullSpecialize linearization of a nonlinear system and a statele… …ss one Check analytic Jacobians of a nonlinear system for states of another element type, parameters given as pairs and with initialization, and the output Jacobian of a system without unknowns, for each specialization. Test linearization with Jacobians that read fixed initial values Parameters bound to `Initial(x)` make the Jacobians depend on the fixed initial value in `p`. With and without `FullSpecialize`, and with `NoInit` and `OverrideInit`, the Jacobians match the analytic values for a new `u`, for `Initial(x)` given as a pair, and after `setp` and `setu`. Use public APIs to detect wrappers in the specialization tests Find function wrappers with SciMLBase.isfunctionwrapper and unwrap them with SciMLBase.unwrapped_f instead of reaching FunctionWrappersWrappers through SciMLBase's module binding and its fw/obj fields. Import RuntimeGeneratedFunction from RuntimeGeneratedFunctions directly, and check inference with @inferred instead of Base.return_types. Detect the outer function wrapper through its exported type in the tests SciMLBase.isfunctionwrapper is true only for the inner FunctionWrapper, so the wrapper search matched by descending into FunctionWrappersWrapper's fields. Declare FunctionWrappersWrappers as a test dependency and stop the search at its exported FunctionWrappersWrapper type. Also check the problem's system function directly: wrapped on the default path, and returned unchanged by SciMLBase.unwrapped_f with FullSpecialize. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Agent-Harness: Claude Code 2.1.316 Agent-Model: claude-opus-5-5 Agent-Harness: Claude Code 2.1.328 Agent-Session: ad77220b-a123-4044-8490-01237c52d3b4
`generate_rhs` excluded `implicit_dae` from the `similar_for_residual`
allocator wrap, so `DAEProblem{false}` with array equations allocated its
residual through `ArrayMaker`'s default `Float64` buffer and failed on
`ForwardDiff.Dual` in `du`, `u`, `p`, or `t`. Apply the same wrap used by
the nonlinear and explicit ODE paths.
Fixes SciML#5053
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Agent-Harness: Claude Code 2.1.287
Agent-Model: claude-opus-5-5
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-ModelingToolkit.jl-5053/log.txt on amdci2.julia.csail.mit.edu
Address review of the Dual-promotion fix: - Implicit DAE residuals use `promoted_zeros`, a singleton allocator whose element type is `promote_type(Float64, ...)` over the numeric element types of the arguments, computed from types alone. Float64 inputs allocate exactly as master's `zeros(sz)`; non-numeric arguments such as callable parameters are ignored, so return-type inference is kept. - The allocator is only attached to residuals longer than 16 rows. Below that SymbolicUtils emits an `SArray` of the element values, which already follows the input eltype, and attaching an allocator would turn it into a heap `Vector`. - The nonlinear path keeps `similar_for_residual` unchanged. Tests cover n = 8 and 20, split and non-split parameters, Float64 bytes equal to a fixed-`Float64`-allocator build of the same expression, and `@inferred` with a callable parameter. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude <noreply@anthropic.com> Agent-Harness: Claude Code 2.1.287 Agent-Model: claude-opus-5-5 Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-ModelingToolkit.jl-5053/log.txt on amdci2.julia.csail.mit.edu
Do not predict SymbolicUtils' private static-array cutoff. The OOP
implicit-DAE residual is generated twice, with the default lowering and
with the `promoted_zeros` allocator, and the two bodies are joined as
if promoted_residual_eltype(args...) === Float64
<default lowering>
else
<promoted allocator>
end
The condition depends only on argument types, so the untaken branch is
removed at compile time. Float64 arguments run exactly master's code on
every SymbolicUtils version, and Dual arguments always get a promoted
buffer, whatever container the default lowering would have produced.
Tests cover n = 4, 5, 8, 16, 17, 20 with split and non-split parameters
(all four Jacobians) and pin the Float64 result type and allocations to
the default branch. They pass under SymbolicUtils 4.49.0 and 4.46.4, the
lowest version that resolves with this ModelingToolkitBase.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Agent-Harness: Claude Code 2.1.287
Agent-Model: claude-opus-5-5
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-ModelingToolkit.jl-5053/log.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Codex <noreply@openai.com> Agent-Harness: Codex CLI 0.170.0 Agent-Model: gpt-6-luna Agent-Job: SciML__ModelingToolkit.jl__5244--20261121T144048Z-codex-gpt-6-luna Agent-Session: local session 01a1fe8f-2dc1-70f3-ad19-c0ccdf938261 (no session URL)
Preserve the validated upstream-based tree while retaining the existing branch as an ancestor. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Codex <noreply@openai.com> Agent-Harness: Codex CLI 0.170.0 Agent-Model: gpt-6-luna Agent-Job: SciML__ModelingToolkit.jl__5244--20261121T144048Z-codex-gpt-6-luna Agent-Session: local session 01a1fe8f-2dc1-70f3-ad19-c0ccdf938261 (no session URL)
Out-of-place
DAEProblem{false}residuals with array equations allocate their output throughArrayMaker's default lowering. That lowering returns either aFloat64zerosbuffer or, for short residuals, anSArrayof the element values; which one it picks depends on a SymbolicUtils-internal size cutoff that differs between versions. With theFloat64buffer,ForwardDiff.Dualinputs indu,u,portfail withMethodError: no method matching Float64(::Dual).For implicit DAEs, this PR generates the OOP residual twice and joins the two bodies:
promoted_residual_eltypepromotesFloat64with the numeric element types of the arguments. It looks only at argument types, so the compiler drops the untaken branch. Non-numeric arguments, such as callable parameters, are ignored, so inference is kept.similar_for_residual) and the in-place functions are unchanged.Regression tests
Two new testsets in
lib/ModelingToolkitBase/test/array_equation_dae.jl:@inferredwith Float64 inputs.ForwardDiffJacobians with respect tou,du, tunablepandt.expression = Val{true}path.@allocatedof the generated function equal those of its default (master) branch evaluated on its own.@parameters (gain::Function)(..)and checks@inferredandVector{Float64}.Both testsets were run under the current SymbolicUtils (4.49.0) and the lowest version that resolves with this ModelingToolkitBase (4.46.4). Versions 4.35.3–4.46.3 do not resolve, even though
Project.tomlallows them.Failing before
Each line below is a separate run of the extracted testsets.
(The
Failentries are the newdefault_expr !== nothingstructure check.)Passing after
A scratch probe compared master with this PR for Float64 inputs. At every n under both SymbolicUtils versions, the result type and bytes are identical, and
@inferredpasses. Dual calls failed on master at n ≥ 17 (4.49.0) or n ≥ 5 (4.46.4); on the PR they pass everywhere.SVector, 800 B / sameSVector, 800 B / sameSVector, 800 B / sameVector, 896 B / sameSVector, 1120 B / sameVector, 1248 B / sameSVector, 1760 B / sameVector, 1952 B / sameVector, 1952 B / sameVector, 1952 B / sameVector, 2304 B / sameVector, 2304 B / sameTest groups (lib/ModelingToolkitBase, SymbolicUtils 4.49.0)
The broken counts come from existing
@test_brokens, not from this PR.Runic
--checkandtyposare clean on both changed files.CI: downgrade-mtkbase (Initialization)
The failing assertion is
initializationsystem.jl:2556, aForwardDiff.gradientthroughRodas5Pin "Initialization problem type is shared across models, use_scc = true". It gave about 1e153–1e162 against the finite-difference value -1.154. It is a pre-existing intermittent failure on master, not caused by this PR:GROUP=Initialization. Both master 34711f6 and this PR passed (758 pass / 12 broken).1.3172268582515041e153) and this PR failed 2/3 (9.898834314793689e154).agent/5200-oop-affect-updates(job 111058298577) andagent/5193-dae-derivative-guesses(job 110457339119).ODEProblemand an initializationNonlinearProblem, neither of which reaches the implicit-DAE branch changed here. On the downgraded env, their generated code differs between master and this PR only in the order of independent CSE temporaries, and that order also varies between two runs of master.Not verified
solvethat differentiates the OOP residual internally.SciMLBase.DespecializedParameterspassed directly to the generated function. Its eltype is not visible from the type, so it would take the Float64 branch.For the reviewer
build_function_wrappertwice (the IIP output of the second call is discarded), and the OOP expression holds both bodies. Runtime is unaffected, since one branch is removed, but codegen and Expr size for these systems roughly double.Vector{Dual}where master returned anSVector{Dual}.Fixes #5053
Please ignore this draft until reviewed by @ChrisRackauckas.
Risk assessment
pending independent review
🤖 Generated with Claude Code 2.1.287 (model: claude-opus-5-5), transcript /log.txt
Risk assessment (independent review, codex-cli gpt-6-astra, reviewed head c3b8499)
🤖 Posted by an AI agent — harness: codex-cli · model: gpt-6-astra (independent reviewer; appended by Claude Code 2.1.301 · claude-opus-5-5)
Conversation: https://claude.ai/code/session_01VZjwf7Ux9YtTzwHGHMqnsq
Fix by Codex CLI 0.164.0 gpt-6.1-sol (head 3253d59)
Merged current master normally, preserving the DAE promotion logic and automatic RHS chunking. This includes the upstream parsing-default, LaTeX reference, and documentation-link fixes. Master's requested indexing, InterfaceI, RegressionI and documentation checks pass.
The promoted OOP branch is now assembled only when OOP generation is enabled. The disabled OOP stub and working IIP residual are retained for
iip_config=(false, true). The regression test checks analytic residuals with split/unsplit parameters and expression/compiled output.Verification
Julia 1.13.3; four Julia threads, one BLAS thread and one precompile task. Scratch paths below are represented by environment variables:
PROBE_ENVdevelops this checkout andIIP_REGRESSIONcontains the unchanged new testset plus its imports.The same regression command was run before and after the guard:
Before:
After:
Completed normal-compilation groups:
GROUP=InterfaceI julia +1.13.3 --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'The five broken assertions are existing tests.
GROUP=QA julia +1.13.3 --project -e 'using Pkg; Pkg.test()'GROUP=QA julia +1.13.3 --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'Aqua's error is the same five non-public accesses reported by master QA:
SymbolicGetproperty,field_name,is_symstruct_type,issymstruct, andget_reachability!. The affected source and QA files match master. They are unchanged by this fix; no checks were disabled or allowlists extended.The complete affected file also passed 241 assertions across 13 testsets, including Dual inputs 180/180 and IIP-only 4/4:
RegressionI ran through the existing runner:
This checked the tracked
50.texreference that failed in CI. The runner generated four absent reference files; those outputs were kept outside the checkout and were not committed or counted as validated reference comparisons.All exited 0 with no diagnostics.
Not run locally: docs build, downstream integration, InterfaceII, GPU/platform matrix, minimum dependency versions, and a code-generation benchmark. The tuple-parameter AD limitation and two-body construction cost remain outside this scoped fix. Initial cache-only validation attempts hit dependency world-age errors; completed root QA and InterfaceI use normal compilation. CI results for this new head are pending.
Next counted review must come from a smart model in a fresh session, not this fix session (risk.md § Independent reviews).
Links
🤖 Posted by an AI agent — harness: Codex CLI 0.164.0 · model: gpt-6.1-sol
Conversation: local fixer job SciML__ModelingToolkit.jl__5244 (no session URL)
Fix by Muse CLI Code muse-wonder-full-1.0 (head 42edb26)
Merged the current default branch (
3df991c81d) into this PR branch normally (clean merge, no conflicts, no code changes beyond the merge). The PR diff against the default branch is unchanged:lib/ModelingToolkitBase/src/systems/codegen.jlandlib/ModelingToolkitBase/test/array_equation_dae.jlonly. The merge brings in the upstreamanctoancestorrename inatomic_array_dict.jlthat the Spell Check job was failing on, plus the current struct/record, SCC-cache, and event-code-generation changes.Before the merge,
rack ci compare --no-recordclassified the failing checks on head3253d5935fas: pre-existing — ModelingToolkitBase QA and ModelOrderReduction.jl/Core; base-green — Extensions (sublibrary, top-level, and downgrade), downgrade Optimization, and Spell Check. All Extensions failures shared one signature, a TaylorDiff precompile error (TypeError: non-boolean (Symbolics.Num) used in boolean contextin TaylorDiff's own codegen), and downgrade Optimization was cancelled at the six-hour job limit with no test assertion failure.Verification
Julia 1.13.3, four Julia threads, one BLAS thread, four precompile tasks. Each group below was run once in full on the merged head.
typos . julia --project=@runic -m Runic --inplace lib/ModelingToolkitBase/src/systems/codegen.jl lib/ModelingToolkitBase/test/array_equation_dae.jl git diff --checkAll exited 0 with no diagnostics and no file changes (Spell Check failure is gone).
GROUP=Extensions julia +1.13.3 --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'TaylorDiff precompiled successfully in this run; the
Symbolics.Numprecompile error from the stale-head CI does not reproduce.GROUP=Extensions julia +1.13.3 --project -e 'using Pkg; Pkg.test()'GROUP=InterfaceI julia +1.13.3 --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'InterfaceI contains the changed file's
Array equations reach DAEProblemtestset. The five broken assertions are existing@test_brokentests.Both QA groups still error only in
all_qualified_accesses_are_public, on names in files this PR does not touch (SymbolicGetproperty,field_name,is_symstruct_type,issymstructfor ModelingToolkitBase;expand_record_equationsfor ModelingToolkit). Those files are byte-identical to the default branch (git diffagainst it is empty),rack ci compareclassified the ModelingToolkitBase QA failure as pre-existing with the same signatures, and the newest default-branch Tests run fails its QA job as well. No QA code or allowlist was changed here.Not run locally: the downgrade groups (including the six-hour downgrade Optimization job that CI cancelled), ModelOrderReduction downstream (classified pre-existing), InterfaceII, Initialization, docs build, and the Julia lts/pre matrix. CI for this head had started (all checks pending) when last checked, and was not waited on.
Next counted review must come from a smart model in a fresh session, not this fix session (risk.md § Independent reviews).
Links
🤖 Posted by an AI agent — harness: Muse CLI Code · model: muse-wonder-full-1.0
Conversation: local fixer job SciML__ModelingToolkit.jl__5244 (no session URL)
Fix by Codex CLI 0.170.0 gpt-6-luna (head 4707b80)
Rebased the PR on current
masterand resolved the code generation conflicts while retaining upstream array derivative and code-size options, the PR's Dual-safe out-of-place array DAE residual path, and its in-place-only generation guard. The published tree is the validated rebase tree; a content-preserving ancestry merge made the update a normal fast-forward push.Validation:
julia --project=@runic -m Runic --inplace lib/ModelingToolkitBase/src/systems/codegen.jl lib/ModelingToolkitBase/test/array_equation_dae.jl— exit 0, no diagnostics.git diff --unified=0 upstream/master...HEAD -- lib/ModelingToolkitBase/src/systems/codegen.jl lib/ModelingToolkitBase/test/array_equation_dae.jl | typos -— exit 0, no diagnostics.git diff --check upstream/master...HEAD— exit 0, no diagnostics.GROUP=InterfaceI julia --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'—InterfaceI | 2393 pass, 5 broken, 2398 total; package tests passed.GROUP=QA julia --project -e 'using Pkg; Pkg.test()'— 39 pass, 1 fail: unapproved public reexports. The same failure is on current default branch (default QA run).GROUP=QA julia --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'— 20 pass, 1 fail: unapproved public reexports. The same failure reproduced on a clean current-default checkout.GROUP=InterfaceII julia --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'— 4279 pass, 1 fail inProper substitution in JumpSysMajParamWrapper; the same failure reproduced on a clean current-default checkout. The assertion sees a JumpProcesses deprecation warning.CI for this pushed head has started (run 44932320182); results are pending. Downstream and full CI results are not verified yet.
Next counted review must come from a smart model in a fresh session, not this fix session.
🤖 Posted by an AI agent — harness: Codex CLI 0.170.0 · model: gpt-6-luna
Conversation: local session 01a1fe8f-2dc1-70f3-ad19-c0ccdf938261 (no session URL)