ray.tune.search.dragonfly.DragonflySearch
ray.tune.search.dragonfly.DragonflySearch#
- class ray.tune.search.dragonfly.DragonflySearch(optimizer: Optional[str] = None, domain: Optional[str] = None, space: Optional[Union[Dict, List[Dict]]] = None, metric: Optional[str] = None, mode: Optional[str] = None, points_to_evaluate: Optional[List[Dict]] = None, evaluated_rewards: Optional[List] = None, random_state_seed: Optional[int] = None, **kwargs)[source]#
Bases:
ray.tune.search.searcher.Searcher
Uses Dragonfly to optimize hyperparameters.
Dragonfly provides an array of tools to scale up Bayesian optimisation to expensive large scale problems, including high dimensional optimisation. parallel evaluations in synchronous or asynchronous settings, multi-fidelity optimisation (using cheap approximations to speed up the optimisation process), and multi-objective optimisation. For more info:
Dragonfly Website: https://github.com/dragonfly/dragonfly
Dragonfly Documentation: https://dragonfly-opt.readthedocs.io/
To use this search algorithm, install Dragonfly:
$ pip install dragonfly-opt
This interface requires using FunctionCallers and optimizers provided by Dragonfly.
This searcher will automatically filter out any NaN, inf or -inf results.
- Parameters
optimizer – Optimizer provided from dragonfly. Choose an optimiser that extends BlackboxOptimiser. If this is a string,
domain
must be set andoptimizer
must be one of [random, bandit, genetic].domain – Optional domain. Should only be set if you don’t pass an optimizer as the
optimizer
argument. Has to be one of [cartesian, euclidean].space – Search space. Should only be set if you don’t pass an optimizer as the
optimizer
argument. Defines the search space and requires adomain
to be set. Can be automatically converted from theparam_space
dict passed totune.Tuner()
.metric – The training result objective value attribute. If None but a mode was passed, the anonymous metric
_metric
will be used per default.mode – One of {min, max}. Determines whether objective is minimizing or maximizing the metric attribute.
points_to_evaluate – Initial parameter suggestions to be run first. This is for when you already have some good parameters you want to run first to help the algorithm make better suggestions for future parameters. Needs to be a list of dicts containing the configurations.
evaluated_rewards – If you have previously evaluated the parameters passed in as points_to_evaluate you can avoid re-running those trials by passing in the reward attributes as a list so the optimiser can be told the results without needing to re-compute the trial. Must be the same length as points_to_evaluate.
random_state_seed – Seed for reproducible results. Defaults to None. Please note that setting this to a value will change global random state for
numpy
on initalization and loading from checkpoint.
Tune automatically converts search spaces to Dragonfly’s format:
from ray import tune config = { "LiNO3_vol": tune.uniform(0, 7), "Li2SO4_vol": tune.uniform(0, 7), "NaClO4_vol": tune.uniform(0, 7) } df_search = DragonflySearch( optimizer="bandit", domain="euclidean", metric="objective", mode="max") tuner = tune.Tuner( my_func, tune_config=tune.TuneConfig( search_alg=df_search ), param_space=config ) tuner.fit()
If you would like to pass the search space/optimizer manually, the code would look like this:
from ray import tune space = [{ "name": "LiNO3_vol", "type": "float", "min": 0, "max": 7 }, { "name": "Li2SO4_vol", "type": "float", "min": 0, "max": 7 }, { "name": "NaClO4_vol", "type": "float", "min": 0, "max": 7 }] df_search = DragonflySearch( optimizer="bandit", domain="euclidean", space=space, metric="objective", mode="max") tuner = tune.Tuner( my_func, tune_config=tune.TuneConfig( search_alg=df_search ), ) tuner.fit()
Methods
add_evaluated_trials
(trials_or_analysis, metric)Pass results from trials that have been evaluated separately.
on_trial_complete
(trial_id[, result, error])Passes result to Dragonfly unless early terminated or errored.
on_trial_result
(trial_id, result)Optional notification for result during training.
restore_from_dir
(checkpoint_dir)Restores the state of a searcher from a given checkpoint_dir.
save_to_dir
(checkpoint_dir[, session_str])Automatically saves the given searcher to the checkpoint_dir.
set_max_concurrency
(max_concurrent)Set max concurrent trials this searcher can run.
Attributes
The training result objective value attribute.
Specifies if minimizing or maximizing the metric.