Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/OptimizationCMAEvolutionStrategy/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OptimizationCMAEvolutionStrategy"
uuid = "bd407f91-200f-4536-9381-e4ba712f53f8"
authors = ["Vaibhav Dixit <vaibhavyashdixit@gmail.com> and contributors"]
version = "0.3.8"
version = "0.3.9"
[deps]
CMAEvolutionStrategy = "8d3b24bd-414e-49e0-94fb-163cc3a3e411"
OptimizationBase = "bca83a33-5cc9-4baa-983d-23429ab6bcbb"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ function __map_optimizer_args(
maxtime::Union{Number, Nothing} = nothing,
abstol::Union{Number, Nothing} = nothing,
reltol::Union{Number, Nothing} = nothing,
verbose::Bool = false
verbose::Bool = false,
# `sigma0` is the initial step size; it is the positional `s0` argument of
# `CMAEvolutionStrategy.minimize`, so it is handled in `__solve` and only
# captured here to keep it out of the forwarded `kwargs`.
sigma0 = nothing,
kwargs...
)
if !isnothing(reltol)
@SciMLMessage(
Expand All @@ -51,7 +56,9 @@ function __map_optimizer_args(
)
end

mapped_args = (; kwargs...)
mapped_args = (;
mapped_args...,
lower = prob.lb,
upper = prob.ub,
logger = CMAEvolutionStrategy.BasicLogger(
Expand Down Expand Up @@ -110,8 +117,10 @@ function SciMLBase.__solve(cache::OptimizationCache{O}) where {O <: CMAEvolution
maxtime = maxtime
)

sigma0 = get(cache.solver_args, :sigma0, 0.1)

t0 = time()
opt_res = CMAEvolutionStrategy.minimize(_loss, cache.u0, 0.1; opt_args...)
opt_res = CMAEvolutionStrategy.minimize(_loss, cache.u0, sigma0; opt_args...)
t1 = time()

opt_ret = _cma_retcode(opt_res.stop.reason)
Expand Down
15 changes: 15 additions & 0 deletions lib/OptimizationCMAEvolutionStrategy/test/core_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ using Test
sol_maxit = solve(prob, CMAEvolutionStrategyOpt(), maxiters = 2)
@test sol_maxit.retcode == SciMLBase.ReturnCode.MaxIters

@testset "solver kwargs are forwarded" begin
# `popsize` is a keyword of `CMAEvolutionStrategy.minimize`; `sigma0` is its
# positional `s0` (initial step size). Both should be reachable through solve.
sol_kw = solve(prob, CMAEvolutionStrategyOpt(); popsize = 20, maxiters = 10)
@test sol_kw.original.p.λ == 20

sol_default = solve(prob, CMAEvolutionStrategyOpt(); maxiters = 10)
@test sol_default.original.p.λ != 20

sol_sigma = solve(
prob, CMAEvolutionStrategyOpt(); sigma0 = 0.5, maxiters = 10
)
@test sol_sigma.retcode isa SciMLBase.ReturnCode.T
end

@testset "_cma_retcode symbol mapping" begin
_cma_retcode = OptimizationCMAEvolutionStrategy._cma_retcode
@test _cma_retcode(:ftarget) == SciMLBase.ReturnCode.Success
Expand Down
Loading