Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP/RFC: parallel population optimizer #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 0 deletions src/BlackBoxOptim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using Distributions, StatsBase, Compat

export Optimizer, AskTellOptimizer, SteppingOptimizer, PopulationOptimizer,
bboptimize, bbsetup, compare_optimizers,
ParallelPopulationOptimizer,

DiffEvoOpt, de_rand_1_bin, de_rand_1_bin_radiuslimited,
adaptive_de_rand_1_bin, adaptive_de_rand_1_bin_radiuslimited,
Expand Down Expand Up @@ -179,6 +180,7 @@ include("resampling_memetic_search.jl")
include("simultaneous_perturbation_stochastic_approximation.jl")
include("generating_set_search.jl")
include("direct_search_with_probabilistic_descent.jl")
include("parallel_population_optimizer.jl")

# Fitness
# include("fitness/fitness_types.jl") FIXME merge it with fitness.jl
Expand Down
17 changes: 17 additions & 0 deletions src/opt_controller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,20 @@ make_opt_results{O<:PopulationOptimizer}(ctrl::OptRunController{O}, oc::OptContr
num_func_evals(ctrl),
population(ctrl.optimizer)
)

# HACK return population results, although ParallelPopulationOptimizer is not
# populaton optimizer
make_opt_results{O<:ParallelPopulationOptimizer}(ctrl::OptRunController{O}, oc::OptController{O}) =
PopulationOptimizationResults{fitness_type(problem(ctrl)), Individual,
typeof(population(ctrl.optimizer))}(
string(oc.parameters[:Method]),
best_fitness(ctrl),
best_candidate(ctrl),
stop_reason(ctrl),
num_steps(ctrl),
start_time(ctrl),
elapsed_time(ctrl),
oc.parameters,
num_func_evals(ctrl),
population(ctrl.optimizer)
)
1 change: 1 addition & 0 deletions src/optimization_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const ValidMethods = @compat Dict{Symbol,Union(Any,Function)}(
:simultaneous_perturbation_stochastic_approximation => SimultaneousPerturbationSA2,
:generating_set_search => GeneratingSetSearcher,
:probabilistic_descent => direct_search_probabilistic_descent,
:parallel_population_optimizer => parallel_population_optimizer,
)

const MethodNames = sort!(collect(keys(ValidMethods)))
407 changes: 407 additions & 0 deletions src/parallel_population_optimizer.jl

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions test/helper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ using FactCheck
using Compat

NumTestRepetitions = 100

if nprocs() < 4
addprocs(4-nprocs()) # add procs for parallel population optimizer
end
@everywhere using BlackBoxOptim
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ my_tests = [
"test_differential_evolution.jl",
"test_adaptive_differential_evolution.jl",
"test_natural_evolution_strategies.jl",
"test_parallel_population_optimizer.jl",

"test_toplevel_bboptimize.jl",
"test_smoketest_bboptimize.jl",
Expand Down
45 changes: 45 additions & 0 deletions test/test_parallel_population_optimizer.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
facts("Parallel population optimizer") do

@everywhere using BlackBoxOptim

context("optimizing small problem") do
rosenbrock2d(x) = (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2

res = bboptimize(rosenbrock2d; Method = :parallel_population_optimizer,
SearchSpace = [(-5.0, 5.0), (-2.0, 2.0)], MaxTime = 100.0,
ShowTrace = true, MigrationSize = 2, MigrationPeriod = 100)
@fact size(best_candidate(res)) => (2,)
@fact typeof(best_fitness(res)) => Float64
@fact best_fitness(res) => less_than(100.0)
pop = population(res)
@fact numdims(pop) --> 2
@fact popsize(pop) > 0 --> true
end

context("propagating exceptions from workers to the master") do
# 0.01 chance to get domain error
bogus(x) = sqrt(x[1]-0.01)
# 0.01 chance to raise exception prematurely during bbsetup()
res = bbsetup(bogus; Method = :parallel_population_optimizer,
SearchSpace = [(0.0, 1.0)], MaxTime = 100.0,
ShowTrace = true, MigrationSize = 2, MigrationPeriod = 100)
@fact_throws RemoteException bboptimize(res)
end

#= doesn't work with PopulationMatrix
context("worker method that uses PopulationMatrix") do
rosenbrock2d(x) = (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2

res = bboptimize(rosenbrock2d; Method = :parallel_population_optimizer,
WorkerMethod = :separable_nes,
SearchSpace = [(-5.0, 5.0), (-2.0, 2.0)], MaxTime = 100.0,
ShowTrace = true, MigrationSize = 2, MigrationPeriod = 100)
@fact size(best_candidate(res)) => (2,)
@fact typeof(best_fitness(res)) => Float64
@fact best_fitness(res) => less_than(100.0)
pop = population(res)
@fact numdims(pop) --> 2
@fact popsize(pop) > 0 --> true
end
=#
end
8 changes: 4 additions & 4 deletions test/test_smoketest_bboptimize.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function rosenbrock2d(x)
return (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2
end

facts("bboptimize smoketest") do
function rosenbrock2d(x)
return (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2
end

for(m in keys(BlackBoxOptim.ValidMethods))
context("testing $(m) method to ensure it works") do
res = bboptimize(rosenbrock2d; Method = m,
Expand Down