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

Rename chocolate algorithm names for consistency #1164

Merged
merged 1 commit into from
Apr 26, 2020
Merged
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
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