Skip to content

Accept ctx arg in late_binding_update_u0_p for SciMLBase v3.1.0+#4474

Open
ChrisRackauckas-Claude wants to merge 2 commits intoSciML:masterfrom
ChrisRackauckas-Claude:fix-late-binding-update-u0-p-ctx
Open

Accept ctx arg in late_binding_update_u0_p for SciMLBase v3.1.0+#4474
ChrisRackauckas-Claude wants to merge 2 commits intoSciML:masterfrom
ChrisRackauckas-Claude:fix-late-binding-update-u0-p-ctx

Conversation

@ChrisRackauckas-Claude
Copy link
Copy Markdown

Summary

SciMLBase v3.1.0 (commit 09770ffa, 2026-04-10, refactor: pass context struct to late_binding_update_u0_p) added a trailing ctx::SciMLBase.LateBindingUpdateU0PContext argument to late_binding_update_u0_p. The 6-arg public entry point now forwards ctx as an 8th positional argument internally.

MTK's existing 7-arg overload no longer dispatches against the new 8-arg call site, so SciMLBase's default 8-arg fallback (return newu0, newp) wins and silently drops the Initial(x) parameter propagation in reinit! (and any other call path that goes through late_binding_update_u0_p).

which(...) evidence on the regression:

julia> which(SciMLBase.late_binding_update_u0_p, Tuple{ODEProblem, AbstractSystem, Vector{Pair}, Missing, Float64, Vector{Float64}, MTKParameters, SciMLBase.LateBindingUpdateU0PContext})
late_binding_update_u0_p(prob, sys, u0, p, t0, newu0, newp, ctx::SciMLBase.LateBindingUpdateU0PContext) in SciMLBase   # generic fallback

This PR adds the optional ctx argument to MTK's overload, restoring dispatch under SciMLBase v3.1.0+. The function body is unchanged; this is a 3-line signature update in lib/ModelingToolkitBase/src/systems/nonlinear/initializesystem.jl (lines 686-689).

function SciMLBase.late_binding_update_u0_p(
        prob, sys::AbstractSystem, u0, p, t0, newu0, newp,
        ctx::SciMLBase.LateBindingUpdateU0PContext = SciMLBase.LateBindingUpdateU0PContext()
    )

Fixes #4473.

Unblocks SciML/OrdinaryDiffEq.jl#3553 (which marks the now-fixed reinit! assertions @test_broken until this lands).

Test plan

  • Run Runic on the touched file (fredrikekre/runic-action@v1, version 1, matches .github/workflows/FormatCheck.yml). No formatting changes beyond the patch itself.

  • Verified locally with the OrdinaryDiffEq.jl NLS_MTK testset: lib/OrdinaryDiffEqNonlinearSolve/test/modelingtoolkit/dae_initialize_integration.jl, testset `reinit!` updates initial parameters (the same one referenced by issue reinit!(integ, new_u0) doesn't update Initial parameters or integ[x] for mtkcompile'd ODE #4473). With the patched MTK developed into the test env (using SciMLBase v3.6.0 from the resolved Manifest):

    Test Summary:                        | Pass  Total  Time
    `reinit!` updates initial parameters |    8      8  4.0s
    

    All 8 assertions pass — both the pre-reinit! checks and the 4 post-reinit! checks (integ.ps[Initial(x)], integ.ps[Initial(y)], integ[x], integ[y]) that the issue identifies as failing.

  • CI on this PR (Tests / Downstream / FormatCheck).

🤖 Generated with Claude Code

SciMLBase v3.1.0 (commit 09770ffa, 2026-04-10, "refactor: pass context
struct to late_binding_update_u0_p") added a trailing
`ctx::LateBindingUpdateU0PContext` argument (with default) that the v3
public path now forwards as an 8th positional. MTK's 7-arg overload no
longer dispatches; SciMLBase's 8-arg no-op fallback wins, so
`newp.initials` was never updated and `initialize_dae!` then re-solved
`u` against the stale `Initial` values. This surfaced as four failing
assertions in the OrdinaryDiffEq.jl `reinit! updates initial parameters`
testset (lib/OrdinaryDiffEqNonlinearSolve/test/modelingtoolkit/dae_initialize_integration.jl:98-101).

Wraps the original body in a small `_late_binding_update_u0_p_impl`
helper and dispatches via `@static if isdefined(SciMLBase,
:LateBindingUpdateU0PContext)` so the patch keeps working on the
SciMLBase v2 line that the package's `[compat]` still supports
(`SciMLBase = "2.149.0, 3"`). On v3.1.0+ the 8-arg method matches; on v2
the 7-arg method is defined as before.

Verified locally: with this patch and SciMLBase v3.6.0 resolved, the
OrdinaryDiffEq `reinit! updates initial parameters` testset goes from
4 fail / 4 pass to 8 / 8 pass.

Fixes SciML#4473.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
@ChrisRackauckas-Claude ChrisRackauckas-Claude force-pushed the fix-late-binding-update-u0-p-ctx branch from fa0b071 to e53a79f Compare April 25, 2026 00:32
Comment thread lib/ModelingToolkitBase/src/systems/nonlinear/initializesystem.jl Outdated
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.

reinit!(integ, new_u0) doesn't update Initial parameters or integ[x] for mtkcompile'd ODE

2 participants