Skip to content

Commit 65e95ef

Browse files
Fix docs dependency resolution
1 parent 915838c commit 65e95ef

4 files changed

Lines changed: 51 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.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.4"
2525
Test = "1.10"
2626
julia = "1.10"
2727

lib/OptimizationSpeedMapping/src/OptimizationSpeedMapping.jl

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@ SciMLBase.allowscallback(::SpeedMappingOpt) = false
1313
SciMLBase.has_init(opt::SpeedMappingOpt) = true
1414
SciMLBase.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+
1624
function __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
)
90110
end
91111

lib/OptimizationSpeedMapping/test/core_tests.jl

Lines changed: 16 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)
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,17 @@ 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((status = :first_order,)) ==
46+
SciMLBase.ReturnCode.Success
47+
@test OptimizationSpeedMapping._retcode((status = :max_time,)) ==
48+
SciMLBase.ReturnCode.MaxTime
49+
@test OptimizationSpeedMapping._retcode((status = :max_iter,)) ==
50+
SciMLBase.ReturnCode.MaxIters
51+
@test OptimizationSpeedMapping._retcode((status = :max_eval,)) ==
52+
SciMLBase.ReturnCode.MaxIters
53+
@test OptimizationSpeedMapping._retcode((status = :failure,)) ==
54+
SciMLBase.ReturnCode.Failure
55+
end
4156
end

0 commit comments

Comments
 (0)