Files
ray/python/ray/tune/suggest/__init__.py
T
Sumanth Ratna 54215ff287 [tune] implement shim instantiation (#10456)
* Create ray.tune.suggest.create.create_scheduler

* Update __init__.py

* Resolve conflict in __init__.py

* Create ray.tune.schedulers.create.create_scheduler

* Update __init__.py

* Move create_scheduler to tune.schedulers.__init__

* Move create_searcher to tune.suggest.__init__

* Delete tune.suggest.create

* Delete tune.schedulers.create

* Update imports for shim functions in tune.__init__

* Remove shim from tune.suggest.__init__.__all__

* Remove shim from tune.schedulers.__init__.__all__

* Add ShimCreationTest

* Move ShimCreationTest to test_api

* Delete test_shim.py

* Add docstring for ray.tune.create_scheduler

* Add docstring to ray.tune.create_searcher

* Fix typo in ray.tune.create_scheduler docstring

* Fix lint errors in tune.schedulers.__init__

* Fix lint errors in tune.suggest.__init__

* Fix lint errors in tune.suggest.__init__

* Fix lint errors in tune.schedulers.__init__

* Fix imports in test_api

* Fix lint errors in test_api

* Fix kwargs in create_searcher

* Fix kwargs in create_scheduler

* Merge branch 'master' into shim-instantiation

* Update use-case in docs in tune.create_scheduler

* Update use-case in docs in tune.create_searcher

* Remove duplicate pytest run from test_api

* Add check to create_searcher


Co-authored-by: Richard Liaw <rliaw@berkeley.edu>

* Add check to create_scheduler

* lint

* Compare types of instances in test_api

Co-authored-by: Richard Liaw <rliaw@berkeley.edu>

* Add tune.create_searcher to docs

* Fix doc build

* Fix tests

* Add tune.create_scheduler to docs

* Fix tests

* Fix lint errors

* Update Ax search for master

* Fix metric kwarg for Ax in test_api

* Fix doc build

* Fix HyperOptSearch import in test_api

* Fix HyperOptSearch import in create_searcher

Co-authored-by: Richard Liaw <rliaw@berkeley.edu>
2020-09-05 09:36:42 -07:00

125 lines
4.1 KiB
Python

from ray.tune.suggest.search import SearchAlgorithm
from ray.tune.suggest.basic_variant import BasicVariantGenerator
from ray.tune.suggest.suggestion import Searcher, ConcurrencyLimiter
from ray.tune.suggest.search_generator import SearchGenerator
from ray.tune.suggest.variant_generator import grid_search
from ray.tune.suggest.repeater import Repeater
def create_searcher(
search_alg,
metric="episode_reward_mean",
mode="max",
**kwargs,
):
"""Instantiate a search algorithm based on the given string.
This is useful for swapping between different search algorithms.
Args:
search_alg (str): The search algorithm to use.
metric (str): The training result objective value attribute. Stopping
procedures will use this attribute.
mode (str): One of {min, max}. Determines whether objective is
minimizing or maximizing the metric attribute.
**kwargs: Additional parameters.
These keyword arguments will be passed to the initialization
function of the chosen class.
Returns:
ray.tune.suggest.Searcher: The search algorithm.
Example:
>>> search_alg = tune.create_searcher('ax')
"""
def _import_ax_search():
from ray.tune.suggest.ax import AxSearch
return AxSearch
def _import_dragonfly_search():
from ray.tune.suggest.dragonfly import DragonflySearch
return DragonflySearch
def _import_skopt_search():
from ray.tune.suggest.skopt import SkOptSearch
return SkOptSearch
def _import_hyperopt_search():
from ray.tune.suggest.hyperopt import HyperOptSearch
return HyperOptSearch
def _import_bayesopt_search():
from ray.tune.suggest.bayesopt import BayesOptSearch
return BayesOptSearch
def _import_bohb_search():
from ray.tune.suggest.bohb import TuneBOHB
return TuneBOHB
def _import_nevergrad_search():
from ray.tune.suggest.nevergrad import NevergradSearch
return NevergradSearch
def _import_optuna_search():
from ray.tune.suggest.optuna import OptunaSearch
return OptunaSearch
def _import_zoopt_search():
from ray.tune.suggest.zoopt import ZOOptSearch
return ZOOptSearch
def _import_sigopt_search():
from ray.tune.suggest.sigopt import SigOptSearch
return SigOptSearch
SEARCH_ALG_IMPORT = {
"ax": _import_ax_search,
"dragonfly": _import_dragonfly_search,
"skopt": _import_skopt_search,
"hyperopt": _import_hyperopt_search,
"bayesopt": _import_bayesopt_search,
"bohb": _import_bohb_search,
"nevergrad": _import_nevergrad_search,
"optuna": _import_optuna_search,
"zoopt": _import_zoopt_search,
"sigopt": _import_sigopt_search,
}
search_alg = search_alg.lower()
if search_alg not in SEARCH_ALG_IMPORT:
raise ValueError(
f"Search alg must be one of {list(SEARCH_ALG_IMPORT)}. "
f"Got: {search_alg}")
SearcherClass = SEARCH_ALG_IMPORT[search_alg]()
return SearcherClass(metric=metric, mode=mode, **kwargs)
__all__ = [
"SearchAlgorithm", "Searcher", "BasicVariantGenerator", "SearchGenerator",
"grid_search", "Repeater", "ConcurrencyLimiter"
]
def BayesOptSearch(*args, **kwargs):
raise DeprecationWarning("""This class has been moved. Please import via
`from ray.tune.suggest.bayesopt import BayesOptSearch`""")
def HyperOptSearch(*args, **kwargs):
raise DeprecationWarning("""This class has been moved. Please import via
`from ray.tune.suggest.hyperopt import HyperOptSearch`""")
def NevergradSearch(*args, **kwargs):
raise DeprecationWarning("""This class has been moved. Please import via
`from ray.tune.suggest.nevergrad import NevergradSearch`""")
def SkOptSearch(*args, **kwargs):
raise DeprecationWarning("""This class has been moved. Please import via
`from ray.tune.suggest.skopt import SkOptSearch`""")
def SigOptSearch(*args, **kwargs):
raise DeprecationWarning("""This class has been moved. Please import via
`from ray.tune.suggest.sigopt import SigOptSearch`""")