Skip to content

Promote Dual inputs in out-of-place array DAE residuals - #5244

Draft
ChrisRackauckas-Claude wants to merge 87 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix-5053-oop-dae-dual-residual
Draft

ChrisRackauckas-Claude wants to merge 87 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix-5053-oop-dae-dual-residual

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Out-of-place DAEProblem{false} residuals with array equations allocate their output through ArrayMaker's default lowering. That lowering returns either a Float64 zeros buffer or, for short residuals, an SArray of the element values; which one it picks depends on a SymbolicUtils-internal size cutoff that differs between versions. With the Float64 buffer, ForwardDiff.Dual inputs in du, u, p or t fail with MethodError: no method matching Float64(::Dual).

For implicit DAEs, this PR generates the OOP residual twice and joins the two bodies:

function (du, u, p, t)
    if promoted_residual_eltype(du, u, p, t) === Float64
        <default lowering, exactly as on master>
    else
        <same body, output allocated by promoted_zeros: zeros(T, sz)>
    end
end
  • The condition: promoted_residual_eltype promotes Float64 with 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.
  • Float64 inputs run master's code unchanged on every SymbolicUtils version. Dual inputs always get a promoted buffer. Nothing depends on predicting the size cutoff.
  • The nonlinear path (similar_for_residual) and the in-place functions are unchanged.

Regression tests

