Repository navigation
Preserve contiguous array derivative views in implicit residual codegen (supersedes #5242) - #5353
Conversation
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
Conflict in lib/ModelingToolkitBase/test/array_equation_dae.jl: both sides appended new testsets at the end of the file; kept both. Agent-Harness: Claude Code 2.1.312 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>
| groups = Dict{SymbolicT, Vector{Int}}() | ||
| for (i, v) in enumerate(dvs) | ||
| parent, indexed = split_indexed_var(v) | ||
| indexed && push!(get!(groups, parent, Int[]), i) |
There was a problem hiding this comment.
| indexed && push!(get!(groups, parent, Int[]), i) | |
| indexed && push!(get!(Vector{Int}, groups, parent), i) |
There was a problem hiding this comment.
Applied in 6f089edd41.
🤖 Posted by an AI agent · harness: Claude Code 2.1.319 · model: claude-sonnet-5-5
Review: unreviewed
Session: de59b94f-0227-49ea-adb5-b158639dad0b
| du_view = Symbolics.STerm( | ||
| view, | ||
| Symbolics.SArgsT((du, a:b)); | ||
| type = Any, shape = SU.ShapeVecT([1:(b - a + 1)]) |
There was a problem hiding this comment.
| type = Any, shape = SU.ShapeVecT([1:(b - a + 1)]) | |
| type = Any, shape = SU.ShapeVecT((1:(b - a + 1),)) |
There was a problem hiding this comment.
Applied in 6f089edd41.
🤖 Posted by an AI agent · harness: Claude Code 2.1.319 · model: claude-sonnet-5-5
Review: unreviewed
Session: de59b94f-0227-49ea-adb5-b158639dad0b
| op = operation(term) | ||
| arg = only(arguments(term)) | ||
| parent, _ = split_indexed_var(arg) | ||
| if isequal(op, D) && haskey(arrays, parent) |
There was a problem hiding this comment.
| if isequal(op, D) && haskey(arrays, parent) | |
| if isequal(op, D)::Bool && haskey(arrays, parent) |
Julia can and likely will refuse to infer this, since op::Any.
There was a problem hiding this comment.
Applied in 6f089edd41, with the ::Bool assertion on isequal(op, D).
🤖 Posted by an AI agent · harness: Claude Code 2.1.319 · model: claude-sonnet-5-5
Review: unreviewed
Session: de59b94f-0227-49ea-adb5-b158639dad0b
| arg = only(arguments(term)) | ||
| parent, _ = split_indexed_var(arg) | ||
| if isequal(op, D) && haskey(arrays, parent) | ||
| subs[term] = unwrap(Symbolics.substitute(wrap(arg), Dict(wrap(parent) => wrap(arrays[parent])))) |
There was a problem hiding this comment.
| subs[term] = unwrap(Symbolics.substitute(wrap(arg), Dict(wrap(parent) => wrap(arrays[parent])))) | |
| subs[term] = SU.IRSubstituter{false}(ir, Dict{SymbolicT, SymbolicT}(parent => arrays[parent]))(arg) |
wrap is evil
There was a problem hiding this comment.
Would be nice to move the Dict allocation outside the loop and reuse it.
There was a problem hiding this comment.
Applied in 6f089edd41: the substitution uses SU.IRSubstituter{false}(ir, ...) and no longer goes through wrap.
🤖 Posted by an AI agent · harness: Claude Code 2.1.319 · model: claude-sonnet-5-5
Review: unreviewed
Session: de59b94f-0227-49ea-adb5-b158639dad0b
There was a problem hiding this comment.
Done in 6f089edd41: one parent_subs Dict is allocated before the loop and refilled with empty! plus a single entry on each iteration. The subs Dict itself cannot be reused this way, since later terms depend on earlier substitutions.
🤖 Posted by an AI agent · harness: Claude Code 2.1.319 · model: claude-sonnet-5-5
Review: unreviewed
Session: de59b94f-0227-49ea-adb5-b158639dad0b
| # Noncontiguous or interleaved layouts cannot share a single `du` view. | ||
| expanded = SymbolicT[term] | ||
| expand_array_derivatives!(expanded, ir) | ||
| subs[term] = unwrap(Symbolics.substitute(wrap(only(expanded)), subs)) |
There was a problem hiding this comment.
| subs[term] = unwrap(Symbolics.substitute(wrap(only(expanded)), subs)) | |
| subs[term] = SU.IRSubstituter{false}(ir, subs)(only(expanded)) |
There was a problem hiding this comment.
This and the previous substitution look like they might be very small, so it could be worth just calling SU.substitute BUT it should never have to call wrap.
There was a problem hiding this comment.
Applied in 6f089edd41: subs[term] = SU.IRSubstituter{false}(ir, subs)(only(expanded)), with no wrap.
🤖 Posted by an AI agent · harness: Claude Code 2.1.319 · model: claude-sonnet-5-5
Review: unreviewed
Session: de59b94f-0227-49ea-adb5-b158639dad0b
There was a problem hiding this comment.
Kept IRSubstituter rather than SU.substitute in 6f089edd41; neither path calls wrap now.
🤖 Posted by an AI agent · harness: Claude Code 2.1.319 · model: claude-sonnet-5-5
Review: unreviewed
Session: de59b94f-0227-49ea-adb5-b158639dad0b
…ocations Use IRSubstituter instead of wrap-based Symbolics.substitute, reuse a single Dict across the loop, assert the isequal result type, and use the suggested get!/ShapeVecT forms. Agent-Harness: Claude Code 2.1.319 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>
|
Pushed
🤖 Posted by an AI agent · harness: Claude Code 2.1.325 · model: claude-sonnet-5-5 |
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>
|
Will merge once CI finishes |
|
Pushed
🤖 Posted by an AI agent · harness: Claude Code 2.1.325 · model: claude-sonnet-5-5 |
|
CI on 🤖 Posted by an AI agent · harness: Claude Code 2.1.325 · model: claude-sonnet-5-5 |
|
Both DAE fixes (#5274 and this PR, array derivative arguments in the residual codegen) are now merged. The earlier request still stands: a patch release of ModelingToolkit and ModelingToolkitBase containing both would let the downstream package stop pinning an integration branch. 🤖 Posted by an AI agent · harness: Claude Code 2.1.325 · model: claude-sonnet-5-5 |
Keep both the dropped-structural-keyword testsets and the array derivative code size testset from SciML#5353. 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>
|
Thank you for the ModelingToolkitBase v1.81.0 release; it contains both DAE array-unknown fixes (#5274 and #5353), so the downstream package can move to the registered version. 🤖 Posted by an AI agent · harness: Claude Code 2.1.325 · model: claude-sonnet-5-5 |
Supersedes #5242 (itself an adoption of the stalled #5121). Fixes #5097.
This is the #5242 change set with current master merged in via a merge commit, because the PR head lives on a fork we cannot push to. The original commits are unchanged and keep their authorship and
Agent-*trailers: Christopher Rackauckas (original work in #5121, with Codex) and ChrisRackauckas-Claude (review follow-ups, with Cursor Agent). Thanks to Chris for the original change; the AI-disclosure sections and the Claude Code and Codex reviews are in #5242.Summary: implicit DAE residuals no longer expand each array derivative into one scalar
duread per element. Contiguous derivative blocks are bound asreshape(view(du, a:b), size), so generated residual code size no longer grows with state dimension. Non-contiguous layouts fall back to the existing scalar expansion.Conflict resolution: one test-only conflict in
lib/ModelingToolkitBase/test/array_equation_dae.jlagainst #5302; both sets of testsets were kept.Conflicts with #5274: this PR and #5274 both touch
generate_rhsinlib/ModelingToolkitBase/src/systems/codegen.jlandlib/ModelingToolkitBase/test/array_equation_dae.jl. Whichever merges second needs a small rebase.Verification:
GROUP=InterfaceIfor ModelingToolkitBase passes (2050 pass, 5 broken, 0 fail), includingarray_equation_dae.jl. Runic 1.13.0 is clean on the touched files. Codex review against upstream/master: approve, 0 findings.Open point carried over from #5242: the reserved
__mtk_dae_dusentinel makes a user parameter of that name throw anArgumentErroron this path, where master accepted it (Codex finding H1 in #5242). A collision-free sentinel would avoid that; it is unchanged here.🤖 Posted by an AI agent · harness: Claude Code 2.1.312 · model: claude-sonnet-5-5
Review: unreviewed
Session: de59b94f-0227-49ea-adb5-b158639dad0b