Skip to content

Fix CheckInit for immutable out-of-place mass-matrix residuals - #1629

Merged
ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/1610-checkinit-immutable
Oct 3, 2026
Merged

ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/1610-checkinit-immutable

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

Please ignore until reviewed by @ChrisRackauckas.

Summary

CheckInit masked algebraic residuals with in-place broadcast (tmp .= ...), which throws setindex! on immutable out-of-place RHS outputs such as SVector. Rebind with tmp = ArrayInterface.restructure(...) instead; tmp is only consumed by the residual norm check below, so this is safe for mutable arrays too. Adds a downstream regression covering consistent SVector mass-matrix ODEs via get_initial_values and Rodas5P.

Fail-before / pass-after

Scratch env: path-dev SciMLBase + OrdinaryDiffEqRosenbrock + StaticArrays, private compile depot, JULIA_NUM_THREADS=1.

1. Issue MWE (solve(prob, Rodas5P()))

using OrdinaryDiffEqRosenbrock, StaticArrays, SciMLBase
f(u, p, t) = SA[-u[1] + u[2], u[1] + u[2] - 1.0]
prob = ODEProblem(ODEFunction(f, mass_matrix = [1.0 0.0; 0.0 0.0]), SA[1.0, 0.0], (0.0, 1.0))
sol = solve(prob, Rodas5P())

Fail-before (master tmp .= at initialization.jl:264, exit 1):

SciMLBase: 3.57.0
mode: mwe_fail_before
Calling solve(prob, Rodas5P())...
REPRODUCED_ERROR:
setindex!(::SVector{2, Float64}, value, ::Int) is not defined.
  [9] get_initial_values(...) at initialization.jl:264

Pass-after (rebinding fix, exit 0):

SciMLBase: 3.57.0
mode: mwe_pass_after
Calling solve(prob, Rodas5P())...
SOLVE_OK retcode=Success u_end=[0.5676676478636662, 0.4323323521363338] sum=1.0

2. Committed regression testset (extracted from test/downstream/initialization.jl)

Fail-before (src reverted to tmp .=, exit 1):

SciMLBase: 3.57.0
mode: testset_fail_before
SVector out-of-place mass matrix: Error During Test
  Got exception outside of a @test
  setindex!(::SVector{2, Float64}, value, ::Int) is not defined.
      @ SciMLBase .../src/initialization.jl:264
Test Summary:                    | Error  Total   Time
SVector out-of-place mass matrix |     1      1  16.6s

Pass-after (fix restored, exit 0):

SciMLBase: 3.57.0
mode: testset_pass_after
Test Summary:                    | Pass  Total   Time
SVector out-of-place mass matrix |    4      4  32.8s
TESTSET_DONE

Also ran Runic --check and typos on touched files (both clean).

Not verified

  • Full test/downstream/initialization.jl (ModelingToolkit/Sundials-heavy); only the new SVector testset was extracted and run.
  • Full GROUP=Downstream suite.
  • Whether other testsets in that file fail on this branch vs master was not checked (only the new testset was executed).

Reviewer pushback

  • Prefer branching on ArrayInterface.ismutable(tmp) instead of always rebinding?
  • Should the same pattern be audited elsewhere for immutable residuals?

Fixes #1610

Please ignore this draft until reviewed by @ChrisRackauckas.

Risk assessment

  • Risk: low
  • Blast radius: CheckInit residual masking for mass-matrix AbstractDEProblems only; rebinding preserves values for mutable and immutable residuals
  • Evidence: issue MWE and committed SVector testset fail-before/pass-after with Rodas5P; Runic/typos clean
  • Independent review: Claude Code (Opus 5.5) rated it low, high confidence: tmp only feeds the CheckInit norm check, so rebinding loses no aliasing; tmp stays concretely typed (SVector{2,Float64} / Vector{Float64} in code_typed); full test/downstream/initialization.jl passes on this branch, and with master's tmp .= line only the new SVector testset errors; inconsistent u0 still raises CheckInitFailureError.
  • Merge: auto-merge candidate once CI shows no regressions vs master (author and reviewer both rate low). The SII downstream failure (SCCNonlinearProblem has no field u0) is shared with other open PRs and not caused by this change.

Harness: Cursor Agent CLI 2026.09.28-64d2043; model: auto; transcript: /home/crackauc/sandbox/goals/issue-backlog/ibd/SciMLBase.jl/jobs/1610-cursor/log.txt on amdci2.julia.csail.mit.edu

ChrisRackauckas and others added 3 commits September 30, 2026 08:08
In-place broadcast assignment into the residual fails for SVector and other
immutable arrays returned by out-of-place mass-matrix RHS evaluation.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.28-64d2043
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/SciMLBase.jl/jobs/1610-cursor/log.txt on amdci2.julia.csail.mit.edu
Covers consistent SVector u0 through get_initial_values and Rodas5P solve.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.28-64d2043
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/SciMLBase.jl/jobs/1610-cursor/log.txt on amdci2.julia.csail.mit.edu
StaticArraysCore alone lacks the convenience SVector constructors the
test needs; declare StaticArrays in the downstream test project.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.28-64d2043
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/SciMLBase.jl/jobs/1610-cursor/log.txt on amdci2.julia.csail.mit.edu
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review October 3, 2026 05:32
@ChrisRackauckas
ChrisRackauckas merged commit 432e985 into SciML:master Oct 3, 2026
66 of 73 checks passed
ChrisRackauckas referenced this pull request Oct 13, 2026
* Add a specialization marker to `OptimizationFunction`

`OptimizationFunction` had no specialization marker: its second type parameter is
the AD type, and `specialization(::OptimizationFunction)` returned that instead of
an `AbstractSpecialization`. The marker is now stored as the last type parameter,
after the field types, so code that spells out the existing parameters keeps
working. It defaults to `FullSpecialize`, so existing functions are unchanged.

`OptimizationFunction{iip, specialize}(f, adtype; kwargs...)` selects it, and
`specialization` returns it. `remake`, `ConstructionBase.setproperties` (and with
it `@set`) and `OptimizationProblem` keep it. The spelling that passes the AD
type as the second type parameter (`OptimizationFunction{iip, AD}(f; adtype)`)
still builds a `FullSpecialize` function.

What `AutoSpecialize` and `AutoDespecialize` do is up to the solver packages,
as for the other SciML functions.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* Convert parameter objects to `DespecializedParameters`

Storage typed for despecialized parameters could not be assigned a new parameter
object. For example, an optimization cache built from an `AutoDespecialize`
problem stores `p` as a `DespecializedParameters`, and `reinit!(cache; p = new_p)`
threw `Cannot convert an object of type ... to an object of type
SciMLBase.DespecializedParameters`. `convert` now wraps the object, and returns an
already wrapped one unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* Bump version to 3.58.0

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.

CheckInit errors on out-of-place mass-matrix DAEs with SVector states

2 participants