Repository navigation
Zero array-element derivatives in NonlinearSystem conversion (facet A of #5066) - #5240
Draft
ChrisRackauckas-Claude wants to merge 4 commits into
Draft
ChrisRackauckas-Claude wants to merge 4 commits into
ChrisRackauckas-Claude wants to merge 4 commits into
Conversation
Substitution rules keyed only on D(x) for whole-array unknowns left D(x[i]) in residuals when unknowns stayed unscalarized after flattening. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Cursor Agent <noreply@cursor.com> Agent-Harness: Cursor Agent CLI 2026.09.28-64d2043 Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/orch-ibmtk/jobs/5066-cursor/log.txt on amdci2.julia.csail.mit.edu
Covers issue SciML#5066 facet A: unscalarized array unknowns with D(x[i]). Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Cursor Agent <noreply@cursor.com> Agent-Harness: Cursor Agent CLI 2026.09.28-64d2043 Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/orch-ibmtk/jobs/5066-cursor/log.txt on amdci2.julia.csail.mit.edu
AayushSabharwal
approved these changes
Oct 6, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ignore until reviewed by @ChrisRackauckas.
Summary
NonlinearSystem(sys)substitution rules were keyed only onD(x)for whole-array unknowns, soD(x[i])survived when unknowns stayed unscalarized after hierarchical flattening, andcompletethen rejected the leftoverDifferential. This adds element-wiseD(x[i]) => Symbolics.COMMON_ZEROrules (used afterexpand_array_derivatives!as well) and a regression test for issue #5066 facet A.Review follow-up: @AayushSabharwal's suggestion applied — use
Symbolics.COMMON_ZEROinstead of0.0, with the existingSU.is_array_shapeguard on the element loop.Part of #5066 (facet A only; facet B already fixed by #5163; facet C not addressed).
Fail before / pass after
On master
NonlinearSystem(no element rules):With the fix (incl. COMMON_ZERO suggestion commit
48dfa3629d):(steady-state solve:
x[1]≈2/3,x[2]≈1/3,y≈2/3from the issue's equations withD≡0)Verification
Tail (post-COMMON_ZERO validation run):
Also: Runic
--checkon touched files (exit 0);typoson touched files (clean).Not verified
All/ other GROUP suites beyond InterfaceII.What a reviewer should push back on
steady_state_initialization_eqsdoes (equations path currently only unknowns, matching prior behaviour).Risk assessment
NonlinearSystemsubstitution-rule construction.Please ignore this draft until reviewed by @ChrisRackauckas.
Harness: Cursor Agent CLI 2026.09.28-64d2043; model: auto; transcript: /log.txt
Risk assessment (independent review, Claude Code 2.1.301 claude-opus-5-5, reviewed head fba58bf)
ModelingToolkitBase.NonlinearSystem(sys::System)substitution rules only. AddsD(x[i]) => 0rules for array-shaped unknowns (whole-arrayD(x)rule kept; its value changes from0.0toSymbolics.COMMON_ZERO). Affects steady-state conversion of systems whose unknowns are unscalarized arrays; scalar-unknown systems get identical rules apart from the zero constant. No public API change, no new deps.fba58bfda43a7ec1a1169ae9ffa3a2238d7eba34. Ranlib/ModelingToolkitBase/test/nonlinearsystem.jl(Julia 1.13, local env developing the checkout): PR source 137/137 pass; same test file withlib/ModelingToolkitBase/srcfrom master (5abac29) 128 pass, 1 error in the new testset "NonlinearSystem conversion: array-element derivatives are zeroed" — fail-before / pass-after confirmed. Issue facet A reproducer: master throwsEncountered operator `Differential(t, 1)` which has different independent variable; PR givesSuccess x=[0.6667, 0.3333] y=0.6667. Extra case with a slice derivativeD(z[1:2]) ~ [...]plusD(z[3])on a 3-vector: master errors the same way, PR solves toz=[2/3, 1/3, 1]. CI: 101 pass; the 6 failures are pre-existing — InterfaceI "Parsing Test" and RegressionI "Latexify recipes Test" error under Symbolics 7.45 (e.g. https://github.com/SciML/ModelingToolkit.jl/actions/runs/38850867728/job/116822205989), fixed on master by Update MTKBase tests and compat floors for Symbolics 7.43-7.45 #5281 (06b51a1) after this run; DocumentationbuildandSciMLBase.jl/SymbolicIndexingInterfaceintegration also fail on master (https://github.com/SciML/ModelingToolkit.jl/actions/runs/38856355754, https://github.com/SciML/ModelingToolkit.jl/actions/runs/38856355740). InterfaceII (which runs NonlinearSystem Test) green.🤖 Posted by an AI agent — harness: Claude Code 2.1.301 · model: claude-opus-5-5 (independent reviewer; appended by Claude Code 2.1.301 · claude-opus-5-5)
Conversation: https://claude.ai/code/session_01VZjwf7Ux9YtTzwHGHMqnsq
Risk assessment (independent review, Codex gpt-6.1-sol, head fba58bf)
ModelingToolkitBase.NonlinearSystem(sys::System)derivative substitution, including unscalarized array unknowns and expanded slices. This does not modify the generalSystemconstructor ormtkcompileimplementation. No new public names, dependencies, copyleft licenses, skipped tests, loosened tolerances, or documented breaking changes; new-public-name documentation and a SemVer major bump are not applicable.git diff origin/HEAD...HEAD, the linked issue, and the risk rubric.git diff --check origin/HEAD...HEADpassed; checkout status stayed clean. Local Julia was 1.12.4, with Symbolics 7.46.0 and NonlinearSolve 4.32.0 resolved identically for head and base. G1 pass: the new test's reference values follow independently fromy=x[1]=2x[2],y+x[2]=1. G2 not applicable: no GPU kernels, AD rules, Reactant tracing, or MPI paths change; the CPU converter was exercised locally. G3 not applicable: the new dictionary is local; no shared state, cache, threading, or global default changes.Local commands used
JULIA_DEPOT_PATH=<local path>,JULIA_NUM_THREADS=4, and scratch-local temporary files. In the commands below,Sdenotes<local path>. Tests ran sequentially against scratch package copies; the checkout was never edited.timeout 3600 julia --startup-file=no --project="$S/env" "$S/run-target.jl" head: exit 0,Targeted NonlinearSystem | 137 137 9m22.9s. This includes the entire officiallib/ModelingToolkitBase/test/nonlinearsystem.jlfile.timeout 3600 julia --startup-file=no --compiled-modules=existing --project="$S/base-env" "$S/run-target.jl" base: exit 1 against the fullorigin/HEADpackage snapshot, commit91fd79ea48;128 passed, 1 errored. The sole error is the added testset at line 567:Encountered operator Differential(t, 1) which has different independent variable ... nothing, contextDifferential(t, 1)((x(t))[1]).timeout 3600 julia --startup-file=no --compiled-modules=existing --project="$S/env" "$S/run-probes.jl": exit 0. Matrix solution[2 3; 3 4], slice solution[0.5, 0.5, 1.0], and scalar equations equal to those obtained with the original substitution rules. API output:Symbolics.COMMON_ZERO public=false;SymbolicUtils.zero_of_vartype public=true; the public zero constructor's result was asserted equal toCOMMON_ZERO.gh pr checks,gh run view, andgh api .../actions/jobs/.../logscomparisons: four PR InterfaceI/RegressionI jobs fail, while the matching default-branch jobs pass at commit06b51a13after its test updates. PR docs and default-branch docs both fail because the OpenModelica link-check curl exits 28. PR and default-branch SciMLBase indexing jobs both error atcomprehensive_indexing.jl:127and:164, with the same one-element-vectorBoundsError. The listed downgrade Optimization job is cancelled, not a demonstrated test failure. See the CI links below.🤖 Posted by an AI agent — harness: Codex CLI 0.162.1 · model: gpt-6.1-sol
Conversation: local headless review run (no public session URL); transcript kept by the fleet master.