Skip to content

Add a lowered_problem slot to SteadyStateProblem - #1603

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:steady-state-lowered-problem
Sep 14, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:steady-state-lowered-problem

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

Summary

Symbolic frontends (ModelingToolkit) can construct a SteadyStateProblem whose intended non-transient form is a lowered problem — e.g. an SCC-decomposed SCCNonlinearProblem — rather than the ODE residual wrapped as a NonlinearProblem. SteadyStateProblem had nowhere to record that lowering, so MTK stored it in System metadata (SciML/ModelingToolkit.jl#5155), which captures the construction-time operating point: after remake(prob; u0, p), SCCNonlinearProblem(prob) still returned the lowering built from the original op.

This adds a lowered_problem field to SteadyStateProblem (default nothing), following the problem_type slot precedent from #1600:

  • Holds an AbstractSciMLProblem (used verbatim — an SCCNonlinearProblem, NonlinearProblem, HomotopyProblem, or even a LinearProblem when the residual is a single linear SCC) or a callable prob -> problem evaluated on the current problem — so frontends can defer an expensive lowering until first use while still reflecting remaked u0/p values. A callable is what MTK stores; carrying it through remake is inherently correct since it is not bound to particular values.
  • The stored-vs-callable check keys on Base.Callable, not a problem abstract type, so any AbstractSciMLProblem is returned verbatim.
  • remake carries the field and accepts lowered_problem as an override.
  • NonlinearProblem(::SteadyStateProblem) prefers the stored lowering over wrapping f. This is the conversion NonlinearSolveBase.solve_call(::SteadyStateProblem, ::AbstractNonlinearAlgorithm) and SteadyStateDiffEq's SSRootfind both go through, so non-dynamic steady-state solves pick up an SCC lowering (and its sequential/direct-block solve path) automatically.

Downstream companions: SciML/ModelingToolkit.jl#5155 moves its deferred SCCNonlinearProblem builder from sys metadata into this field (fixing the stale-op bug), and SciML/SteadyStateDiffEq.jl#166 adds the matching DynamicSS/SCCNonlinearProblem dispatch that sequentially solves SCC blocks.

Test plan

  • SteadyStateProblem lowered_problem testset (17 tests): default nothing + f-wrap fallback, verbatim stored NonlinearProblem and LinearProblem, callable materialized against current problem, remake carry/override/clear — test/problem_building_test.jl
  • remake_tests.jl: all 88-per-container SteadyStateProblem cases pass (field rides through constructorof/setproperties/@reset)
  • Discrimination: on 3.54.0, lowered_problem leaks into prob.kwargs and prob.lowered_problem throws FieldError; NonlinearProblem(prob) ignores it
  • Runic clean on all touched files
  • Full GROUP=Core and GROUP=QA left to CI (no new imports/exports/extensions; QA env is heavy locally)

Generated with Devin (harness: Devin CLI 3000.10.21, model: SWE-2 Max, session transcript: /home/crackauc/.local/share/devin/cli/summaries/history_f9264d4995564dac.md — local file, no shareable URL for this harness).

ChrisRackauckas and others added 2 commits September 14, 2026 07:29
Symbolic frontends can construct a SteadyStateProblem whose intended
non-transient form is a lowered problem (e.g. an SCC-decomposed
SCCNonlinearProblem) rather than the ODE residual wrapped as a
NonlinearProblem. SteadyStateProblem had nowhere to record that lowering,
so ModelingToolkit stored it in system metadata — which survives remake
structurally but captures the construction-time operating point, so
remake(prob; u0, p) returned a lowering built from stale values.

Add a `lowered_problem` field (default `nothing`) following the
`problem_type` slot added to OptimizationProblem in SciML#1600: it holds either
an AbstractNonlinearProblem (used verbatim) or a callable
`prob -> problem` that is evaluated on the current problem, letting
frontends defer the lowering while still seeing remade u0/p. `remake`
carries and can override the field, and `NonlinearProblem(::SteadyStateProblem)`
prefers the stored lowering over wrapping `f`, so non-dynamic steady-state
solves (NonlinearSolveBase's solve_call, SteadyStateDiffEq's SSRootfind)
pick it up automatically.

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; workspace /home/crackauc/sandbox/tmp_20260913_211211_19443)
The callable-vs-stored check now keys on Base.Callable rather than
AbstractNonlinearProblem: a system whose steady-state residual lowers to a
single linear SCC stores a LinearProblem, which is an AbstractLinearProblem
and would otherwise have been invoked as a callable.

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)
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/ModelingToolkit.jl that referenced this pull request Sep 14, 2026
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)
@ChrisRackauckas
ChrisRackauckas merged commit c13c04c into SciML:master Sep 14, 2026
68 of 72 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 14, 2026
- Add a lowered_problem slot to SteadyStateProblem (#1603)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas added a commit to SciML/ModelingToolkit.jl that referenced this pull request Sep 17, 2026
* Record the SCC lowering of a SteadyStateProblem on its system

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)

* Store the SCC lowering in SteadyStateProblem.lowered_problem

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)

* Bump SciMLBase lower bound to 3.55 for SteadyStateProblem.lowered_problem

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)

---------

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 to SciML/DiffEqDocs.jl that referenced this pull request Sep 22, 2026
)

SciML/SciMLBase.jl#1603 (c13c04c7ce, "Add a lowered_problem slot to
SteadyStateProblem") added a `lowered_problem` field whose docstring text
contains `[`NonlinearProblem`](@ref)`. The `SteadyStateProblem` docstring is
rendered on docs/src/types/steady_state_types.md, but `SciMLBase.NonlinearProblem`
was not included anywhere in this manual, so Documenter's cross-reference check
failed:

    Error: Cannot resolve @ref for md"[`NonlinearProblem`](@ref)" in docs/src/types/steady_state_types.md.
    - No docstring found in doc for binding `SciMLBase.NonlinearProblem`.
    ERROR: LoadError: `makedocs` encountered an error [:cross_references] -- terminating build before rendering.

Document the binding on the same page so the existing cross-reference resolves.
The green-to-red bracket is SciMLBase v3.53.3 (green run 34702898469) to
v3.55.0 (red run 35146255120); the only DiffEqDocs change in between was the
unrelated CSV compat bump.


Agent-Harness: OpenCode
Agent-Model: muse-spark-1.3-contributor-free
Agent-Session: local session at /home/crackauc/sandbox/tmp_20260917_040834_91074 (no public conversation URL)

Co-authored-by: ChrisRackauckas-Claude <[email protected]>
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/SciMLBase.jl that referenced this pull request Oct 7, 2026
…sion.

After SciML#1603, MTK-lowered SteadyStateProblems surface SCCNonlinearProblem through
NonlinearProblem(::SteadyStateProblem); callers that touch .u0 then FieldError.
Forward .u0 to state_values and raise ArgumentError on NonlinearProblem(::SCC).

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/jobs/master-SciMLBase-scc-u0/log.txt on amdci2
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/SciMLBase.jl that referenced this pull request Oct 20, 2026
…sion.

After SciML#1603, MTK-lowered SteadyStateProblems surface SCCNonlinearProblem through
NonlinearProblem(::SteadyStateProblem); callers that touch .u0 then FieldError.
Forward .u0 to state_values and raise ArgumentError on NonlinearProblem(::SCC).

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe
Agent-Model: cursor-grok-4.5-high
Agent-Session: local session b2e00361-e7ad-4cb5-a134-76b6ed75a02f (no session URL)
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