Skip to content

Record the SCC lowering of a SteadyStateProblem on its system - #5155

Merged
ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:scc-steady-state-storage
Sep 17, 2026
Merged

ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:scc-steady-state-storage

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

Summary

SteadyStateProblem(sys, op) stores its SCC lowering in the new
SteadyStateProblem.lowered_problem field (SciMLBase 3.55,
SciML/SciMLBase.jl#1603): a prob -> problem callable that lazily
mtkcompiles the residual NonlinearSystem and returns the
SCCNonlinearProblem. The compiled residual system is memoized in a Ref,
while the operating point is rebuilt from the queried problem's u0/p via
calculate_op_from_u0_p — so remake(prob; u0 = ..., p = ...) produces a
lowering reflecting the new values, fixing the stale-construction-op capture
of the earlier metadata design.

Consumers:

  • SciMLBase.SCCNonlinearProblem(prob::SteadyStateProblem) (defined in
    MTKBase; generic fallback returns nothing) materializes the lowering —
    a verbatim AbstractSciMLProblem is returned as-is, anything else is
    treated as a builder and called on prob.
  • NonlinearProblem(prob) prefers the stored lowering over wrapping f
    (SciMLBase side), so SSRootfind-style solves and SteadyStateDiffEq.jl#166's
    DynamicSS/SSRootfind SCC routing pick the decomposition up
    automatically.
  • Storage is skipped on the expression = Val{true} codegen path —
    build_scimlproblem_expr embeds kwargs as literals and cannot embed a
    closure capturing sys.

steady_state_sccprob(sys, op; kwargs...) is the MTKBase stub + MTK impl
bridge, same pattern as get_initialization_problem_type.

Compat: SciMLBase = "3.55" on both ModelingToolkit and
ModelingToolkitBase — the guards that kept this inert on older SciMLBase
are removed.

Companion to SciML/SciMLBase.jl#1603 (merged, released in 3.55.0) and the
SSRootfind/DynamicSS SCCNonlinearProblem support in
SciML/SteadyStateDiffEq.jl#166.

Test plan

  • test/scc_nonlinear_problem.jl — all testsets pass, including
    "SteadyStateProblem stores its SCC lowering" (18 assertions): builder
    presence/callability, SCCNonlinearProblem(prob) materialization, 2-block
    LinearProblem+NonlinearProblem decomposition, getu-indexed
    operating-point values, NonlinearProblem(prob) preference, Newton solve →
    [1, 2, ∛3], remake-correctness regression (remake(prob; u0) produces
    a lowering reflecting the new operating point, not the construction op),
    build_initializeprob=false, nothing for ODEProblem
  • End-to-end with SteadyStateDiffEq.jl#166: solve(ssprob, DynamicSS())
    takes the sequential SCC path and solve(ssprob, SSRootfind(...)) runs the
    decomposition, with sol[states] indexing on the lowered problem
  • Discrimination: the testset MethodErrors without the change
  • MTK Aqua QA 20/20; MTKBase Aqua QA 20/20 (the
    SCCNonlinearProblem(::SteadyStateProblem) extension is allowlisted via
    INTENTIONAL_EXTERNAL_GENERIC_EXTENSIONS, matching MTKBase's ownership of
    SCCNonlinearProblem(::System) construction)
  • steady_state_sccprob added to NONPUBLIC_QUALIFIED_ACCESSES (same
    convention as get_initialization_problem_type)
  • Runic format + typos over the diff

Note: MTKBase's JET QA lane is red on master already — 234 ##And#…/##Call#…
"may be undefined" reports, the documented short-circuit-guard false positives
(JuliaLang/julia#62745, JET.jl#858) that forced jet = false on root MTK. No
report touches the files changed here.

🤖 Generated with Devin CLI (model: SWE-2 Max). Session: local transcript at /home/crackauc/.local/share/devin/cli/summaries/history_45335a77847a4532.md (no shareable URL for this harness).

SteadyStateProblem(sys, op) now tags `sys` (under the
`Type{SCCNonlinearProblem}` metadata key) with a deferred builder that
produces the SCCNonlinearProblem the steady-state residual lowers to:
the NonlinearSystem residual of the original uncompiled model is
mtkcompiled and decomposed into SCCs. The lowering is lazy — building it
requires a full mtkcompile that most SteadyStateProblem consumers never
need — and memoized on first access, and it rides on `prob.f.sys` so it
survives `remake`.

Retrieval goes through `SciMLBase.SCCNonlinearProblem(prob)`, which
returns `nothing` for problems that record no lowering, so downstream
solvers can detect SCC-decomposable steady-state problems without
knowing MTK internals. The MTKBase stub/hook split mirrors
`get_initialization_problem_type`: ModelingToolkitBase owns the ctor
tagging and the accessor, ModelingToolkit supplies the lowering.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: daily-primrose (local Devin CLI session ID, no shareable URL; workspace /home/crackauc/sandbox/tmp_20260913_211211_19443)
Moves the lowering association off the shared system metadata (which
captured the construction-time operating point and went stale after
remake) onto the problem itself. The stored value is a callable
`prob -> problem`: the mtkcompile'd residual system is memoized, while
the operating point is rebuilt from the queried problem's u0/p via
calculate_op_from_u0_p, so a remake'd SteadyStateProblem yields a
lowering matching its current values.

`SCCNonlinearProblem(prob::SteadyStateProblem)` reads the field, and
`NonlinearProblem(prob)` prefers it over wrapping f directly. Requires
the `lowered_problem` field from SciMLBase (SciML/SciMLBase.jl#1603);
on older versions the hasfield guards keep construction a no-op and the
accessor returns nothing.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: /home/crackauc/.local/share/devin/cli/summaries/history_f9264d4995564dac.md (local transcript; no shareable URL)
…blem

The field shipped in SciMLBase 3.55.0, so drop the hasfield guards and store
the SCC lowering builder unconditionally (still skipped on the codegen path).
The accessor dispatches on AbstractSciMLProblem rather than Base.Callable to
avoid a non-public qualified access.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: daily-primrose (local Devin CLI session ID, no shareable URL; workspace /home/crackauc/sandbox/tmp_20260913_211211_19443)
@ChrisRackauckas
ChrisRackauckas merged commit 52a3cf5 into SciML:master Sep 17, 2026
106 of 110 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 17, 2026
Ships #5155: the new public `steady_state_sccprob` stub (with docstrings) that lets a SteadyStateProblem record the SCC lowering of its residual, plus the SciMLBase compat floor of 3.55. Minor rather than patch because it adds public API that ModelingToolkit 11.44.0 extends.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude <[email protected]>
Agent-Harness: Claude Code 2.1.273
Agent-Model: claude-opus-5[1m]
Agent-Session: 6a01e420-3436-4518-83cc-6cd853283cfb (local transcript; this harness publishes no conversation URL)
ChrisRackauckas added a commit that referenced this pull request Sep 17, 2026
Ships #5155: the new public `steady_state_sccprob` stub (with docstrings) that lets a SteadyStateProblem record the SCC lowering of its residual, plus the SciMLBase compat floor of 3.55. Minor rather than patch because it adds public API that ModelingToolkit 11.44.0 extends.



Agent-Harness: Claude Code 2.1.273
Agent-Model: claude-opus-5[1m]
Agent-Session: 6a01e420-3436-4518-83cc-6cd853283cfb (local transcript; this harness publishes no conversation URL)

Co-authored-by: Claude <[email protected]>
ChrisRackauckas added a commit that referenced this pull request Sep 17, 2026
#5155 defines MTKBase.steady_state_sccprob, which is new public API in
ModelingToolkitBase 1.74.0. The floor was still 1.70, so a resolve picking an
older ModelingToolkitBase would fail to load.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude <[email protected]>
Agent-Harness: Claude Code 2.1.273
Agent-Model: claude-opus-5[1m]
Agent-Session: 6a01e420-3436-4518-83cc-6cd853283cfb (local transcript; this harness publishes no conversation URL)
ChrisRackauckas added a commit that referenced this pull request Sep 17, 2026
#5155 defines MTKBase.steady_state_sccprob, which is new public API in
ModelingToolkitBase 1.74.0. The floor was still 1.70, so a resolve picking an
older ModelingToolkitBase would fail to load.



Agent-Harness: Claude Code 2.1.273
Agent-Model: claude-opus-5[1m]
Agent-Session: 6a01e420-3436-4518-83cc-6cd853283cfb (local transcript; this harness publishes no conversation URL)

Co-authored-by: Claude <[email protected]>
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/SteadyStateDiffEq.jl that referenced this pull request Sep 17, 2026
MTK 11.44 ships the lowered_problem storage (SciML/ModelingToolkit.jl#5155),
so MTK-built SteadyStateProblems always carry the SCC builder and the tests
can assert the delegation unconditionally.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: daily-primrose (local Devin CLI session ID, no shareable URL; workspace /home/crackauc/sandbox/tmp_20260913_211211_19443)
ChrisRackauckas added a commit to SciML/SteadyStateDiffEq.jl that referenced this pull request Sep 17, 2026
* Forward SCCNonlinearProblem through SSRootfind to the SCC solver

An SCCNonlinearProblem has no top-level u0/kwargs fields, so the
generic AbstractNonlinearProblem solve preprocessing cannot handle it.
solve(prob::SCCNonlinearProblem, alg::SSRootfind) now bypasses that
path and forwards the problem directly to the wrapped algorithm, where
SCCNonlinearSolve.jl's dispatches solve it in SCC order while
preserving the linear/nonlinear block decomposition. The returned
solution wraps the inner solve as `original`, matching the
SteadyStateProblem path.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: daily-primrose (local Devin CLI session ID, no shareable URL; workspace /home/crackauc/sandbox/tmp_20260913_211211_19443)

* Integrate an SCCNonlinearProblem directly with DynamicSS

A second `solve` specialization:
`solve(prob::SCCNonlinearProblem, alg::DynamicSS)` bypasses the generic
nonlinear solve path and integrates the pseudo-transient system
`u' = g(u)`, where `g` is the concatenated residual of the SCC blocks
evaluated at the trial state. Upstream trial values reach each block's
parameter cache through `explicitfuns!`, exactly as in the SCC solve.
Linear blocks contribute `b - A*u` (ModelingToolkit's `calculate_A_b`
encodes `A*u - b = -expr`); homotopy blocks are evaluated at `λ = 1`.
The problem is deep-copied since `explicitfuns!` mutate the block
caches on every residual call, and the result is wrapped on the
original problem with the inner steady-state solve as `original`.

ModelingToolkit needs no integration change: its generated
SCCNonlinearProblems solve through this path, and MTK
SteadyStateProblems whose `initialization_data.initializeprob` is an
SCCNonlinearProblem already work through the ODE initialization
machinery. Both directions are covered by the new tests.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: daily-primrose (local Devin CLI session ID, no shareable URL; workspace /home/crackauc/sandbox/tmp_20260913_211211_19443)

* Solve SCCNonlinearProblem blocks sequentially under DynamicSS

Replace the monolithic-residual integration with the SCC solve protocol:
each block's parameter cache is updated from upstream solutions through
explicitfuns!, LinearProblem blocks are solved directly, and nonlinear
blocks are integrated to steady state by DynamicSS on the block residual.
Direct linear solves no longer require b - A*u to be attracting, and
convergence only needs each nonlinear block to be attracting under its
own pseudo-transient dynamics rather than a globally attracting
concatenated field. HomotopyProblem blocks evaluate the residual at the
lambda endpoint of lambda_span, which is the actual system.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: /home/crackauc/.local/share/devin/cli/summaries/history_f9264d4995564dac.md (local transcript; no shareable URL)

* Solve SteadyStateProblems through a stored SCCNonlinearProblem lowering

A SteadyStateProblem carrying lowered_problem now does an SCC-style solve:
DynamicSS delegates to the sequential block solve and SSRootfind's
NonlinearProblem(prob) conversion already returns the lowering. The inner
solution is expressed on the lowered problem since its block ordering need
not match the steady-state problem's u0. The alias/verbose specifiers
injected by the nonlinear solve pipeline are stripped when forwarding to an
SCCNonlinearProblem because LinearProblem block solves reject the nonlinear
specifier types.

Requires SciMLBase 3.55 for the lowered_problem field.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: daily-primrose (local Devin CLI session ID, no shareable URL; workspace /home/crackauc/sandbox/tmp_20260913_211211_19443)

* Raise the ModelingToolkit floor to 11.44 for the stored SCC lowering

MTK 11.44 ships the lowered_problem storage (SciML/ModelingToolkit.jl#5155),
so MTK-built SteadyStateProblems always carry the SCC builder and the tests
can assert the delegation unconditionally.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: daily-primrose (local Devin CLI session ID, no shareable URL; workspace /home/crackauc/sandbox/tmp_20260913_211211_19443)

---------

Co-authored-by: ChrisRackauckas-Claude <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Devin <[email protected]>
ChrisRackauckas added a commit that referenced this pull request Sep 18, 2026
…owering (#5163)

* Fix `solve(::SteadyStateProblem)` for SCC lowerings

#5155 stores a deferred `SCCNonlinearProblem` lowering on `SteadyStateProblem`,
which `SciMLBase.NonlinearProblem(prob)` materializes on every solve. Several
bugs made that path fail:

- `NonlinearSystem(sys)` called `bound_parameters` on complete systems whose
  `parameter_bindings_graph` was invalidated by `complete(; flatten = false)`,
  and merged child-system data through the recursive accessors while also
  keeping the converted subsystems, double-counting equations, unknowns and
  bindings (the duplicate `t => Inf` was the first failure).
- Initialization equations were copied untranslated into the time-independent
  residual, so bare unknowns were rejected; they are now wrapped in `Initial`,
  and derivatives (including `Initial(D(x))`) collapse to zero.
- Bound parameters were merged into the operating point, colliding with the
  lowered system's own `bindings`.
- A residual that `mtkcompile` reduces entirely to `observed` produced an
  empty SCC schedule; the lowering is now a stateless `NonlinearProblem`.
- `solve` re-dispatched `__solve` on the materialized `SCCNonlinearProblem`,
  whose generic fallbacks read `prob.u0` — a field it does not have. `solve`
  on `SteadyStateProblem` now routes SCC lowerings through `SCCAlg` and leaves
  every other problem/algorithm combination on the upstream path.

Fixes #5162

Generated with [Devin](https://devin.ai)

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.31
Agent-Model: SWE-2 Max
Agent-Session: local session, no shareable URL; transcript summary at /home/crackauc/.local/share/devin/cli/summaries/history_53525bdc70b74343.md

* Move variable bindings to initial conditions in `NonlinearSystem(sys)`

SteadyStateDiffEq 2.17's `__solve_scc_lowering` invokes the deferred
lowering on `DynamicSS` solves too, which exposed a latent crash: a
completed time-dependent system stores variable defaults like
`z(t) => z0` in `bindings`, and the `System` constructor rejects
variable bindings when `iv === nothing`, so `NonlinearSystem(sys)`
threw before ever building a problem. Mirror
`convert_bindings_for_time_independent_system` on the local `get_*`
fields — the recursive `bindings(sys)` would re-fold subsystem data
that this conversion already handles separately.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.31
Agent-Model: SWE-2 Max
Agent-Session: local session, no shareable URL; transcript summary at /home/crackauc/.local/share/devin/cli/summaries/history_d2dbf511181844c4.md

* Move `solve(::SteadyStateProblem)` SCC routing to SteadyStateDiffEq

Per review on #5163, the steady-state solve dispatch belongs in the
solver package rather than the problem producer. The interception now
lives in SteadyStateDiffEq (SciML/SteadyStateDiffEq.jl#169); MTK keeps
the lowering side (`NonlinearSystem` conversion, empty-SCC schedule,
bound-parameter guards). `test/scc_nonlinear_problem.jl` imports
SteadyStateDiffEq so the routing is loaded when solving these problems.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.31
Agent-Model: SWE-2 Max
Agent-Session: local session, no shareable URL; transcript summary at /home/crackauc/.local/share/devin/cli/summaries/history_d2dbf511181844c4.md

---------

Co-authored-by: ChrisRackauckas-Claude <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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