-
-
Notifications
You must be signed in to change notification settings - Fork 46
Fix return codes for nonlinear least squares #606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fixes #459. The crux of the issue is that `f(x) = residual` only applies in the NonlinearProblem and SteadyStateProblem cases. When `f(x)` is a nonlinear least squares problem, finding a local minima is a solution, not a failure of the algorithm. Thus this reclassifies Stalled in NLLSQ to StalledSuccess, which makes it a successful return. Algorithms which require the NonlinearLeastSquares solution to have `||resid|| < tol` thus need to be careful with the return handling, as is done in the PR that introduces this return code SciML/SciMLBase.jl#1016. However, that's a fairly odd case because it's feasibility checking, while the normal use case for NLLSQ is for optimization, and in an optimization case there's no reason to believe you should always have a solution close to zero.
if SciMLBase.successful_retcode($(cache_syms[i]).retcode) && | ||
$(cache_syms[i]).retcode != ReturnCode.StalledSuccess |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
if SciMLBase.successful_retcode($(cache_syms[i]).retcode) && | |
$(cache_syms[i]).retcode != ReturnCode.StalledSuccess | |
if SciMLBase.successful_retcode($(cache_syms[i]).retcode) && | |
$(cache_syms[i]).retcode != ReturnCode.StalledSuccess |
@@ -146,6 +149,7 @@ end | |||
function (cache::NonlinearTerminationModeCache)( | |||
mode::AbstractSafeNonlinearTerminationMode, du, u, uprev, abstol, reltol, args... | |||
) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
f(u,p) = [1.0] | ||
nlf = NonlinearFunction(f; resid_prototype=zeros(1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
f(u,p) = [1.0] | |
nlf = NonlinearFunction(f; resid_prototype=zeros(1)) | |
f(u, p) = [1.0] | |
nlf = NonlinearFunction(f; resid_prototype = zeros(1)) |
sol = solve(prob) | ||
@test SciMLBase.successful_retcode(sol) | ||
@test sol.retcode == ReturnCode.StalledSuccess | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶
end | |
end |
Fixes #459. The crux of the issue is that
f(x) = residual
only applies in the NonlinearProblem and SteadyStateProblem cases. Whenf(x)
is a nonlinear least squares problem, finding a local minima is a solution, not a failure of the algorithm. Thus this reclassifies Stalled in NLLSQ to StalledSuccess, which makes it a successful return.Algorithms which require the NonlinearLeastSquares solution to have
||resid|| < tol
thus need to be careful with the return handling, as is done in the PR that introduces this return code SciML/SciMLBase.jl#1016. However, that's a fairly odd case because it's feasibility checking, while the normal use case for NLLSQ is for optimization, and in an optimization case there's no reason to believe you should always have a solution close to zero.