Skip to content

Commit

Permalink
Rename chocolate algorithm names for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
c-bata committed Apr 26, 2020
1 parent 116f9f0 commit ef82a9d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions pkg/suggestion/v1alpha3/chocolate/base_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import chocolate as choco
import logging
import base64
import warnings

from pkg.suggestion.v1alpha3.internal.constant import MAX_GOAL, INTEGER, DOUBLE, CATEGORICAL, DISCRETE
from pkg.suggestion.v1alpha3.internal.trial import Assignment
Expand All @@ -12,6 +13,13 @@
DB_FIELD_CHOCOLATE_ID = "_chocolate_id"
DB_FIELD_TRIAL_NAME = "_trial_name"

DEPRECATED_ALGORITHM_NAME = {
"chocolate-random": "random",
"chocolate-quasirandom": "quasirandom",
"chocolate-bayesian-optimization": "bayesianoptimization",
"chocolate-mocmaes": "mocmaes",
}


class BaseChocolateService(object):
"""
Expand Down Expand Up @@ -48,23 +56,32 @@ def create_optimizer(self, algorithm_name):
chocolate_search_space[key] = choco.choice(
[idx for idx, _ in enumerate(param.list)])

if algorithm_name in DEPRECATED_ALGORITHM_NAME:
warnings.warn(
"Algorithm name '{}' is deprecated. Please use '{}'.".format(
algorithm_name, DEPRECATED_ALGORITHM_NAME[algorithm_name],
),
DeprecationWarning,
)
algorithm_name = DEPRECATED_ALGORITHM_NAME[algorithm_name]

# Refer to https://chocolate.readthedocs.io/tutorials/algo.html
if algorithm_name == "grid":
self.chocolate_optimizer = choco.Grid(
self.conn, chocolate_search_space, clear_db=True)
# hyperopt-random is the default option in katib.
elif algorithm_name == "chocolate-random":
elif algorithm_name == "random":
self.chocolate_optimizer = choco.Random(
self.conn, chocolate_search_space, clear_db=True)
elif algorithm_name == "chocolate-quasirandom":
elif algorithm_name == "quasirandom":
self.chocolate_optimizer = choco.QuasiRandom(
self.conn, chocolate_search_space, clear_db=True)
elif algorithm_name == "chocolate-bayesian-optimization":
elif algorithm_name == "bayesianoptimization":
self.chocolate_optimizer = choco.Bayes(
self.conn, chocolate_search_space, clear_db=True)
# elif self.algorithm_name == "chocolate-CMAES":
# self.chocolate_optimizer = choco.CMAES(self.conn, chocolate_search_space, clear_db=True)
elif algorithm_name == "chocolate-mocmaes":
elif algorithm_name == "mocmaes":
mu = 1
self.chocolate_optimizer = choco.MOCMAES(
self.conn, chocolate_search_space, mu=mu, clear_db=True)
Expand Down
2 changes: 1 addition & 1 deletion pkg/suggestion/v1alpha3/chocolate/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def ValidateAlgorithmSettings(self, request, context):
request.experiment)
for param in search_space.params:
if param.type == DOUBLE:
if param.step == "" or param.step == None:
if param.step == "" or param.step is None:
return self._set_validate_context_error(
context, "param {} step is nil".format(param.name))
return api_pb2.ValidateAlgorithmSettingsReply()
Expand Down

0 comments on commit ef82a9d

Please sign in to comment.