Two new testsets in lib/ModelingToolkitBase/test/array_equation_dae.jl:

  • "OOP DAE residual promotes Dual inputs" runs n ∈ {4, 5, 8, 16, 17, 20} × split/non-split. For each case it checks:
    • @inferred with Float64 inputs.
    • Analytic ForwardDiff Jacobians with respect to u, du, tunable p and t.
    • The expression = Val{true} path.
    • That the Float64 result type, value and @allocated of the generated function equal those of its default (master) branch evaluated on its own.
  • "OOP DAE residual ignores callable parameters" uses @parameters (gain::Function)(..) and checks @inferred and Vector{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.toml allows them.

Failing before

Each line below is a separate run of the extracted testsets.

# master, SymbolicUtils 4.49.0: n = 4..16 work (SVector), n = 17 errors
  MethodError: no method matching Float64(::ForwardDiff.Dual{...DAEFunction{false,...
OOP DAE residual promotes Dual inputs |   74     8      1     83
# master, SymbolicUtils 4.46.4: n = 5 already errors
OOP DAE residual promotes Dual inputs |   20     2      1     23   (MethodError Float64(::Dual))
# previous PR commit 6ec655c44a (copied 16-row cutoff), SymbolicUtils 4.46.4: same n = 5 failure
OOP DAE residual promotes Dual inputs |   20     2      1     23   (MethodError Float64(::Dual))

(The Fail entries are the new default_expr !== nothing structure check.)

Passing after

SymbolicUtils 4.49.0:  OOP DAE residual promotes Dual inputs | 180 180 ; ignores callable parameters | 2 2
SymbolicUtils 4.46.4:  OOP DAE residual promotes Dual inputs | 180 180 ; ignores callable parameters | 2 2

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 @inferred passes. Dual calls failed on master at n ≥ 17 (4.49.0) or n ≥ 5 (4.46.4); on the PR they pass everywhere.

n 4.49.0 master / PR 4.46.4 master / PR
4 SVector, 800 B / same SVector, 800 B / same
5 SVector, 800 B / same Vector, 896 B / same
8 SVector, 1120 B / same Vector, 1248 B / same
16 SVector, 1760 B / same Vector, 1952 B / same
17 Vector, 1952 B / same Vector, 1952 B / same
20 Vector, 2304 B / same Vector, 2304 B / same

Test groups (lib/ModelingToolkitBase, SymbolicUtils 4.49.0)

GROUP=InterfaceI:   InterfaceI | 1951 pass, 5 broken, 1956 total, 50m42.5s   Testing ModelingToolkitBase tests passed
GROUP=InterfaceII:  29 testsets, 7720 pass, 2 broken ("Optimal Control + Constraints"), incl. Code Generation 65/65,
                    Array Equation ODEProblem 51/51, Array-equation Nonlinear 172/172, Implicit Discrete 18/18
                    Testing ModelingToolkitBase tests passed

The broken counts come from existing @test_brokens, not from this PR.

Runic --check and typos are clean on both changed files.

CI: downgrade-mtkbase (Initialization)

The failing assertion is initializationsystem.jl:2556, a ForwardDiff.gradient through Rodas5P in "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:

  • Exact CI environment: I rebuilt the job's test Manifest locally (284 packages, identical to the CI log; Julia 1.10.12, SymbolicUtils 4.46.4) and ran GROUP=Initialization. Both master 34711f6 and this PR passed (758 pass / 12 broken).
  • Repeated runs: running only that testset 3× per revision in fresh processes, master failed 1/3 (1.3172268582515041e153) and this PR failed 2/3 (9.898834314793689e154).
  • Other branches: CI hit the same failure, with the same two values, on unrelated branches agent/5200-oop-affect-updates (job 111058298577) and agent/5193-dae-derivative-guesses (job 110457339119).
  • Not touched by this PR: the test builds an ODEProblem and an initialization NonlinearProblem, 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

  • QA, Initialization and the other groups, the top-level ModelingToolkit tests, downstream packages, and Julia 1.10 or pre-release.
  • The full InterfaceI/II groups were not run under SymbolicUtils 4.46.4; only the regression testsets and the probe were.
  • An end-to-end solve that differentiates the OOP residual internally.
  • SciMLBase.DespecializedParameters passed directly to the generated function. Its eltype is not visible from the type, so it would take the Float64 branch.

For the reviewer

  • Codegen cost: array-equation implicit DAEs now run build_function_wrapper twice (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.
  • Container type for Duals: a Dual call on a short residual now returns a Vector{Dual} where master returned an SVector{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)

  • Risk: medium
  • Blast radius: out-of-place implicit array DAE residual generation for numeric types other than Float64. Default Float64 lowering and in-place functions are retained; the implementation generates two function bodies, and short non-Float64 residuals can change from SVector to Vector.
  • Evidence: Julia 1.13.1 added regression tests passed 180/180 for Dual propagation and 2/2 for callable parameters. An independent n=20 probe observed Float64(::Dual) on the unfixed default generated branch, versus correct state derivative 2.0 and tunable-parameter derivative 1.0 on the promoted function. The two current CI failures match master; primary groups are pending. The complete affected array-DAE file also exited 0: 214/214 assertions across 10 testsets, including all 32 existing assertions.
  • Independent review: codex-cli 0.163.0 gpt-6-astra rated it medium, high confidence in the scoped fix: the full new differentiation matrix passes, with disclosed code-generation and return-container tradeoffs requiring maintainer judgment.
  • Merge: needs human review — medium risk from generated-code size and non-Float64 output-container changes; no blocking correctness finding.

🤖 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

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

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_ENV develops this checkout and IIP_REGRESSION contains the unchanged new testset plus its imports.

The same regression command was run before and after the guard:

julia +1.13.3 --startup-file=no --compiled-modules=existing --project="$PROBE_ENV" "$IIP_REGRESSION"

Before:

ArgumentError: Expected a generated `function` expression.
Test Summary:               | Error  Total
IIP-only array DAE residual |     1      1

After:

Test Summary:               | Pass  Total
IIP-only array DAE residual |    4      4

Completed normal-compilation groups:

GROUP=InterfaceI julia +1.13.3 --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'
InterfaceI    | 2312       5   2317  23m24.8s
Testing ModelingToolkitBase tests passed

The five broken assertions are existing tests.

GROUP=QA julia +1.13.3 --project -e 'using Pkg; Pkg.test()'
QA            |   40     40  2m47.3s
Testing ModelingToolkit tests passed
GROUP=QA julia +1.13.3 --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'
JET Tests     |   54     54  43.1s
Aqua Tests    |   20      1     21

Aqua's error is the same five non-public accesses reported by master QA: SymbolicGetproperty, field_name, is_symstruct_type, issymstruct, and get_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:

julia +1.13.3 --startup-file=no --compiled-modules=existing --project="$PROBE_ENV" -e 'using Pkg; Pkg.add("SymbolicIndexingInterface"); include("lib/ModelingToolkitBase/test/array_equation_dae.jl")'

RegressionI ran through the existing runner:

GROUP=RegressionI julia +1.13.3 --startup-file=no --compiled-modules=existing --project="$PROBE_ENV" -e 'using Pkg; Pkg.add(["SafeTestsets", "ReferenceTests", "Latexify", "ModelingToolkitStandardLibrary"]); cd("lib/ModelingToolkitBase/test"); include("runtests.jl")'
Latexify recipes Test |    1      1  41.4s

This checked the tracked 50.tex reference 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.

julia +1.13.3 --project=@runic -m Runic --inplace lib/ModelingToolkitBase/src/systems/codegen.jl lib/ModelingToolkitBase/test/array_equation_dae.jl
git diff --unified=0 upstream/master -- lib/ModelingToolkitBase/src/systems/codegen.jl lib/ModelingToolkitBase/test/array_equation_dae.jl > "$DIFF_FILE"
typos "$DIFF_FILE"
git diff --check

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)

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

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.jl and lib/ModelingToolkitBase/test/array_equation_dae.jl only. The merge brings in the upstream anc to ancestor rename in atomic_array_dict.jl that 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-record classified the failing checks on head 3253d5935f as: 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 context in 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 --check

All 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()'
Test Summary:                       | Pass  Total     Time
HomotopyContinuation Extension Test |   76     76  5m54.4s
LabelledArrays Test |   18     18  15.5s
BifurcationKit Extension Test |    7      7  1m31.7s
Despecialized MTKParameters AD Test |    2      2  2m57.3s
Initialization maps AD |    7      7  11.1s
Auto Differentiation Test |   67     67  2m49.1s
     Testing ModelingToolkitBase tests passed

TaylorDiff precompiled successfully in this run; the Symbolics.Num precompile error from the stale-head CI does not reproduce.

GROUP=Extensions julia +1.13.3 --project -e 'using Pkg; Pkg.test()'
Test Summary: | Pass  Total      Time
Extensions    |  106    106  12m11.1s
     Testing ModelingToolkit tests passed
GROUP=InterfaceI julia +1.13.3 --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'
Test Summary: | Pass  Broken  Total      Time
InterfaceI    | 2338       5   2343  22m58.0s
     Testing ModelingToolkitBase tests passed

InterfaceI contains the changed file's Array equations reach DAEProblem testset. The five broken assertions are existing @test_broken tests.

GROUP=QA julia +1.13.3 --project=lib/ModelingToolkitBase -e 'using Pkg; Pkg.test()'
GROUP=QA julia +1.13.3 --project -e 'using Pkg; Pkg.test()'
JET Tests     |   54     54  42.4s
Aqua Tests    |   20      1     21  4m38.5s
QA            |   39      1     40  2m34.5s

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, issymstruct for ModelingToolkitBase; expand_record_equations for ModelingToolkit). Those files are byte-identical to the default branch (git diff against it is empty), rack ci compare classified 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)

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

Fix by Codex CLI 0.170.0 gpt-6-luna (head 4707b80)

Rebased the PR on current master and 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 in Proper substitution in JumpSysMajParamWrapper; the same failure reproduced on a clean current-default checkout. The assertion sees a JumpProcesses deprecation warning.
  • The ModelOrderReduction Core DimensionMismatch also occurs on current default (default integration run).

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)

ChrisRackauckas and others added 9 commits September 26, 2026 14:59
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
ChrisRackauckas and others added 2 commits October 13, 2026 19:42
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
@ChrisRackauckas

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

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
Conversation: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master)

