Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SciMLBase"
uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
authors = ["Chris Rackauckas <[email protected]> and contributors"]
version = "2.88.0"
version = "2.89.0"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
7 changes: 7 additions & 0 deletions docs/src/interfaces/Solutions.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,21 @@ SciMLBase.ReturnCode.Terminated
SciMLBase.ReturnCode.DtNaN
SciMLBase.ReturnCode.MaxIters
SciMLBase.ReturnCode.MaxNumSub
SciMLBase.ReturnCode.MaxTime
SciMLBase.ReturnCode.DtLessThanMin
SciMLBase.ReturnCode.Unstable
SciMLBase.ReturnCode.InitialFailure
SciMLBase.ReturnCode.ConvergenceFailure
SciMLBase.ReturnCode.Failure
SciMLBase.ReturnCode.Infeasible
SciMLBase.ReturnCode.ExactSolutionLeft
SciMLBase.ReturnCode.ExactSolutionRight
SciMLBase.ReturnCode.FloatingPointLimit
SciMLBase.ReturnCode.InternalLineSearchFailed
SciMLBase.ReturnCode.InternalLinearSolveFailed
SciMLBase.ReturnCode.ShrinkThresholdExceeded
SciMLBase.ReturnCode.Stalled
SciMLBase.ReturnCode.SuccessfulStall
```

## Solution Traits
Expand Down
12 changes: 11 additions & 1 deletion src/initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,17 @@ function get_initial_values(prob, valp, f, alg::OverrideInit,
throw(OverrideInitNoTolerance(:reltol))
end
nlsol = solve(initprob, nlsolve_alg; abstol = _abstol, reltol = _reltol, kwargs...)
success = SciMLBase.successful_retcode(nlsol)

success = if initprob isa NonlinearLeastSquaresProblem
# Do not accept StalledSuccess as a solution
# A good local minima is not a success
resid = nlsol.resid
normresid = isdefined(integrator.opts, :internalnorm) ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChrisRackauckas integrator is not defined here. This causes test errors in ModelingToolkit, e.g. https://github.com/SciML/ModelingToolkit.jl/actions/runs/14966367552/job/42037129153?pr=3624

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing. #1020 addresses this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ehh fuck. thanks for catching this

integrator.opts.internalnorm(resid, t) : norm(resid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
integrator.opts.internalnorm(resid, t) : norm(resid)
integrator.opts.internalnorm(resid, t) : norm(resid)

SciMLBase.successful_retcode(nlsol) && normresid <= abstol
else
SciMLBase.successful_retcode(nlsol)
end
end

if initdata.initializeprobmap !== nothing
Expand Down
28 changes: 25 additions & 3 deletions src/retcodes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,36 @@ EnumX.@enumx ReturnCode begin
ReturnCode.Stalled

The solution has stalled. This is only returned by algorithms for which stalling is a
failure mode. Certain solvers like Nonlinear Least Squares solvers are considered
successful if the solution has stalled, in those cases `ReturnCode.Success` is returned.
failure mode, such as on a NonlinearProblem where the found solution is larger than
the accepted tolerance.

## Properties

- `successful_retcode` = `false`
"""
Stalled

"""
ReturnCode.StalledSuccess
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
ReturnCode.StalledSuccess
ReturnCode.StalledSuccess


The solution process has stalled, but the stall is not considered a failure of the solver.
For example, a nonlinear optimizer may have stalled, that is its steps went to zero, which
is a valid local minima.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
is a valid local minima.
is a valid local minima.


## Common Reasons for Seeing this Return Code

- For nonlinear least squares optimizations, this is given for local minima which exceed
the chosen tolerance, i.e. `f(x)=resid` where `||resid||>tol` so it's not considered
Comment on lines +413 to +414
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
- For nonlinear least squares optimizations, this is given for local minima which exceed
the chosen tolerance, i.e. `f(x)=resid` where `||resid||>tol` so it's not considered
- For nonlinear least squares optimizations, this is given for local minima which exceed
the chosen tolerance, i.e. `f(x)=resid` where `||resid||>tol` so it's not considered

ReturnCode.Success but it is still considered a sucessful return of the solver since
it's a valid local minima (and there no minima which achieves the tolerance).

## Properties

- `successful_retcode` = `true`

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

"""
StalledSuccess

"""
ReturnCode.InternalLinearSolveFailed

Expand Down Expand Up @@ -510,6 +531,7 @@ function successful_retcode(retcode::ReturnCode.T)
retcode == ReturnCode.Success || retcode == ReturnCode.Terminated ||
retcode == ReturnCode.ExactSolutionLeft ||
retcode == ReturnCode.ExactSolutionRight ||
retcode == ReturnCode.FloatingPointLimit
retcode == ReturnCode.FloatingPointLimit ||
retcode == ReturnCode.StalledSuccess
end
successful_retcode(sol::AbstractSciMLSolution) = successful_retcode(sol.retcode)
Loading