Skip to content

Preserve lb/ub when remaking Nonlinear(LeastSquares)Problem - #1372

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:claude/nonlinear-remake-bounds
Jun 5, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:claude/nonlinear-remake-bounds

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Note

Draft — please ignore until reviewed by @ChrisRackauckas.

Problem

remake(::NonlinearProblem) and remake(::NonlinearLeastSquaresProblem) reconstruct the problem without forwarding the lb/ub fields, so any bounds on the problem are silently dropped on every remake. Because problem construction in ModelingToolkit (and the trivial-initialization remake path generally) routes through remake, bounds set at construction never survive to the solver.

remake(::OptimizationProblem) already preserves lb/ub (and int, lcons, …); the nonlinear remake methods simply never got the same treatment.

Fix

Add lb/ub keyword arguments to both nonlinear remake methods, defaulting to the problem's current values and forwarding them to the constructor — exactly mirroring remake(::OptimizationProblem). Bounds can be overridden or cleared (lb = nothing).

Reproduction (before this PR)

using NonlinearSolve, SciMLBase
prob = NonlinearProblem((u,p)->u.^2 .- 4 .*u .+ 3, [1.5], nothing; lb=[0.0], ub=[2.0])
remake(prob).lb   # => nothing   (bounds dropped!)

Tests

Added a testset to test/remake_tests.jl covering preservation, override, and clearing of lb/ub for both NonlinearProblem and NonlinearLeastSquaresProblem. Verified locally against this branch.

Context

This is a prerequisite for SciML/ModelingToolkit.jl#4308 (forwarding bounds metadata to nonlinear problems). It also pairs with a NonlinearSolveBase fix so that bounded problems carrying initialization data solve correctly.

🤖 Generated with Claude Code

`remake(::NonlinearProblem)` and `remake(::NonlinearLeastSquaresProblem)`
reconstructed the problem without forwarding the `lb`/`ub` fields, so any bounds
set on the problem were silently dropped on every remake (including the
`remake` that runs trivial initialization at construction). This mirrors the
existing behavior of `remake(::OptimizationProblem)`: default `lb`/`ub` to the
problem's current values, and allow overriding (or clearing with `nothing`).

Co-Authored-By: Chris Rackauckas <[email protected]>
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review June 5, 2026 11:52
@ChrisRackauckas
ChrisRackauckas merged commit 19b86b8 into SciML:master Jun 5, 2026
29 of 60 checks passed
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/ModelingToolkit.jl that referenced this pull request Jun 5, 2026
The bounds forwarded to `NonlinearProblem`/`NonlinearLeastSquaresProblem` are
only retained through the `remake` that runs during problem construction as of
SciMLBase 3.18 (SciML/SciMLBase.jl#1372); on older versions they are silently
dropped. The solve-time correctness for bounded problems carrying initialization
data is provided by NonlinearSolveBase 2.30.3 (SciML/NonlinearSolve.jl#955),
which the test environment resolves to.

Co-Authored-By: Chris Rackauckas <[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