Skip to content

Commit

Permalink
Merge pull request #82 from CyberAgent/feature-separable-cma
Browse files Browse the repository at this point in the history
Separable CMA-ES
  • Loading branch information
c-bata committed Oct 20, 2020
2 parents e7bb67a + 63390c7 commit f542c55
Show file tree
Hide file tree
Showing 5 changed files with 411 additions and 3 deletions.
26 changes: 25 additions & 1 deletion benchmark/optuna_solver.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import argparse
import optuna

from cmaes import SepCMA
from kurobako import solver
from kurobako.solver.optuna import OptunaSolverFactory

parser = argparse.ArgumentParser()
parser.add_argument("sampler", choices=["cmaes", "ipop-cmaes", "pycma"])
parser.add_argument(
"sampler", choices=["cmaes", "sep-cmaes", "ipop-cmaes", "ipop-sep-cmaes", "pycma"]
)
parser.add_argument(
"--loglevel", choices=["debug", "info", "warning", "error"], default="warning"
)
Expand All @@ -26,6 +29,12 @@ def create_cmaes_study(seed):
return optuna.create_study(sampler=sampler)


def create_sep_cmaes_study(seed):
optuna.samplers._cmaes.CMA = SepCMA # monkey patch
sampler = optuna.samplers.CmaEsSampler(seed=seed, warn_independent_sampling=True)
return optuna.create_study(sampler=sampler)


def create_ipop_cmaes_study(seed):
sampler = optuna.samplers.CmaEsSampler(
seed=seed,
Expand All @@ -36,6 +45,17 @@ def create_ipop_cmaes_study(seed):
return optuna.create_study(sampler=sampler)


def create_ipop_sep_cmaes_study(seed):
optuna.samplers._cmaes.CMA = SepCMA # monkey patch
sampler = optuna.samplers.CmaEsSampler(
seed=seed,
warn_independent_sampling=True,
restart_strategy="ipop",
inc_popsize=2,
)
return optuna.create_study(sampler=sampler)


def create_pycma_study(seed):
sampler = optuna.integration.PyCmaSampler(
seed=seed,
Expand All @@ -47,8 +67,12 @@ def create_pycma_study(seed):
if __name__ == "__main__":
if args.sampler == "cmaes":
factory = OptunaSolverFactory(create_cmaes_study)
elif args.sampler == "sep-cmaes":
factory = OptunaSolverFactory(create_sep_cmaes_study)
elif args.sampler == "ipop-cmaes":
factory = OptunaSolverFactory(create_ipop_cmaes_study)
elif args.sampler == "ipop-sep-cmaes":
factory = OptunaSolverFactory(create_ipop_sep_cmaes_study)
elif args.sampler == "pycma":
factory = OptunaSolverFactory(create_pycma_study)
else:
Expand Down
6 changes: 4 additions & 2 deletions benchmark/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,20 @@ esac

RANDOM_SOLVER=$($KUROBAKO solver random)
CMAES_SOLVER=$($KUROBAKO solver --name 'cmaes' command python $DIR/optuna_solver.py cmaes)
SEP_CMAES_SOLVER=$($KUROBAKO solver --name 'sep-cmaes' command python $DIR/optuna_solver.py sep-cmaes)
IPOP_CMAES_SOLVER=$($KUROBAKO solver --name 'ipop-cmaes' command python $DIR/optuna_solver.py ipop-cmaes)
IPOP_SEP_CMAES_SOLVER=$($KUROBAKO solver --name 'ipop-sep-cmaes' command python $DIR/optuna_solver.py ipop-sep-cmaes)
PYCMA_SOLVER=$($KUROBAKO solver --name 'pycma' command python $DIR/optuna_solver.py pycma)

if [ $BUDGET -le 500 ]; then
$KUROBAKO studies \
--solvers $RANDOM_SOLVER $IPOP_CMAES_SOLVER $PYCMA_SOLVER $CMAES_SOLVER \
--solvers $RANDOM_SOLVER $PYCMA_SOLVER $CMAES_SOLVER $SEP_CMAES_SOLVER \
--problems $PROBLEM \
--seed $SEED --repeats $REPEATS --budget $BUDGET \
| $KUROBAKO run --parallelism 4 > $2
else
$KUROBAKO studies \
--solvers $RANDOM_SOLVER $IPOP_CMAES_SOLVER $CMAES_SOLVER \
--solvers $RANDOM_SOLVER $CMAES_SOLVER $IPOP_SEP_CMAES_SOLVER $IPOP_CMAES_SOLVER $SEP_CMAES_SOLVER \
--problems $PROBLEM \
--seed $SEED --repeats $REPEATS --budget $BUDGET \
| $KUROBAKO run --parallelism 6 > $2
Expand Down
1 change: 1 addition & 0 deletions cmaes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ._cma import CMA # NOQA
from ._sepcma import SepCMA # NOQA

__version__ = "0.6.1"
Loading

0 comments on commit f542c55

Please sign in to comment.