Skip to content

Handle array symbols in symbolic remake - #1602

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/array-symbolic-remake
Oct 31, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/array-symbolic-remake

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Sep 13, 2026 •

Copy link
Copy Markdown
Member

Symbolic remake now handles providers that enumerate whole-array variables or parameters while mapping their elements to flat numerical indices. Previously fill_vars mapped the array index range to its parent symbol, then looked up individual indices and raised KeyError: key 1 not found. The fix expands symbols locally, preserves parent and scalar defaults, and copies the defaults dictionary before expansion.

This is a prerequisite found while implementing array DAE unknowns for SciML/MethodOfLines.jl#695. Public symbol enumeration is unchanged; no dependencies or public API are added.

Regression evidence

The official SII_Remake group was run with the new vector/matrix regression on clean upstream source and again with the fix:

GROUP=SII_Remake TMPDIR="$PWD/tmp" JULIA_PKG_PRECOMPILE_AUTO=0 julia +1.12 --project=scimlbase-unfixed -e 'using Pkg; Pkg.test(; julia_args=["--compiled-modules=existing"])'
GROUP=SII_Remake TMPDIR="$PWD/tmp" JULIA_PKG_PRECOMPILE_AUTO=0 julia +1.12 --project=SciMLBase.jl -e 'using Pkg; Pkg.test(; julia_args=["--compiled-modules=existing"])'

Before (both array cases error before their assertions):

KeyError: key 1 not found
Test Summary:                                                                                        | Pass  Error  Total     Time
Remake                                                                                               | 4605      2   4607  4m04.8s

After, with the byte-identical test file:

Test Summary: | Pass  Total     Time
Remake        | 4631   4631  4m13.9s
Testing SciMLBase tests passed

The isolated array regression passed 26/26.

The cases cover variable and parameter arrays, vector and matrix shapes, parent and indexed keys, array name aliases, partial updates, sibling scalar values, default precedence, and nonmutation of caller defaults.

Validation

Runic confirmed both changed files already formatted. Typos over the diff and git diff --check passed.

Full QA passed with the system Python interpreter (the first attempt failed during Conda Python provisioning, before QA completed):

GROUP=QA TMPDIR="$PWD/tmp" JULIA_CONDAPKG_BACKEND=Null JULIA_PYTHONCALL_EXE=/usr/bin/python3 JULIA_PKG_PRECOMPILE_AUTO=0 julia +1.12 --project=SciMLBase.jl -e 'using Pkg; Pkg.test(; julia_args=["--compiled-modules=existing"])'
Test Summary: | Pass  Total      Time
QA            |  123    123  10m47.3s
Testing SciMLBase tests passed

No tests or assertions were disabled. An integration check with local ModelingToolkit array DAE support also passed 24/24 checks, covering initialization, a DFBDF solve, shape-preserving indexing, and symbolic remake.

A second integration run with the completed local ModelingToolkit constructor stack passed on Julia 1.10.12 and the minimum CI dependencies (Symbolics 7.37.0, SymbolicUtils 4.37.0, SymbolicIndexingInterface 0.3.46, NonlinearSolveBase 2.49.4). Only the MTKBase and SciMLBase source paths changed from the copied minimum-dependency manifest:

TMPDIR="$PWD/tmp" JULIA_PKG_PRECOMPILE_AUTO=0 julia +1.10.12 --project=array_constructors_downgrade_env array_constructors_downgrade_tests.jl

The driver uses the official SafeTestsets isolation for these three unchanged test files:

Array derivative initialization |  6/6   | 2m23.6s
Array DAE Unknowns               | 46/46  |   52.5s
Array unknown DAE Jacobians      | 96/96  |   11.5s

The constructor stack includes a separate MTK integer-index bound correction exposed by older SII; that correction is not part of this SciMLBase diff. Julia emitted the previously identified Moshi precompilation warning and continued loading; the test process completed with exit 0.

No docs or public API changed. GPU, the full downstream matrix, and prerelease Julia jobs were not run locally. Focused downstream controls are documented below.

Downstream failure investigation

