Skip to content

Commit 80e6ea5

Browse files
Merge pull request #1016 from SciML/stalledsuccess
Add StalledSuccess and improve return code documentation
2 parents 1d5b5af + 08ddb81 commit 80e6ea5

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SciMLBase"
22
uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
33
authors = ["Chris Rackauckas <accounts@chrisrackauckas.com> and contributors"]
4-
version = "2.88.0"
4+
version = "2.89.0"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

docs/src/interfaces/Solutions.md

+7
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,21 @@ SciMLBase.ReturnCode.Terminated
8282
SciMLBase.ReturnCode.DtNaN
8383
SciMLBase.ReturnCode.MaxIters
8484
SciMLBase.ReturnCode.MaxNumSub
85+
SciMLBase.ReturnCode.MaxTime
8586
SciMLBase.ReturnCode.DtLessThanMin
8687
SciMLBase.ReturnCode.Unstable
8788
SciMLBase.ReturnCode.InitialFailure
8889
SciMLBase.ReturnCode.ConvergenceFailure
8990
SciMLBase.ReturnCode.Failure
91+
SciMLBase.ReturnCode.Infeasible
9092
SciMLBase.ReturnCode.ExactSolutionLeft
9193
SciMLBase.ReturnCode.ExactSolutionRight
9294
SciMLBase.ReturnCode.FloatingPointLimit
95+
SciMLBase.ReturnCode.InternalLineSearchFailed
96+
SciMLBase.ReturnCode.InternalLinearSolveFailed
97+
SciMLBase.ReturnCode.ShrinkThresholdExceeded
98+
SciMLBase.ReturnCode.Stalled
99+
SciMLBase.ReturnCode.SuccessfulStall
93100
```
94101

95102
## Solution Traits

src/initialization.jl

+11-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,17 @@ function get_initial_values(prob, valp, f, alg::OverrideInit,
282282
throw(OverrideInitNoTolerance(:reltol))
283283
end
284284
nlsol = solve(initprob, nlsolve_alg; abstol = _abstol, reltol = _reltol, kwargs...)
285-
success = SciMLBase.successful_retcode(nlsol)
285+
286+
success = if initprob isa NonlinearLeastSquaresProblem
287+
# Do not accept StalledSuccess as a solution
288+
# A good local minima is not a success
289+
resid = nlsol.resid
290+
normresid = isdefined(integrator.opts, :internalnorm) ?
291+
integrator.opts.internalnorm(resid, t) : norm(resid)
292+
SciMLBase.successful_retcode(nlsol) && normresid <= abstol
293+
else
294+
SciMLBase.successful_retcode(nlsol)
295+
end
286296
end
287297

288298
if initdata.initializeprobmap !== nothing

src/retcodes.jl

+25-3
Original file line numberDiff line numberDiff line change
@@ -392,15 +392,36 @@ EnumX.@enumx ReturnCode begin
392392
ReturnCode.Stalled
393393
394394
The solution has stalled. This is only returned by algorithms for which stalling is a
395-
failure mode. Certain solvers like Nonlinear Least Squares solvers are considered
396-
successful if the solution has stalled, in those cases `ReturnCode.Success` is returned.
395+
failure mode, such as on a NonlinearProblem where the found solution is larger than
396+
the accepted tolerance.
397397
398398
## Properties
399399
400400
- `successful_retcode` = `false`
401401
"""
402402
Stalled
403403

404+
"""
405+
ReturnCode.StalledSuccess
406+
407+
The solution process has stalled, but the stall is not considered a failure of the solver.
408+
For example, a nonlinear optimizer may have stalled, that is its steps went to zero, which
409+
is a valid local minima.
410+
411+
## Common Reasons for Seeing this Return Code
412+
413+
- For nonlinear least squares optimizations, this is given for local minima which exceed
414+
the chosen tolerance, i.e. `f(x)=resid` where `||resid||>tol` so it's not considered
415+
ReturnCode.Success but it is still considered a sucessful return of the solver since
416+
it's a valid local minima (and there no minima which achieves the tolerance).
417+
418+
## Properties
419+
420+
- `successful_retcode` = `true`
421+
422+
"""
423+
StalledSuccess
424+
404425
"""
405426
ReturnCode.InternalLinearSolveFailed
406427
@@ -510,6 +531,7 @@ function successful_retcode(retcode::ReturnCode.T)
510531
retcode == ReturnCode.Success || retcode == ReturnCode.Terminated ||
511532
retcode == ReturnCode.ExactSolutionLeft ||
512533
retcode == ReturnCode.ExactSolutionRight ||
513-
retcode == ReturnCode.FloatingPointLimit
534+
retcode == ReturnCode.FloatingPointLimit ||
535+
retcode == ReturnCode.StalledSuccess
514536
end
515537
successful_retcode(sol::AbstractSciMLSolution) = successful_retcode(sol.retcode)

0 commit comments

Comments
 (0)