Skip to content

Write initialization guesses through array slice indices - #5143

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix/array-slice-initialization-guesses
Oct 16, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix/array-slice-initialization-guesses

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

Initialization guess writes to array slices currently fail because write_possibly_indexed_array! assumes every indexed variable has a scalar stable index. Assign array-valued guesses through the slice's original indices while retaining the scalar path. Existing parent entries remain intact outside the slice, and numeric versus symbolic values retain the atomic map's existing representation.

This is an additional upstream prerequisite for SciML/MethodOfLines.jl#695, reached after fixing derivative naming of interior slices in JuliaSymbolics/Symbolics.jl#1986. It is separate from shaped default derivative guesses in #5132 and the DAE array-unknown constructor work.

Regression evidence

The same regression was run against unmodified master 21814d32c and after applying the helper change:

TMPDIR="$PWD/tmp" julia +1.12 --compiled-modules=existing --project=array_slice_guess_env array-slice-guess-regression.jl

Before:

ArgumentError: Invalid variable a[2:2:4] for `get_stable_index`.
Test Summary:                                   | Error  Total  Time
write_possibly_indexed_array! with array slices |     4      4  6.3s
  shape=(5,) initialized=false                  |     1      1  3.9s
  shape=(5,) initialized=true                   |     1      1  0.5s
  shape=(3, 4) initialized=false                |     1      1  1.7s
  shape=(3, 4) initialized=true                 |     1      1  0.2s

After:

Test Summary:                                   | Pass  Total  Time
write_possibly_indexed_array! with array slices |   16     16  7.1s

The scratch script contains the same testset added to the official variable_utils.jl. It covers stepped vector slices and matrix slices, numeric and symbolic replacement arrays, and empty and populated parent maps.

Validation

  • GROUP=InterfaceII julia +1.12 --project=array_slice_guess_env -e 'using Pkg; Pkg.test("ModelingToolkitBase")': 7462 passed, 2 pre-existing broken; exit 0. The official Variable Utils testset passes 165/165, including all 16 added assertions.
  • Full QA: JET 54/54 passed; Aqua 20 passed, 1 failed on the 234 existing Moshi unbound-type-parameter reports tracked at ModelingToolkitBase QA lane red since #4832: JET typo mode reports 263 errors, 234 of them from Moshi @match codegen #5063. The same reports reproduce on clean master. No QA assertion was changed.
  • Runic on both changed Julia files, typos over added lines, and git diff --check: pass.
  • With the separate constructor and Symbolics slice patches, the six-point heat model with an array unknown and interior array equation passes 6/6: inferred initial derivatives, flat numerical buffers and differential mask, successful DFBDF solve, and the analytic discrete heat solution. Initialization is enabled.

No public API, dependency, or documentation changes. GPU and other downstream suites were not run locally.

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 (independent review, Claude Code 2.1.301 claude-opus-5-5, reviewed head 572a04b)

  • Risk: low
  • Blast radius: One internal helper, write_possibly_indexed_array! (lib/ModelingToolkitBase/src/atomic_array_dict.jl). Only keys with ndims(k) > 0 take the new branch, and every such key used to throw in get_stable_index. Scalar-index writes run the same code as before. No public API, dependency or version change.
  • Evidence:
  • Independent review: Claude Code 2.1.301 claude-opus-5-5 rated it low, high confidence: a small change that only replaces an error with a correct write, shown by the fail-before/pass-after run above.
  • Merge: auto-merge candidate. Small internal change, no regressions caused by the PR, and all red checks reproduce on master or match known Symbolics breakage.

🤖 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

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 16, 2026 11:34
@ChrisRackauckas
ChrisRackauckas merged commit 2b821a5 into SciML:master Oct 16, 2026
104 of 111 checks passed
ChrisRackauckas referenced this pull request Oct 17, 2026
…5284)

Bump versions: ModelingToolkitBase 1.77.5, ModelingToolkit 11.45.5
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Agent-Harness: Claude Code 2.1.302
Agent-Model: claude-sonnet-5-5
Claude-Session: https://claude.ai/code/session_01VZjwf7Ux9YtTzwHGHMqnsq
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.

2 participants