Three downstream failures have independent baseline evidence; no tests were disabled or weakened to hide them.

  • SciMLSensitivity Core8: the unchanged official test/Core8/desauty_dae_mwe.jl fails identically on clean SciMLBase base source and this feature. Both use Julia 1.13.0, SciMLSensitivity a5a9b938aeca1eab8009fd35ec33bfea40656f33, ModelingToolkit 11.43.1, ModelingToolkitBase 1.71.1, NonlinearSolve 4.28.0, NonlinearSolveBase 2.49.5, and Enzyme 0.13.203; the manifests differ only in the SciMLBase source path. The sole error is EnzymeNoTypeError through CacheWriter{Any} during SCC initialization. A separate reduced parent/commit comparison identifies ModelingToolkit's initialization change: its immediate parent passes 2/2, and that commit errors. The reproducer and introduction boundary are tracked in Enzyme SCC initialization regresses at concretize_initializeprob on Julia 1.13 ModelingToolkit.jl#5140. No production fix is claimed here.

    Exact local commands (the first pins NonlinearSolve to the CI version):

    TMPDIR="$PWD/tmp" JULIA_PKG_PRECOMPILE_AUTO=0 julia +1.13.0 --project=scimlbase-sensitivity-ci-env -e 'using Pkg; Pkg.add(PackageSpec(name="NonlinearSolve", version="4.28.0")); include("scimlbase-sensitivity-check/test/Core8/desauty_dae_mwe.jl")'
    TMPDIR="$PWD/tmp" JULIA_PKG_PRECOMPILE_AUTO=0 julia +1.13.0 --project=scimlbase-sensitivity-ci-feature-env -e 'include("scimlbase-sensitivity-check/test/Core8/desauty_dae_mwe.jl")'
    # Clean base
    DAE with SCC Initialization | Pass 19  Error 1  Broken 5  Total 25  10m46.6s
    # Feature, identical test and dependency versions
    DAE with SCC Initialization | Pass 19  Error 1  Broken 5  Total 25  10m34.9s
    

    The five broken tests are pre-existing in the unchanged upstream file.

  • SciMLSensitivity Core1: the same LLVM 20 ClobberWalker / getMatchingValue / loadCSE crash occurs in the clean-base job and feature job. The standalone LLVM IR already published in Runtime loop unrolling hits a MemorySSA assertion llvm/llvm-project#222852 independently segfaults locally with Julia 1.13's LLVM 20 (exit 139), while LLVM 18 passes; its backtrace matches the leading CI frames. Julia 1.13: segfault in LLVM 20 loop unrolling on !invariant.group cache loads (tracks llvm/llvm-project#222852) EnzymeAD/Enzyme.jl#3568 tracks that defect. The exact solver-specific crash did not reproduce locally: the unchanged clean-base test prefix through the failing CI assertion passes 1/1 with matching package versions and coverage/check-bounds enabled. No monotonic SciMLBase source regression was established.

  • Catalyst ReleaseTest: both the clean-base job and feature job fail when the registered package's tests try to write test/extensions/Project.toml inside its read-only installed source. This was reproduced independently and is tracked with a reproducer in Extension test environment setup writes read-only installed Project.toml on Julia 1.13 Catalyst.jl#1561.

Please ignore this draft until reviewed by @ChrisRackauckas.

🤖 Generated with Codex CLI 0.154.0 (model: gpt-6-astra; local session ID: 01a099aa-308a-7fd3-91bd-9fb2dc357b91).

