diff --git a/Project.toml b/Project.toml index cde18d3..a114796 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "NonconvexMultistart" uuid = "11b12826-7e46-4acf-9706-be0a67f2add7" authors = ["Mohamed Tarek and contributors"] -version = "0.1.1" +version = "0.1.2" [deps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" @@ -19,7 +19,7 @@ Hyperopt = "0.4" NonconvexCore = "1" Parameters = "0.12" Reexport = "1" -Setfield = "0.7" +Setfield = "0.7, 0.8, 1" Sobol = "1" julia = "1" diff --git a/src/hyperopt.jl b/src/hyperopt.jl index cf90b81..470d1f3 100644 --- a/src/hyperopt.jl +++ b/src/hyperopt.jl @@ -119,7 +119,7 @@ function optimize!(workspace::HyperoptWorkspace) objective = objective, params = params, candidates = candidates, ) - ho = @set _ho.objective = (args...) -> begin + ho = switch_objective(_ho, (args...) -> begin if length(args) == 2 && sampler isa Hyperopt.Hyperband if _sampler isa Hyperopt.GPSampler res, _ = _ho.objective(args[1], args[2]...) @@ -135,7 +135,7 @@ function optimize!(workspace::HyperoptWorkspace) else return res end - end + end) if _sampler isa Union{Hyperopt.LHSampler, Hyperopt.CLHSampler, Hyperopt.GPSampler} Hyperopt.init!(_sampler, ho) end @@ -156,6 +156,19 @@ function optimize!(workspace::HyperoptWorkspace) end end +function switch_objective(ho, objective) + (; iterations, params, candidates, history, results, sampler) = ho + return Hyperopt.Hyperoptimizer(; + iterations, + params, + candidates, + history, + results, + sampler, + objective, + ) +end + function get_linrange_candidates(lb, ub, n) return Tuple(Symbol.(:x0_, 1:length(lb))), Tuple(LinRange.(lb, ub, n)) end