@@ -13,13 +13,22 @@ SciMLBase.allowscallback(::SpeedMappingOpt) = false
1313SciMLBase. has_init (opt:: SpeedMappingOpt ) = true
1414SciMLBase. requiresgradient (opt:: SpeedMappingOpt ) = true
1515
16+ function _retcode (opt_res)
17+ status = opt_res. status
18+ status === :first_order && return SciMLBase. ReturnCode. Success
19+ status === :max_time && return SciMLBase. ReturnCode. MaxTime
20+ status in (:max_iter , :max_eval ) && return SciMLBase. ReturnCode. MaxIters
21+ return SciMLBase. ReturnCode. Failure
22+ end
23+
1624function __map_optimizer_args (
17- cache:: OptimizationBase.OptimizationCache , opt:: SpeedMappingOpt ;
25+ cache:: OptimizationBase.OptimizationCache ,
26+ opt:: SpeedMappingOpt ;
1827 callback = nothing ,
1928 maxiters:: Union{Number, Nothing} = nothing ,
2029 maxtime:: Union{Number, Nothing} = nothing ,
2130 abstol:: Union{Number, Nothing} = nothing ,
22- reltol:: Union{Number, Nothing} = nothing
31+ reltol:: Union{Number, Nothing} = nothing ,
2332 )
2433
2534 # add optimiser options from kwargs
@@ -37,14 +46,16 @@ function __map_optimizer_args(
3746 if ! isnothing (abstol)
3847 @SciMLMessage (
3948 lazy " common abstol is currently not used by $(opt)" ,
40- cache. verbose, :unsupported_kwargs
49+ cache. verbose,
50+ :unsupported_kwargs
4151 )
4252 end
4353
4454 if ! isnothing (reltol)
4555 @SciMLMessage (
4656 lazy " common reltol is currently not used by $(opt)" ,
47- cache. verbose, :unsupported_kwargs
57+ cache. verbose,
58+ :unsupported_kwargs
4859 )
4960 end
5061
@@ -66,26 +77,35 @@ function SciMLBase.__solve(cache::OptimizationCache{O}) where {O <: SpeedMapping
6677 maxiters = OptimizationBase. _check_and_convert_maxiters (cache. solver_args. maxiters)
6778 maxtime = OptimizationBase. _check_and_convert_maxtime (cache. solver_args. maxtime)
6879 opt_args = __map_optimizer_args (
69- cache, cache. opt, maxiters = maxiters,
80+ cache,
81+ cache. opt,
82+ maxiters = maxiters,
7083 maxtime = maxtime,
7184 abstol = cache. solver_args. abstol,
72- reltol = cache. solver_args. reltol; cache. solver_args...
85+ reltol = cache. solver_args. reltol;
86+ cache. solver_args... ,
7387 )
7488
7589 t0 = time ()
7690 opt_res = SpeedMapping. speedmapping (
77- cache. u0; f = _loss, (g!) = cache. f. grad,
91+ cache. u0;
92+ f = _loss,
93+ (g!) = cache. f. grad,
7894 lower = cache. lb,
79- upper = cache. ub, opt_args...
95+ upper = cache. ub,
96+ opt_args... ,
8097 )
8198 t1 = time ()
82- opt_ret = opt_res. converged ? SciMLBase. ReturnCode. Success :
83- SciMLBase. ReturnCode. Failure
99+ opt_ret = _retcode (opt_res)
84100 stats = OptimizationBase. OptimizationStats (; time = t1 - t0)
85101 return SciMLBase. build_solution (
86- cache, cache. opt,
87- opt_res. minimizer, _loss (opt_res. minimizer);
88- original = opt_res, retcode = opt_ret, stats = stats
102+ cache,
103+ cache. opt,
104+ opt_res. minimizer,
105+ _loss (opt_res. minimizer);
106+ original = opt_res,
107+ retcode = opt_ret,
108+ stats = stats,
89109 )
90110end
91111
0 commit comments