Repository navigation
Preserve lb/ub when remaking Nonlinear(LeastSquares)Problem - #1372
Merged
ChrisRackauckas merged 1 commit intoJun 5, 2026
Merged
ChrisRackauckas merged 1 commit into
ChrisRackauckas merged 1 commit into
Conversation
`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
marked this pull request as ready for review
June 5, 2026 11:52
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Draft — please ignore until reviewed by @ChrisRackauckas.
Problem
remake(::NonlinearProblem)andremake(::NonlinearLeastSquaresProblem)reconstruct the problem without forwarding thelb/ubfields, so any bounds on the problem are silently dropped on everyremake. Because problem construction in ModelingToolkit (and the trivial-initializationremakepath generally) routes throughremake, bounds set at construction never survive to the solver.remake(::OptimizationProblem)already preserveslb/ub(andint,lcons, …); the nonlinearremakemethods simply never got the same treatment.Fix
Add
lb/ubkeyword arguments to both nonlinearremakemethods, defaulting to the problem's current values and forwarding them to the constructor — exactly mirroringremake(::OptimizationProblem). Bounds can be overridden or cleared (lb = nothing).Reproduction (before this PR)
Tests
Added a testset to
test/remake_tests.jlcovering preservation, override, and clearing oflb/ubfor bothNonlinearProblemandNonlinearLeastSquaresProblem. Verified locally against this branch.Context
This is a prerequisite for SciML/ModelingToolkit.jl#4308 (forwarding
boundsmetadata to nonlinear problems). It also pairs with a NonlinearSolveBase fix so that bounded problems carrying initialization data solve correctly.🤖 Generated with Claude Code