From 0ddd93ab91ff686d8c80470961a2068caa617ff4 Mon Sep 17 00:00:00 2001 From: Antoni Baum Date: Wed, 5 Oct 2022 02:22:27 +0200 Subject: [PATCH] Move tune imports to new locations (#253) * Move tune imports to new locations Signed-off-by: Antoni Baum * Fix master test Signed-off-by: Antoni Baum * Bump Ray version Signed-off-by: Antoni Baum * Remove debug Signed-off-by: Antoni Baum Signed-off-by: Antoni Baum --- .github/workflows/test.yml | 2 +- examples/custom_searcher_example.py | 4 ++-- setup.py | 4 +++- tests/test_randomizedsearch.py | 8 ++++---- tune_sklearn/list_searcher.py | 2 +- tune_sklearn/tune_basesearch.py | 2 +- tune_sklearn/tune_search.py | 18 +++++++++--------- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 14db6408..94e5126b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,7 @@ jobs: python -m pip install --upgrade pip python -m pip install -U pytest python -m pip install codecov - python -m pip install -U https://s3-us-west-2.amazonaws.com/ray-wheels/latest/ray-2.0.0.dev0-cp37-cp37m-manylinux2014_x86_64.whl + python -m pip install -U https://s3-us-west-2.amazonaws.com/ray-wheels/latest/ray-3.0.0.dev0-cp37-cp37m-manylinux2014_x86_64.whl python -m pip install -U -q scikit-learn scikit-optimize hyperopt hpbandster ConfigSpace scipy dataclasses optuna keras if [ -f requirements-test.txt ]; then python -m pip install -r requirements-test.txt; fi - name: Install package diff --git a/examples/custom_searcher_example.py b/examples/custom_searcher_example.py index 170eeaff..30ad65de 100644 --- a/examples/custom_searcher_example.py +++ b/examples/custom_searcher_example.py @@ -5,7 +5,7 @@ from tune_sklearn import TuneSearchCV from ray import tune -from ray.tune.suggest.hebo import HEBOSearch +from ray.tune.search.hebo import HEBOSearch from sklearn.ensemble import RandomForestClassifier from sklearn import datasets from sklearn.model_selection import train_test_split @@ -28,7 +28,7 @@ searcher = HEBOSearch() # It is also possible to use user-defined Searchers, as long as -# they inherit from ray.tune.suggest.Searcher and have the following +# they inherit from ray.tune.search.Searcher and have the following # attributes: _space, _metric, _mode tune_search = TuneSearchCV( diff --git a/setup.py b/setup.py index 4d3c6f8b..8c9ba1d5 100644 --- a/setup.py +++ b/setup.py @@ -27,4 +27,6 @@ os.path.join(ROOT_DIR, "README.md"), "r", encoding="utf-8").read(), long_description_content_type="text/markdown", url="https://github.com/ray-project/tune-sklearn", - install_requires=["scikit-learn", "scipy", "ray[tune]", "numpy>=1.16"]) + install_requires=[ + "scikit-learn", "scipy", "ray[tune]>=2.0.0", "numpy>=1.16" + ]) diff --git a/tests/test_randomizedsearch.py b/tests/test_randomizedsearch.py index b7bd11ed..0240e98e 100644 --- a/tests/test_randomizedsearch.py +++ b/tests/test_randomizedsearch.py @@ -692,7 +692,7 @@ def testOptuna(self): self._test_method("optuna") def testCustomSearcher(self): - from ray.tune.suggest.hyperopt import HyperOptSearch + from ray.tune.search.hyperopt import HyperOptSearch class CustomSearcher(HyperOptSearch): pass @@ -708,7 +708,7 @@ class ThisShouldRaiseAnExc: self._test_method(CustomSearcher()) def testCustomSearcherWithSearchSpaceException(self): - from ray.tune.suggest.hyperopt import HyperOptSearch + from ray.tune.search.hyperopt import HyperOptSearch from hyperopt import hp class CustomSearcher(HyperOptSearch): @@ -737,7 +737,7 @@ class CustomSearcher(HyperOptSearch): " its mode") in str(exc.exception)) def testCustomSearcherWithSearchSpace(self): - from ray.tune.suggest.hyperopt import HyperOptSearch + from ray.tune.search.hyperopt import HyperOptSearch from hyperopt import hp class CustomSearcher(HyperOptSearch): @@ -827,7 +827,7 @@ def testBayesianPointsToEvaluate(self): self._test_points_to_evaluate("bayesian") def testHyperoptPointsToEvaluate(self): - from ray.tune.suggest.hyperopt import HyperOptSearch + from ray.tune.search.hyperopt import HyperOptSearch # Skip test if category conversion is not available if not hasattr(HyperOptSearch, "_convert_categories_to_indices"): self.skipTest(f"The current version of Ray does not support the " diff --git a/tune_sklearn/list_searcher.py b/tune_sklearn/list_searcher.py index bce7533e..8a611635 100644 --- a/tune_sklearn/list_searcher.py +++ b/tune_sklearn/list_searcher.py @@ -4,7 +4,7 @@ """ from sklearn.model_selection import ParameterGrid -from ray.tune.suggest.suggestion import Searcher +from ray.tune.search.searcher import Searcher import random diff --git a/tune_sklearn/tune_basesearch.py b/tune_sklearn/tune_basesearch.py index 61901d05..6e3483c6 100644 --- a/tune_sklearn/tune_basesearch.py +++ b/tune_sklearn/tune_basesearch.py @@ -30,7 +30,7 @@ import numbers import ray -from ray.tune.trial import Trial +from ray.tune.experiment.trial import Trial from ray.tune.schedulers import ( PopulationBasedTraining, AsyncHyperBandScheduler, HyperBandScheduler, MedianStoppingRule, TrialScheduler, ASHAScheduler, HyperBandForBOHB) diff --git a/tune_sklearn/tune_search.py b/tune_sklearn/tune_search.py index 2bb04842..6fd35a66 100644 --- a/tune_sklearn/tune_search.py +++ b/tune_sklearn/tune_search.py @@ -9,15 +9,15 @@ from sklearn.base import clone from ray import tune -from ray.tune.sample import Domain -from ray.tune.suggest import (ConcurrencyLimiter, BasicVariantGenerator, - Searcher) -from ray.tune.suggest.bohb import TuneBOHB +from ray.tune.search.sample import Domain +from ray.tune.search import (ConcurrencyLimiter, BasicVariantGenerator, + Searcher) +from ray.tune.search.bohb import TuneBOHB from ray.tune.schedulers import HyperBandForBOHB from ray.tune.stopper import CombinedStopper -from ray.tune.suggest.skopt import SkOptSearch -from ray.tune.suggest.hyperopt import HyperOptSearch -from ray.tune.suggest.optuna import OptunaSearch +from ray.tune.search.skopt import SkOptSearch +from ray.tune.search.hyperopt import HyperOptSearch +from ray.tune.search.optuna import OptunaSearch from tune_sklearn.utils import check_is_pipeline, MaximumIterationStopper from tune_sklearn.tune_basesearch import TuneBaseSearchCV @@ -254,7 +254,7 @@ class TuneSearchCV(TuneBaseSearchCV): resource_param (max_iter or n_estimators) is incremented by `max resource value // max_iters`. search_optimization ("random" or "bayesian" or "bohb" or "hyperopt" - or "optuna" or `ray.tune.suggest.Searcher` instance): + or "optuna" or `ray.tune.search.Searcher` instance): Randomized search is invoked with ``search_optimization`` set to ``"random"`` and behaves like scikit-learn's ``RandomizedSearchCV``. @@ -350,7 +350,7 @@ def __init__(self, raise ValueError( "Search optimization must be one of " f"{', '.join(list(available_optimizations.values()))} " - "or a ray.tune.suggest.Searcher instance.") + "or a ray.tune.search.Searcher instance.") if isinstance(self._search_optimization_lower, Searcher): if not hasattr(self._search_optimization_lower,