diff --git a/python/ray/tune/examples/hyperopt_example.py b/python/ray/tune/examples/hyperopt_example.py index b81680b4c..3d8bfab81 100644 --- a/python/ray/tune/examples/hyperopt_example.py +++ b/python/ray/tune/examples/hyperopt_example.py @@ -28,7 +28,7 @@ if __name__ == "__main__": parser.add_argument( "--smoke-test", action="store_true", help="Finish quickly for testing") args, _ = parser.parse_known_args() - ray.init(configure_logging=False) + ray.init() space = { "width": hp.uniform("width", 0, 20), diff --git a/python/ray/tune/suggest/ax.py b/python/ray/tune/suggest/ax.py index cb714f829..5713f93f6 100644 --- a/python/ray/tune/suggest/ax.py +++ b/python/ray/tune/suggest/ax.py @@ -70,15 +70,18 @@ class AxSearch(Searcher): logger.warning("Detected sequential enforcement. Setting max " "concurrency to 1.") max_concurrent = 1 + self.max_concurrent = max_concurrent self._parameters = list(exp.parameters) self._live_index_mapping = {} super(AxSearch, self).__init__( metric=self._objective_name, mode=mode, - max_concurrent=max_concurrent, use_early_stopped_trials=use_early_stopped_trials) def suggest(self, trial_id): + if self.max_concurrent: + if len(self._live_trial_mapping) >= self.max_concurrent: + return None parameters, trial_index = self._ax.get_next_trial() self._live_index_mapping[trial_id] = trial_index return parameters diff --git a/python/ray/tune/suggest/bayesopt.py b/python/ray/tune/suggest/bayesopt.py index d734126e9..1de179cfa 100644 --- a/python/ray/tune/suggest/bayesopt.py +++ b/python/ray/tune/suggest/bayesopt.py @@ -60,7 +60,7 @@ class BayesOptSearch(Searcher): assert utility_kwargs is not None, ( "Must define arguments for the utility function!") assert mode in ["min", "max"], "`mode` must be 'min' or 'max'!" - + self.max_concurrent = max_concurrent super(BayesOptSearch, self).__init__( metric=metric, mode=mode, @@ -79,6 +79,9 @@ class BayesOptSearch(Searcher): self.utility = byo.UtilityFunction(**utility_kwargs) def suggest(self, trial_id): + if self.max_concurrent: + if len(self._live_trial_mapping) >= self.max_concurrent: + return None new_trial = self.optimizer.suggest(self.utility) self._live_trial_mapping[trial_id] = new_trial diff --git a/python/ray/tune/suggest/hyperopt.py b/python/ray/tune/suggest/hyperopt.py index 8b6cb4517..f328630ea 100644 --- a/python/ray/tune/suggest/hyperopt.py +++ b/python/ray/tune/suggest/hyperopt.py @@ -88,6 +88,7 @@ class HyperOptSearch(Searcher): mode=mode, max_concurrent=max_concurrent, use_early_stopped_trials=use_early_stopped_trials) + self.max_concurrent = max_concurrent # hyperopt internally minimizes, so "max" => -1 if mode == "max": self.metric_op = -1. @@ -118,6 +119,9 @@ class HyperOptSearch(Searcher): self.rstate = np.random.RandomState(random_state_seed) def suggest(self, trial_id): + if self.max_concurrent: + if len(self._live_trial_mapping) >= self.max_concurrent: + return None if self._points_to_evaluate > 0: new_trial = self._hpopt_trials.trials[self._points_to_evaluate - 1] self._points_to_evaluate -= 1 diff --git a/python/ray/tune/suggest/nevergrad.py b/python/ray/tune/suggest/nevergrad.py index fae75c895..55732fae1 100644 --- a/python/ray/tune/suggest/nevergrad.py +++ b/python/ray/tune/suggest/nevergrad.py @@ -62,6 +62,7 @@ class NevergradSearch(Searcher): parameter_names, metric="episode_reward_mean", mode="max", + max_concurrent=None, **kwargs): assert ng is not None, "Nevergrad must be installed!" assert mode in ["min", "max"], "`mode` must be 'min' or 'max'!" @@ -74,8 +75,9 @@ class NevergradSearch(Searcher): self._metric_op = 1. self._nevergrad_opt = optimizer self._live_trial_mapping = {} + self.max_concurrent = max_concurrent super(NevergradSearch, self).__init__( - metric=metric, mode=mode, **kwargs) + metric=metric, mode=mode, max_concurrent=max_concurrent, **kwargs) # validate parameters if hasattr(optimizer, "instrumentation"): # added in v0.2.0 if optimizer.instrumentation.kwargs: @@ -98,6 +100,9 @@ class NevergradSearch(Searcher): "dimension for non-instrumented optimizers") def suggest(self, trial_id): + if self.max_concurrent: + if len(self._live_trial_mapping) >= self.max_concurrent: + return None suggested_config = self._nevergrad_opt.ask() self._live_trial_mapping[trial_id] = suggested_config # in v0.2.0+, output of ask() is a Candidate, diff --git a/python/ray/tune/suggest/skopt.py b/python/ray/tune/suggest/skopt.py index 55f7a4f82..46d21db32 100644 --- a/python/ray/tune/suggest/skopt.py +++ b/python/ray/tune/suggest/skopt.py @@ -93,6 +93,7 @@ class SkOptSearch(Searcher): _validate_warmstart(parameter_names, points_to_evaluate, evaluated_rewards) assert mode in ["min", "max"], "`mode` must be 'min' or 'max'!" + self.max_concurrent = max_concurrent super(SkOptSearch, self).__init__( metric=metric, mode=mode, @@ -114,6 +115,9 @@ class SkOptSearch(Searcher): self._live_trial_mapping = {} def suggest(self, trial_id): + if self.max_concurrent: + if len(self._live_trial_mapping) >= self.max_concurrent: + return None if self._initial_points: suggested_config = self._initial_points[0] del self._initial_points[0] diff --git a/python/ray/tune/suggest/suggestion.py b/python/ray/tune/suggest/suggestion.py index 4719666b2..68d2e49b5 100644 --- a/python/ray/tune/suggest/suggestion.py +++ b/python/ray/tune/suggest/suggestion.py @@ -68,9 +68,10 @@ class Searcher: "Early stopped trials are now always used. If this is a " "problem, file an issue: https://github.com/ray-project/ray.") if max_concurrent is not None: - raise DeprecationWarning( - "max_concurrent is now deprecated for this search algorithm. " - "Please use tune.suggest.ConcurrencyLimiter instead.") + logger.warning( + "DeprecationWarning: `max_concurrent` is deprecated for this " + "search algorithm. Use tune.suggest.ConcurrencyLimiter() " + "instead. This will raise an error in future versions of Ray.") assert mode in ["min", "max"], "`mode` must be 'min' or 'max'!" self._metric = metric self._mode = mode