xtalax and others added 16 commits October 14, 2026 17:43
…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
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Independent review (Codex CLI 0.166.0 / gpt-6.1-sol), session 01a19819-4498-7d63-80d6-46cf1c2899ed, reviewed head c3b8499

  • Verdict: CHANGES
  • Risk: high (H1: a supported existing configuration throws before its in-place residual can be used; initial blind rating was medium under M3 for the extra code-generation pass, raised after confirming this compatibility regression).
  • Round / slot: 1 / 1
  • Blocking priorities: P2

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 Float64(::Dual) error. An independent analytic probe passes IIP-only generation on base and gets an ArgumentError on head. CI exercises the affected tests but has failures elsewhere; recent master jobs are green, so matching baseline failures were not established.

Blocking findings

  1. [P2] Confirmed by running: lib/ModelingToolkitBase/src/systems/codegen.jl:383 enters the new two-body generation branch even when codegen_opts.iip_config[1] is false. Symbolics then supplies a named unimplemented OOP stub, while branch_on_residual_eltype at lib/ModelingToolkitBase/src/systems/codegen.jl:164 requires an anonymous tuple signature. For complete(System([D(z) ~ k .* z], t, [z], [k]; name=:probe)) with 20 array elements, generate_rhs(sys; implicit_dae=true, iip_config=(false,true), expression=Val{true}) succeeds on base and its IIP function exactly returns the analytic k*u-du. The same call on head throws ArgumentError: Expected a generated function expression before returning the valid IIP function. Guard the second generation and branch combination with the OOP-enabled option, retain the original disabled OOP stub, and test this configuration.

