Skip to content

Commit 901a8b9

Browse files
Use common retcode deduction
1 parent 2a78d49 commit 901a8b9

File tree

2 files changed

+4
-27
lines changed

2 files changed

+4
-27
lines changed

lib/OptimizationNLopt/src/OptimizationNLopt.jl

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module OptimizationNLopt
33
using Reexport
44
@reexport using NLopt, Optimization
55
using Optimization.SciMLBase
6+
using Optimization: deduce_retcode
67

78
(f::NLopt.Algorithm)() = f
89

@@ -125,31 +126,6 @@ function __map_optimizer_args!(cache::OptimizationCache, opt::NLopt.Opt;
125126
return nothing
126127
end
127128

128-
function __nlopt_status_to_ReturnCode(status::Symbol)
129-
if status in Symbol.([
130-
NLopt.SUCCESS,
131-
NLopt.STOPVAL_REACHED,
132-
NLopt.FTOL_REACHED,
133-
NLopt.XTOL_REACHED,
134-
NLopt.ROUNDOFF_LIMITED
135-
])
136-
return ReturnCode.Success
137-
elseif status == Symbol(NLopt.MAXEVAL_REACHED)
138-
return ReturnCode.MaxIters
139-
elseif status == Symbol(NLopt.MAXTIME_REACHED)
140-
return ReturnCode.MaxTime
141-
elseif status in Symbol.([
142-
NLopt.OUT_OF_MEMORY,
143-
NLopt.INVALID_ARGS,
144-
NLopt.FAILURE,
145-
NLopt.FORCED_STOP
146-
])
147-
return ReturnCode.Failure
148-
else
149-
return ReturnCode.Default
150-
end
151-
end
152-
153129
function SciMLBase.__solve(cache::OptimizationCache{
154130
F,
155131
RC,
@@ -258,7 +234,7 @@ function SciMLBase.__solve(cache::OptimizationCache{
258234
t0 = time()
259235
(minf, minx, ret) = NLopt.optimize(opt_setup, cache.u0)
260236
t1 = time()
261-
retcode = __nlopt_status_to_ReturnCode(ret)
237+
retcode = deduce_retcode(ret)
262238

263239
if retcode == ReturnCode.Failure
264240
@warn "NLopt failed to converge: $(ret)"

src/utils.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ const STOP_REASON_MAP = Dict(
9494
r"STOP: XTOL.TOO.SMALL" => ReturnCode.ConvergenceFailure,
9595
r"STOP: TERMINATION" => ReturnCode.Terminated,
9696
r"Optimization completed" => ReturnCode.Success,
97-
r"Convergence achieved" => ReturnCode.Success
97+
r"Convergence achieved" => ReturnCode.Success,
98+
r"ROUNDOFF_LIMITED" => ReturnCode.Success
9899
)
99100

100101
# Function to deduce ReturnCode from a stop_reason string using the dictionary

0 commit comments

Comments
 (0)