Skip to content

Add a problem_type slot to OptimizationProblem - #1600

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:optimizationproblem-problem-type
Sep 12, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:optimizationproblem-problem-type

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

Note: please ignore this PR until it has been reviewed by @ChrisRackauckas.

What changed and why

PDE discretizations that lower to an optimization problem (the NeuralPDE parser rewrite, SciML/NeuralPDE.jl#1161) need wrap_sol to turn the OptimizationSolution into a PDENoTimeSolution. wrap_sol decides that through problem_type(prob), and OptimizationProblem had no problem_type field, so it always returned nothing. This adds the field (keyword problem_type = nothing, so nothing changes for existing problems), documents it, and carries it through remake.

Companion PRs: OptimizationBase passes problem_type(prob) to wrap_sol (an OptimizationSolution has no prob field, so the one-argument wrap_sol(sol) cannot find it) at SciML/Optimization.jl#1354, and ModelingToolkitBase forwards ProblemTypeCtx metadata into the new slot at SciML/ModelingToolkit.jl#5115.

Minor version bump (3.53.3 → 3.54.0): new keyword and a new type parameter on OptimizationProblem.

Verification

New testset in test/pde_solutions.jl. Without the change the constructor rejects the keyword:

MethodError: no method matching OptimizationProblem{true}(::OptimizationFunction{…}, ::Vector{Float64}; problem_type::TestNoTimeMetadata)

With the change (GROUP=Core julia --project -e 'using Pkg; Pkg.test()' on Julia 1.11.9):

Test Summary: | Pass  Total  Time
pde           |   18     18  1.6s
...
exit=0

(The full Core group passed; the tail of the log only shows the last summaries.)

Not verified

Downstream groups and Julia 1.10/pre were not run locally.

🤖 Generated with Claude Code (model: claude-fable-5-1)

https://claude.ai/code/session_01WYPUXLxE9jVu2jXLFRd8ax

PDE discretizations that lower to an optimization problem (the NeuralPDE parser
rewrite, SciML/NeuralPDE.jl#1161) need `wrap_sol` to turn the `OptimizationSolution`
into a `PDENoTimeSolution`, which `wrap_sol` decides through `problem_type(prob)`.
`OptimizationProblem` had no `problem_type` field, so `problem_type` always returned
`nothing`. Add the field (default `nothing`, so nothing changes for existing
problems) and carry it through `remake`.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Agent-Harness: 2.1.269 (Claude Code)
Agent-Model: claude-fable-5-1
Agent-Session: https://claude.ai/code/session_01WYPUXLxE9jVu2jXLFRd8ax
Claude-Session: https://claude.ai/code/session_01WYPUXLxE9jVu2jXLFRd8ax
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 12, 2026 21:02
@ChrisRackauckas
ChrisRackauckas merged commit 573bc6c into SciML:master Sep 12, 2026
69 of 72 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 14, 2026
* Add a lowered_problem slot to SteadyStateProblem

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 #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)

* Treat any stored problem as materialized in NonlinearProblem(prob)

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)

---------

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]>
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