Non-blocking findings

  1. [P3] lib/ModelingToolkitBase/src/systems/codegen.jl:136: tuple parameter buffers contribute no numeric type. ForwardDiff.jacobian(theta -> prob.f(du, u, Tuple(replace(Tunable(), p, theta)), t), [2.0]) still throws Float64(::Dual) for the 20-element array DAE instead of returning an all-ones column. This also fails on base, so it is an existing limitation, not the compatibility blocker above. Consider recursively promoting supported tuple buffer types and adding parameter-only AD coverage for them.
  2. [P3] lib/ModelingToolkitBase/src/systems/codegen.jl:387: the second wrapper build also generates an IIP body that is discarded. The new allocation tests measure residual evaluation, not construction cost. Add an array-DAE generation benchmark and consider requesting only the OOP variant on the second pass.

What I ran

  • Read the rules and repository guidance; ran git -C src fetch origin '+refs/pull/5244/head:refs/remotes/pr/5244' master, git -C src rev-parse HEAD origin/master, git -C src merge-base origin/master HEAD, and git -C src diff origin/master...HEAD (exit 0). The merge-base is the Base above; the fetched current master is 661303665a43b215c059a7eacbc753a169106056. Froze the blind assessment with sha256sum INITIAL.md > INITIAL.sha256 before reading author context.
  • Retrieved live PR metadata with gh pr view 5244 --repo SciML/ModelingToolkit.jl --json body,title,baseRefOid,headRefOid; inspected issue 5053 and gh api --paginate repos/SciML/ModelingToolkit.jl/pulls/5244/commits (exit 0). The newest non-merge PR commit is 0dd52e8648a118688afa98d5196fc69982b9f094; author identifiers come only from its trailers.
  • Created the base worktree with git -C src worktree add --detach ../base bf209c9c2b761da61774a46c421ef179d99cfd2e (exit 0). Used one scratch environment, developing the appropriate ModelingToolkitBase checkout and running Pkg.instantiate(; update_registry=false, allow_autoprecomp=false) within each Julia invocation. Dependencies resolved to SymbolicUtils 4.54.0, Symbolics 7.48.0 and ForwardDiff 1.4.6.
  • Exactly three sequential Julia invocations, with the supplied shared depot represented by SHARED_DEPOT below:
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.jl

Head runner includes lib/ModelingToolkitBase/test/array_equation_dae.jl unchanged: exit 0, existing assertions 32/32, Dual inputs 180/180, callable parameters 2/2. Base runner includes an unchanged copy of that head test file against base: exit 1, existing assertions 32/32, Dual testset 74 passed / 8 failed / 1 errored. The eight failures check the new branch structure; the error independently demonstrates the original Dual conversion bug. The later callable testset is not reached on base. The base runner catches the reported regression failure only to run diagnostics and then exits 1.

The independent probe uses D(z) ~ k*z, 20 elements, u=ones(20), du=zeros(20), k=2, and the analytic references k*u-du and parameter Jacobian ones(20,1). Base: normal residual error 0.0; IIP-only error 0.0; tuple parameter AD throws. Head probe: exit 1; normal residual error 0.0; IIP-only ArgumentError; tuple parameter AD throws. Probe exceptions are printed and counted explicitly.

  • Inspected gh pr checks 5244 --repo SciML/ModelingToolkit.jl and failed logs via gh run view RUN_ID --repo SciML/ModelingToolkit.jl --log-failed. Sublibrary CI reports 214 passing array-DAE assertions, but InterfaceI fails on a parsing default-size error and RegressionI on Latexify references. IntegrationTest fails with state/observed indexing BoundsErrors; Documentation fails link checking. Compared with gh run list --repo SciML/ModelingToolkit.jl --branch master --event push --limit 5: all five completed runs are successful, including master Sublibrary CI. These failures were not verified to occur on master and are not asserted to be caused by this PR.

What I did not verify

No 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
Conversation: https://claude.ai/code/session_01379heiiB35TtywhR7uSU74

AayushSabharwal and others added 30 commits November 16, 2026 12:30
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)

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.

Support Dual propagation in out-of-place DAE array residuals