Risk assessment

  • Risk: low
  • Blast radius: Every symbolic remake(prob; u0 = [sym => val], p = [...]) goes through fill_vars ([remake_pr1602.jl:1827-1894](/remake_pr1602.jl)). That covers MTK, Catalyst, MethodOfLines and any direct SII SymbolCache user. The new branch only runs for symbols that are ArraySymbolic() and whose variable_index/parameter_index is an AbstractArray. In that case the array is split into its elements, and the parent's default is copied down to elements that have no default of their own. MTK's usual ParameterIndex path and scalarized unknowns don't reach the new code. A GitHub code search across the SciML org found no calls to fill_vars/fill_u0/fill_p outside SciMLBase's own tests. The API is internal and there is no SemVer impact. Edge cases the tests don't cover:
    • zip(sym, defval) silently truncates if an array symbol's default is a scalar or has the wrong shape.
    • For array symbols that remade without error before (parent key only), fill_vars now returns element keys instead of the parent key.
    • defs is copied once per array symbol that has a default. This costs a little performance on systems with many array parameters.
  • Evidence: 3 checks fail on head bd19191 (CI ran 2026-09-13). All 3 are pre-existing: each fails on all 6 recent master commits (83b4fc3, 9cfd9e6, d57a756, 4fa7f7f, b7076b5, 7013302), and I confirmed the matching log signatures on head and on 83b4fc3.
    • SciMLSensitivity.jl/Core8: same EnzymeNoTypeError on head and master. It did pass on the PR's merge base 573bc6c, so it started failing on master after the branch point. The PR attributes that to an MTK change (tracked in MTK issue 5140).
    • SciMLSensitivity.jl/Core1: same LLVM 20 ClobberWalker/getMatchingValue segfault on head, master and the merge base.
    • Catalyst/All/1: same SystemError ... Catalyst/tAUzg/test/extensions/Project.toml: Permission denied on head and master. Catalyst.jl/All passes on head.
    • Everything else passes on head: QA, Core (1/lts/x86/pre), SII, Downstream, DownstreamAD, Python, Downgrade, Docs, Runic, Typos, and all MTK/OrdinaryDiffEq/SciMLSensitivity Core2–7 downstream groups. No regressions.
    • The branch is 9 commits behind master and its CI is 13 days old. Master's src/remake.jl changes since the merge base don't touch fill_vars (they touch the function-remake type-erasure code, SteadyStateProblem's lowered_problem, and the SCC eltype), and GitHub reports the PR as MERGEABLE.
    • The diff only adds lines (+16 src, +52 test). No tests are skipped, loosened or removed. It uses only public SII names (symbolic_type, ArraySymbolic) plus the local varmap_get, so no non-public dependency internals.
  • Independent review: Devin CLI / fusion-claude-opus-5-5-high-sidekick-swe-2-medium rated it low, medium-high confidence: it is a small, additive fix to an internal function, it only runs in a case that used to throw KeyError, it has before/after regression evidence, and every failing check fails identically on current master.
  • Merge: needs human review. Findings:
    • The PR is a draft that explicitly says "Please ignore this draft until reviewed by @ChrisRackauckas", and it has zero reviews.
    • The head CI is stale (13 days, 9 commits behind master) and should be rerun after a rebase.
    • The description doesn't disclose that the output changes for the previously working parent-key-only array path (element keys instead of parent key).
    • There are no tests for scalar or mismatched-shape array defaults, which zip would silently truncate.
    • It's attributed to Codex CLI (gpt-6-astra) but posted from the ChrisRackauckas-Claude account, and it lacks the standard UNREVIEWED banner.

🤖 Risk assessment posted by an AI agent (fleet master) — harness: Devin CLI / fusion-claude-opus-5-5-high-sidekick-swe-2-medium; dispatched by Claude Code head, model claude-opus-5-5[1m]
Conversation: local Claude Code session 3cd6500a-1f81-46b5-ac0b-c466e15b6a53 (session ID, no URL)

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

Risk assessment (independent review, Codex Desktop (Codex core 0.164.0-alpha.11.1) gpt-6.1-sol, slot 1, head 68a5669)

  • Risk: medium-high (MH1: Changes the shared remake main lane in SciMLBase, even though the intended effect is a localized bug fix.)
  • Verdict: MERGE
  • Session: 01a18db8-25fc-7b72-9d35-a1341e0ae484
  • Blocking priorities: none

Review round 1, written by the reviewer named above (Codex Desktop (Codex core 0.164.0-alpha.11.1) / gpt-6.1-sol) in a session other than the PR author's, and copied here by the posting agent without change to its findings. The posting agent did not re-run the reviewer's commands.

Summary: Expands array symbols to scalar components during symbolic remake and preserves scalar/default precedence without mutating the provider defaults. Vector and matrix regression cases fail on base and pass 26 assertions at the reviewed head.

Blast radius: Symbolic remake of initial states and parameters supplied by unscalarized array-symbol providers.

Evidence: The test covers whole arrays by parent and alias, scalar element updates, untouched values, use_defaults, explicit scalar-default precedence and source-dictionary preservation. Local base errors with KeyError: key 1 not found for both shapes. The same SII downstream failure sites and counts (comprehensive_indexing.jl:127 and :164, 3747 pass/2 error) occur in the sampled default run; this does not establish equivalence of every other failed check.

Blocking findings

None.

Non-blocking findings

None.

What I ran

gh pr view 1602 --repo SciML/SciMLBase.jl --json number,url,state,isDraft,headRefOid,baseRefName,baseRefOid,title,files,commits,statusCheckRollup
git fetch origin "+refs/pull/1602/head:refs/remotes/pr/1602" "master" "365283c66ec24db40c3fae1f2694693070dd7a46"
git checkout --detach 68a5669b57700624f8a314f301740faba36ef4c5
git rev-parse HEAD
git diff 365283c66ec24db40c3fae1f2694693070dd7a46...HEAD
git diff --check 365283c66ec24db40c3fae1f2694693070dd7a46...HEAD
git log -1 --no-merges --format=%B 68a5669b57700624f8a314f301740faba36ef4c5
gh pr checks 1602 --repo SciML/SciMLBase.jl
gh pr view 1602 --repo SciML/SciMLBase.jl --json body,closingIssuesReferences

HEAD was verified equal to 68a5669b57700624f8a314f301740faba36ef4c5. git diff --check exited 0. The diff was compared to the recorded live base through its merge base, not directly against unrelated base-only commits. Root/nested agent instructions and surrounding changed-code callers were inspected. Author metadata above is from the newest non-merge commit only; absent trailers are intentionally unknown.

Local Julia processes ran sequentially with JULIA_NUM_THREADS=4, OPENBLAS_NUM_THREADS=1, an isolated temporary directory and a task-owned first depot (existing global depot read as a fallback). Commands used julia --startup-file=no --compiled-modules=no --project=<isolated-environment> after Pkg.develop selected the exact checkout. Focused tests were extracted unchanged from the named committed testset except for explicitly described reviewer probes; full Pkg.test was not run. Machine-specific scratch paths are omitted to follow the review-file rule.
Local head, Julia 1.13.0, exit 0:

remake with unscalarized array symbols |   26     26  2.0s

Local base, Julia 1.13.0, exit 1:

KeyError: key 1 not found
remake with unscalarized array symbols |     2      2  2.1s
shape (2,)                           |     1      1  1.7s
shape (2, 2)                         |     1      1  0.4s

Focused input: RemakeArraySymbol/RemakeArraySystem and the testset remake with unscalarized array symbols from test/remake_tests.jl.

CI inspection: gh run view <run-id> --repo SciML/SciMLBase.jl --log-failed, and for selected green jobs gh run view <run-id> --job <job-id> --repo SciML/SciMLBase.jl --log. Default-branch samples used gh run list --repo SciML/SciMLBase.jl --branch master --event push --limit 5 --json databaseId,conclusion,headSha,url,name; completed failing runs were read rather than assuming equivalence from status alone.

67 checks successful/skipped/neutral; 6 checks failed/cancelled/pending at the captured snapshot. These counts include external status checks.

Sampled current default-branch runs (status alone is not used to waive failures):

What I did not verify

No local full SII_Remake/ModelingToolkit/MethodOfLines integration, AD suite, or performance benchmark. The new Any[] normalization adds work to every fill_vars call; scaling was not benchmarked.

This review continues the interrupted Codex session 01a18dad-6f75-7ae1-b6dc-3a84553833ec, retaining its exact-head checkouts, CI logs and sequential test evidence. The continuation session is 01a18db8-25fc-7b72-9d35-a1341e0ae484. Initial risk ratings were saved before author descriptions; those descriptions contained embedded earlier reviews, so complete prior-review blindness was not maintained. The initial findings were frozen before the explicit same-head review comparison; additional corroboration is identified as post-freeze. This limitation is disclosed rather than claiming full blind-first compliance.

🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5
Conversation: https://claude.ai/code/session_01379heiiB35TtywhR7uSU74

@xtalax-droid

Copy link
Copy Markdown

Validation of this PR against a real ModelingToolkit array-unknown problem (@variables u(t)[1:6], D(u) ~ A*u, @parameters A[1:6,1:6]), using this branch's head (based on upstream 365283c) as the SciMLBase dependency. On upstream master the u0 forms below throw KeyError: key 1 not found.

remake call Result with this PR
u0 = [u => fill(0.5, 6)] u0 = [0.5, 0.5, 0.5, 0.5, 0.5, 0.5]
u0 = [u[5] => 0.3] [1, 2, 3, 4, 0.3, 6]
u0 = [u[2] => 0.1, u[5] => 0.3] [1, 0.1, 3, 4, 0.3, 6]
u0 = [u[5] => 0.3], use_defaults = true [1, 2, 3, 4, 0.3, 6] (the problem's own u0 took precedence over the system default here)
p = [A => 2I] diagonal of A becomes 2.0
p = [A[1, 2] => 7.0] KeyError: ParameterIndex{Tunable}(…, 7, false) not found

The last row also fails on an independent branch with a different fix for the same bug, so it looks separate from this PR; I did not check plain master.

Two further regression tests, written for that independent branch, also pass against this PR: a fake symbolic container whose array unknown has a range variable_index, covering [u => vec], one and two element updates, and a use_defaults = true partial update that must give [9, 9, 9, 9, 0.3, 9] from default_values; and a SymbolCache([:x], Dict(:a => 1:2, :b => 3)) case checking remake(prob; p = [:b => 5.0]) still returns [2, 3, 5].


🤖 Posted by an AI agent · harness: Claude Code 2.1.310 · model: claude-sonnet-5-5
Review: unreviewed
Session: b5eb1992-1a0f-4e2c-a174-f96b1d0f7fd3

Expand array parents locally when mapping flat state and parameter indices.
Preserve explicit scalar defaults without mutating caller dictionaries.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Codex <[email protected]>
Agent-Harness: Codex CLI 0.154.0
Agent-Model: gpt-6-astra
Agent-Session: local session ID 01a099aa-308a-7fd3-91bd-9fb2dc357b91
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review October 31, 2026 23:04
@ChrisRackauckas
ChrisRackauckas merged commit 030ec28 into SciML:master Oct 31, 2026
67 of 73 checks passed
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.

3 participants