Skip to content

Commit 02ee3bd

Browse files
Fix docs dependency resolution
1 parent 915838c commit 02ee3bd

4 files changed

Lines changed: 60 additions & 16 deletions

File tree

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ IterTools = "1"
159159
Juniper = "0.9"
160160
Lux = "1"
161161
MLUtils = "0.4.4"
162-
Manifolds = "0.10"
162+
Manifolds = "0.10, 0.11"
163163
Manopt = "0.5"
164164
ModelingToolkit = "10.23, 11"
165165
NLPModels = "0.21, 0.22"

lib/OptimizationSpeedMapping/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Pkg = "1"
2121
Reexport = "1.2"
2222
SafeTestsets = "0.1"
2323
SciMLBase = "2.122.1, 3"
24-
SpeedMapping = "0.3"
24+
SpeedMapping = "0.3, 0.4"
2525
Test = "1.10"
2626
julia = "1.10"
2727

lib/OptimizationSpeedMapping/src/OptimizationSpeedMapping.jl

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,27 @@ SciMLBase.allowscallback(::SpeedMappingOpt) = false
1313
SciMLBase.has_init(opt::SpeedMappingOpt) = true
1414
SciMLBase.requiresgradient(opt::SpeedMappingOpt) = true
1515

16+
function _retcode(opt_res)
17+
if hasproperty(opt_res, :converged)
18+
return opt_res.converged ? SciMLBase.ReturnCode.Success :
19+
SciMLBase.ReturnCode.Failure
20+
end
21+
22+
status = hasproperty(opt_res, :status) ? opt_res.status : nothing
23+
status === :first_order && return SciMLBase.ReturnCode.Success
24+
status === :max_time && return SciMLBase.ReturnCode.MaxTime
25+
status in (:max_iter, :max_eval) && return SciMLBase.ReturnCode.MaxIters
26+
return SciMLBase.ReturnCode.Failure
27+
end
28+
1629
function __map_optimizer_args(
17-
cache::OptimizationBase.OptimizationCache, opt::SpeedMappingOpt;
30+
cache::OptimizationBase.OptimizationCache,
31+
opt::SpeedMappingOpt;
1832
callback = nothing,
1933
maxiters::Union{Number, Nothing} = nothing,
2034
maxtime::Union{Number, Nothing} = nothing,
2135
abstol::Union{Number, Nothing} = nothing,
22-
reltol::Union{Number, Nothing} = nothing
36+
reltol::Union{Number, Nothing} = nothing,
2337
)
2438

2539
# add optimiser options from kwargs
@@ -37,14 +51,16 @@ function __map_optimizer_args(
3751
if !isnothing(abstol)
3852
@SciMLMessage(
3953
lazy"common abstol is currently not used by $(opt)",
40-
cache.verbose, :unsupported_kwargs
54+
cache.verbose,
55+
:unsupported_kwargs
4156
)
4257
end
4358

4459
if !isnothing(reltol)
4560
@SciMLMessage(
4661
lazy"common reltol is currently not used by $(opt)",
47-
cache.verbose, :unsupported_kwargs
62+
cache.verbose,
63+
:unsupported_kwargs
4864
)
4965
end
5066

@@ -66,26 +82,35 @@ function SciMLBase.__solve(cache::OptimizationCache{O}) where {O <: SpeedMapping
6682
maxiters = OptimizationBase._check_and_convert_maxiters(cache.solver_args.maxiters)
6783
maxtime = OptimizationBase._check_and_convert_maxtime(cache.solver_args.maxtime)
6884
opt_args = __map_optimizer_args(
69-
cache, cache.opt, maxiters = maxiters,
85+
cache,
86+
cache.opt,
87+
maxiters = maxiters,
7088
maxtime = maxtime,
7189
abstol = cache.solver_args.abstol,
72-
reltol = cache.solver_args.reltol; cache.solver_args...
90+
reltol = cache.solver_args.reltol;
91+
cache.solver_args...,
7392
)
7493

7594
t0 = time()
7695
opt_res = SpeedMapping.speedmapping(
77-
cache.u0; f = _loss, (g!) = cache.f.grad,
96+
cache.u0;
97+
f = _loss,
98+
(g!) = cache.f.grad,
7899
lower = cache.lb,
79-
upper = cache.ub, opt_args...
100+
upper = cache.ub,
101+
opt_args...,
80102
)
81103
t1 = time()
82-
opt_ret = opt_res.converged ? SciMLBase.ReturnCode.Success :
83-
SciMLBase.ReturnCode.Failure
104+
opt_ret = _retcode(opt_res)
84105
stats = OptimizationBase.OptimizationStats(; time = t1 - t0)
85106
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
107+
cache,
108+
cache.opt,
109+
opt_res.minimizer,
110+
_loss(opt_res.minimizer);
111+
original = opt_res,
112+
retcode = opt_ret,
113+
stats = stats,
89114
)
90115
end
91116

lib/OptimizationSpeedMapping/test/core_tests.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using OptimizationSpeedMapping, OptimizationBase, ForwardDiff
1+
using OptimizationSpeedMapping, OptimizationBase, ForwardDiff, SciMLBase
22
using Test
33

44
@testset "OptimizationSpeedMapping.jl" begin
@@ -10,6 +10,8 @@ using Test
1010
prob = OptimizationProblem(f, x0, _p)
1111
sol = solve(prob, SpeedMappingOpt())
1212
@test 10 * sol.objective < l1
13+
@test SciMLBase.successful_retcode(sol)
14+
@test hasproperty(sol.original, :status) || hasproperty(sol.original, :converged)
1315

1416
prob = OptimizationProblem(f, x0, _p; lb = [-1.0, -1.0], ub = [1.5, 1.5])
1517
sol = solve(prob, SpeedMappingOpt())
@@ -38,4 +40,21 @@ using Test
3840
sol = OptimizationBase.solve!(cache)
3941
@test sol.u [2.0] atol = 1.0e-3
4042
end
43+
44+
@testset "return code mapping" begin
45+
@test OptimizationSpeedMapping._retcode((converged = true,)) ==
46+
SciMLBase.ReturnCode.Success
47+
@test OptimizationSpeedMapping._retcode((converged = false,)) ==
48+
SciMLBase.ReturnCode.Failure
49+
@test OptimizationSpeedMapping._retcode((status = :first_order,)) ==
50+
SciMLBase.ReturnCode.Success
51+
@test OptimizationSpeedMapping._retcode((status = :max_time,)) ==
52+
SciMLBase.ReturnCode.MaxTime
53+
@test OptimizationSpeedMapping._retcode((status = :max_iter,)) ==
54+
SciMLBase.ReturnCode.MaxIters
55+
@test OptimizationSpeedMapping._retcode((status = :max_eval,)) ==
56+
SciMLBase.ReturnCode.MaxIters
57+
@test OptimizationSpeedMapping._retcode((status = :failure,)) ==
58+
SciMLBase.ReturnCode.Failure
59+
end
4160
end

0 commit comments

Comments
 (0)