From 03f22058b043a3c880f17beeedaa55c8e64ef2c5 Mon Sep 17 00:00:00 2001 From: gjoliver Date: Wed, 17 Nov 2021 10:27:00 -0800 Subject: [PATCH 1/5] [rllib] Make sure json can serialize result dict (#20439) We may have fields in the result dict that are or None. Make sure our results are json serializable. --- python/ray/tune/suggest/optuna.py | 93 ++++++++++++++++--- python/requirements/ml/requirements_rllib.txt | 2 +- release/rllib_tests/app_config.yaml | 2 + rllib/utils/test_utils.py | 9 +- 4 files changed, 87 insertions(+), 19 deletions(-) diff --git a/python/ray/tune/suggest/optuna.py b/python/ray/tune/suggest/optuna.py index c69ef4fa34c3..21945a145d32 100644 --- a/python/ray/tune/suggest/optuna.py +++ b/python/ray/tune/suggest/optuna.py @@ -3,7 +3,7 @@ import pickle import functools import warnings -from typing import Any, Callable, Dict, List, Optional, Tuple, Union +from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Union from ray.tune.result import DEFAULT_METRIC, TRAINING_ITERATION from ray.tune.sample import Categorical, Domain, Float, Integer, LogUniform, \ @@ -76,6 +76,8 @@ class OptunaSearch(Searcher): You can pass any Optuna sampler, which will be used to generate hyperparameter suggestions. + Multi-objective optimization is supported. + Args: space (dict|Callable): Hyperparameter search space definition for Optuna's sampler. This can be either a :class:`dict` with @@ -92,18 +94,23 @@ class OptunaSearch(Searcher): function. Instead, put the training logic inside the function or class trainable passed to ``tune.run``. - metric (str): The training result objective value attribute. If None - but a mode was passed, the anonymous metric `_metric` will be used - per default. - mode (str): One of {min, max}. Determines whether objective is - minimizing or maximizing the metric attribute. + metric (str|list): The training result objective value attribute. If + None but a mode was passed, the anonymous metric ``_metric`` + will be used per default. Can be a list of metrics for + multi-objective optimization. + mode (str|list): One of {min, max}. Determines whether objective is + minimizing or maximizing the metric attribute. Can be a list of + modes for multi-objective optimization (corresponding to + ``metric``). points_to_evaluate (list): 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. sampler (optuna.samplers.BaseSampler): Optuna sampler used to - draw hyperparameter configurations. Defaults to ``TPESampler``. + draw hyperparameter configurations. Defaults to ``TPESampler`` + for single-objective optimization and ``MOTPESampler`` for + multi-objective optimization. seed (int): Seed to initialize sampler with. This parameter is only used when ``sampler=None``. In all other cases, the sampler you pass should be initialized with the seed already. @@ -173,6 +180,34 @@ def define_search_space(trial: optuna.Trial): tune.run(trainable, search_alg=optuna_search) + Multi-objective optimization is supported: + + .. code-block:: python + + from ray.tune.suggest.optuna import OptunaSearch + import optuna + + space = { + "a": optuna.distributions.UniformDistribution(6, 8), + "b": optuna.distributions.LogUniformDistribution(1e-4, 1e-2), + } + + # Note you have to specify metric and mode here instead of + # in tune.run + optuna_search = OptunaSearch( + space, + metric=["loss1", "loss2"], + mode=["min", "max"]) + + # The metric and mode specified here will be used for sorting + # trials, and not during search itself + tune.run( + trainable, + metric="loss1", + mode="min", + search_alg=optuna_search + ) + You can pass configs that will be evaluated first using ``points_to_evaluate``: @@ -224,8 +259,9 @@ def __init__(self, space: Optional[Union[Dict[str, "OptunaDistribution"], List[ Tuple], Callable[["OptunaTrial"], Optional[Dict[ str, Any]]]]] = None, - metric: Optional[str] = None, - mode: Optional[str] = None, + metric: Optional[Union[str, List[str]]] = None, + mode: Optional[Union[Literal["min"], Literal["max"], List[ + Union[Literal["min"], Literal["max"]]]]] = None, points_to_evaluate: Optional[List[Dict]] = None, sampler: Optional["BaseSampler"] = None, seed: Optional[int] = None, @@ -262,7 +298,12 @@ def __init__(self, "`seed` parameter has to be passed to the sampler directly " "and will be ignored.") - self._sampler = sampler or ot.samplers.TPESampler(seed=seed) + if sampler: + self._sampler = sampler + elif isinstance(mode, list): + self._sampler = ot.samplers.MOTPESampler(seed=seed) + else: + self._sampler = ot.samplers.TPESampler(seed=seed) assert isinstance(self._sampler, BaseSampler), \ "You can only pass an instance of `optuna.samplers.BaseSampler` " \ @@ -275,19 +316,32 @@ def __init__(self, def _setup_study(self, mode: str): if self._metric is None and self._mode: + if isinstance(self._mode, list): + raise ValueError( + "If ``mode`` is a list (multi-objective optimization " + "case), ``metric`` must be defined.") # If only a mode was passed, use anonymous metric self._metric = DEFAULT_METRIC pruner = ot.pruners.NopPruner() storage = ot.storages.InMemoryStorage() + if isinstance(mode, list): + study_direction_args = dict( + directions=[ + "minimize" if m == "min" else "maximize" for m in mode + ], ) + else: + study_direction_args = dict( + direction="minimize" if mode == "min" else "maximize", ) + self._ot_study = ot.study.create_study( storage=storage, sampler=self._sampler, pruner=pruner, study_name=self._study_name, - direction="minimize" if mode == "min" else "maximize", - load_if_exists=True) + load_if_exists=True, + **study_direction_args) if self._points_to_evaluate: validate_warmstart( @@ -314,7 +368,7 @@ def set_search_properties(self, metric: Optional[str], mode: Optional[str], if mode: self._mode = mode - self._setup_study(mode) + self._setup_study(self._mode) return True def _suggest_from_define_by_run_func( @@ -360,6 +414,7 @@ def suggest(self, trial_id: str) -> Optional[Dict]: metric=self._metric, mode=self._mode)) if callable(self._space): + # Define-by-run case if trial_id not in self._ot_trials: self._ot_trials[trial_id] = self._ot_study.ask() @@ -378,6 +433,10 @@ def suggest(self, trial_id: str) -> Optional[Dict]: return unflatten_dict(params) def on_trial_result(self, trial_id: str, result: Dict): + if isinstance(self.metric, list): + # Optuna doesn't support incremental results + # for multi-objective optimization + return metric = result[self.metric] step = result[TRAINING_ITERATION] ot_trial = self._ot_trials[trial_id] @@ -389,7 +448,13 @@ def on_trial_complete(self, error: bool = False): ot_trial = self._ot_trials[trial_id] - val = result.get(self.metric, None) if result else None + if result: + if isinstance(self.metric, list): + val = [result.get(metric, None) for metric in self.metric] + else: + val = result.get(self.metric, None) + else: + val = None ot_trial_state = OptunaTrialState.COMPLETE if val is None: if error: diff --git a/python/requirements/ml/requirements_rllib.txt b/python/requirements/ml/requirements_rllib.txt index e26422385dff..a9b500e40165 100644 --- a/python/requirements/ml/requirements_rllib.txt +++ b/python/requirements/ml/requirements_rllib.txt @@ -15,7 +15,7 @@ pettingzoo==1.11.1 pymunk==6.0.0 supersuit==2.6.6 # For testing in MuJoCo-like envs (in PyBullet). -pybullet==3.1.7 +pybullet==3.2.0 # For tests on RecSim and Kaggle envs. recsim==0.2.4 tensorflow_estimator==2.6.0 diff --git a/release/rllib_tests/app_config.yaml b/release/rllib_tests/app_config.yaml index 18dd76969c95..5029c76d1ae0 100755 --- a/release/rllib_tests/app_config.yaml +++ b/release/rllib_tests/app_config.yaml @@ -14,6 +14,8 @@ post_build_cmds: - pip uninstall -y ray || true - pip3 install -U {{ env["RAY_WHEELS"] | default("ray") }} - {{ env["RAY_WHEELS_SANITY_CHECK"] | default("echo No Ray wheels sanity check") }} + # TODO(jungong): remove once nightly image gets upgraded. + - pip install -U pybullet==3.2.0 # Clone the rl-experiments repo for offline-RL files. - git clone https://github.com/ray-project/rl-experiments.git - cp rl-experiments/halfcheetah-sac/2021-09-06/halfcheetah_expert_sac.zip ~/. diff --git a/rllib/utils/test_utils.py b/rllib/utils/test_utils.py index c0716d0037a1..ef57e2782aa2 100644 --- a/rllib/utils/test_utils.py +++ b/rllib/utils/test_utils.py @@ -759,8 +759,9 @@ def run_learning_tests_from_yaml( # Record performance. stats[experiment] = { - "episode_reward_mean": episode_reward_mean, - "throughput": throughput, + "episode_reward_mean": float(episode_reward_mean), + "throughput": (float(throughput) + if throughput is not None else 0.0), } print(f" ... Desired reward={desired_reward}; " @@ -787,9 +788,9 @@ def run_learning_tests_from_yaml( # Create results dict and write it to disk. result = { - "time_taken": time_taken, + "time_taken": float(time_taken), "trial_states": dict(Counter([trial.status for trial in all_trials])), - "last_update": time.time(), + "last_update": float(time.time()), "stats": stats, "passed": [k for k, exp in checks.items() if exp["passed"]], "failures": { From a4b2992323ca84d659d2141819b2510a66fb961b Mon Sep 17 00:00:00 2001 From: Antoni Baum Date: Wed, 17 Nov 2021 20:00:28 +0000 Subject: [PATCH 2/5] Add test --- python/ray/tune/tests/test_searchers.py | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/python/ray/tune/tests/test_searchers.py b/python/ray/tune/tests/test_searchers.py index 49eeef31db38..c2f73917bc59 100644 --- a/python/ray/tune/tests/test_searchers.py +++ b/python/ray/tune/tests/test_searchers.py @@ -23,6 +23,10 @@ def _invalid_objective(config): tune.report(float(config[metric]) or 0.1) +def _multi_objective(config): + tune.report(a=config["a"] * 100, b=config["b"] * -100, c=config["c"]) + + class InvalidValuesTest(unittest.TestCase): """ Test searcher handling of invalid values (NaN, -inf, inf). @@ -602,6 +606,54 @@ def testZOOpt(self): self._restore(searcher) +class MultiObjectiveTest(unittest.TestCase): + """ + Test multi-objective optimization in searchers that support it. + """ + + def setUp(self): + self.config = { + "a": tune.uniform(0, 1), + "b": tune.uniform(0, 1), + "c": tune.uniform(0, 1) + } + + def tearDown(self): + pass + + @classmethod + def setUpClass(cls): + ray.init(num_cpus=4, num_gpus=0, include_dashboard=False) + + @classmethod + def tearDownClass(cls): + ray.shutdown() + + def testOptuna(self): + from ray.tune.suggest.optuna import OptunaSearch + from optuna.samplers import RandomSampler + + np.random.seed(1000) + + out = tune.run( + _multi_objective, + search_alg=OptunaSearch( + sampler=RandomSampler(seed=1234), + metric=["a", "b", "c"], + mode=["max", "min", "max"], + ), + config=self.config, + num_samples=16, + reuse_actors=False) + + best_trial_a = out.get_best_trial("a", "max") + self.assertGreaterEqual(best_trial_a.config["a"], 0.8) + best_trial_b = out.get_best_trial("b", "min") + self.assertGreaterEqual(best_trial_b.config["b"], 0.8) + best_trial_c = out.get_best_trial("c", "max") + self.assertGreaterEqual(best_trial_c.config["c"], 0.8) + + if __name__ == "__main__": import pytest import sys From b335e98e63dfd57c3ba127f02c27fb6ec30d8e4d Mon Sep 17 00:00:00 2001 From: Antoni Baum Date: Wed, 17 Nov 2021 20:12:37 +0000 Subject: [PATCH 3/5] Add docs, example --- doc/source/tune/examples/index.rst | 1 + doc/source/tune/examples/optuna_example.rst | 2 +- .../optuna_multiobjective_example.rst | 6 ++ python/ray/tune/BUILD | 9 +++ ...peropt_conditional_search_space_example.py | 2 +- .../examples/optuna_multiobjective_example.py | 74 +++++++++++++++++++ python/ray/tune/suggest/optuna.py | 34 +++++---- 7 files changed, 110 insertions(+), 18 deletions(-) create mode 100644 doc/source/tune/examples/optuna_multiobjective_example.rst create mode 100644 python/ray/tune/examples/optuna_multiobjective_example.py diff --git a/doc/source/tune/examples/index.rst b/doc/source/tune/examples/index.rst index 22cec4451b14..d3fe5696ff0d 100644 --- a/doc/source/tune/examples/index.rst +++ b/doc/source/tune/examples/index.rst @@ -45,6 +45,7 @@ Search Algorithm Examples - :doc:`/tune/examples/nevergrad_example`: Example script showing usage of :ref:`NevergradSearch ` [`Nevergrad website `__] - :doc:`/tune/examples/optuna_example`: Example script showing usage of :ref:`OptunaSearch ` [`Optuna website `__] - :doc:`/tune/examples/optuna_define_by_run_example`: Example script showing usage of :ref:`OptunaSearch ` [`Optuna website `__] with a define-by-run function +- :doc:`/tune/examples/optuna_multiobjective_example`: Example script showing usage of :ref:`OptunaSearch ` [`Optuna website `__] for multi-objective optimization - :doc:`/tune/examples/zoopt_example`: Example script showing usage of :ref:`ZOOptSearch ` [`ZOOpt website `__] - :doc:`/tune/examples/sigopt_example`: Example script showing usage of :ref:`SigOptSearch ` [`SigOpt website `__] - :doc:`/tune/examples/hebo_example`: Example script showing usage of :ref:`HEBOSearch ` [`HEBO website `__] diff --git a/doc/source/tune/examples/optuna_example.rst b/doc/source/tune/examples/optuna_example.rst index 296bebb652b6..8dcff5fabe4a 100644 --- a/doc/source/tune/examples/optuna_example.rst +++ b/doc/source/tune/examples/optuna_example.rst @@ -1,6 +1,6 @@ :orphan: optuna_example -~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~ .. literalinclude:: /../../python/ray/tune/examples/optuna_example.py \ No newline at end of file diff --git a/doc/source/tune/examples/optuna_multiobjective_example.rst b/doc/source/tune/examples/optuna_multiobjective_example.rst new file mode 100644 index 000000000000..15127513807a --- /dev/null +++ b/doc/source/tune/examples/optuna_multiobjective_example.rst @@ -0,0 +1,6 @@ +:orphan: + +optuna_multiobjective_example +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. literalinclude:: /../../python/ray/tune/examples/optuna_multiobjective_example.py \ No newline at end of file diff --git a/python/ray/tune/BUILD b/python/ray/tune/BUILD index bd8dffd55b62..ec43603125ec 100644 --- a/python/ray/tune/BUILD +++ b/python/ray/tune/BUILD @@ -670,6 +670,15 @@ py_test( args = ["--smoke-test"] ) +py_test( + name = "optuna_multiobjective_example", + size = "small", + srcs = ["examples/optuna_multiobjective_example.py"], + deps = [":tune_lib"], + tags = ["team:ml", "exclusive", "example"], + args = ["--smoke-test"] +) + py_test( name = "pb2_example", size = "medium", diff --git a/python/ray/tune/examples/hyperopt_conditional_search_space_example.py b/python/ray/tune/examples/hyperopt_conditional_search_space_example.py index 22ca8694b996..856df2f0cdf3 100644 --- a/python/ray/tune/examples/hyperopt_conditional_search_space_example.py +++ b/python/ray/tune/examples/hyperopt_conditional_search_space_example.py @@ -3,7 +3,7 @@ It also checks that it is usable with a separate scheduler. For an example of using a Tune search space, see -:doc:`/tune/examples/optuna_example`. +:doc:`/tune/examples/hyperopt_example`. """ import time diff --git a/python/ray/tune/examples/optuna_multiobjective_example.py b/python/ray/tune/examples/optuna_multiobjective_example.py new file mode 100644 index 000000000000..3e9a8d5cb4f2 --- /dev/null +++ b/python/ray/tune/examples/optuna_multiobjective_example.py @@ -0,0 +1,74 @@ +"""This example demonstrates the usage of Optuna with Ray Tune for +multi-objective optimization. + +Please note that schedulers may not work correctly with multi-objective +optimization. +""" +import time + +import ray +from ray import tune +from ray.tune.suggest import ConcurrencyLimiter +from ray.tune.suggest.optuna import OptunaSearch + + +def evaluation_fn(step, width, height): + return (0.1 + width * step / 100)**(-1) + height * 0.1 + + +def easy_objective(config): + # Hyperparameters + width, height = config["width"], config["height"] + + for step in range(config["steps"]): + # Iterative training function - can be any arbitrary training procedure + intermediate_score = evaluation_fn(step, width, height) + # Feed the score back back to Tune. + tune.report( + iterations=step, + loss=intermediate_score, + gain=intermediate_score * width) + time.sleep(0.1) + + +def run_optuna_tune(smoke_test=False): + algo = OptunaSearch(metric=["loss", "gain"], mode=["min", "max"]) + algo = ConcurrencyLimiter(algo, max_concurrent=4) + analysis = tune.run( + easy_objective, + search_alg=algo, + num_samples=10 if smoke_test else 100, + config={ + "steps": 100, + "width": tune.uniform(0, 20), + "height": tune.uniform(-100, 100), + # This is an ignored parameter. + "activation": tune.choice(["relu", "tanh"]) + }) + + print("Best hyperparameters for loss found were: ", + analysis.get_best_config("loss", "min")) + print("Best hyperparameters for gain found were: ", + analysis.get_best_config("gain", "max")) + + +if __name__ == "__main__": + import argparse + + parser = argparse.ArgumentParser() + parser.add_argument( + "--smoke-test", action="store_true", help="Finish quickly for testing") + parser.add_argument( + "--server-address", + type=str, + default=None, + required=False, + help="The address of server to connect to if using " + "Ray Client.") + args, _ = parser.parse_known_args() + if args.server_address is not None: + ray.init(f"ray://{args.server_address}") + else: + ray.init(configure_logging=False) + + run_optuna_tune(smoke_test=args.smoke_test) diff --git a/python/ray/tune/suggest/optuna.py b/python/ray/tune/suggest/optuna.py index 21945a145d32..0e6089071b82 100644 --- a/python/ray/tune/suggest/optuna.py +++ b/python/ray/tune/suggest/optuna.py @@ -199,12 +199,9 @@ def define_search_space(trial: optuna.Trial): metric=["loss1", "loss2"], mode=["min", "max"]) - # The metric and mode specified here will be used for sorting - # trials, and not during search itself + # Do not specify metric and mode here! tune.run( trainable, - metric="loss1", - mode="min", search_alg=optuna_search ) @@ -297,24 +294,22 @@ def __init__(self, "You passed an initialized sampler to `OptunaSearch`. The " "`seed` parameter has to be passed to the sampler directly " "and will be ignored.") + elif sampler: + assert isinstance( + self._sampler, + BaseSampler), ("You can only pass an instance of " + "`optuna.samplers.BaseSampler` " + "as a sampler to `OptunaSearcher`.") - if sampler: - self._sampler = sampler - elif isinstance(mode, list): - self._sampler = ot.samplers.MOTPESampler(seed=seed) - else: - self._sampler = ot.samplers.TPESampler(seed=seed) - - assert isinstance(self._sampler, BaseSampler), \ - "You can only pass an instance of `optuna.samplers.BaseSampler` " \ - "as a sampler to `OptunaSearcher`." + self._sampler = sampler + self._seed = seed self._ot_trials = {} self._ot_study = None if self._space: self._setup_study(mode) - def _setup_study(self, mode: str): + def _setup_study(self, mode: Union[str, list]): if self._metric is None and self._mode: if isinstance(self._mode, list): raise ValueError( @@ -326,6 +321,13 @@ def _setup_study(self, mode: str): pruner = ot.pruners.NopPruner() storage = ot.storages.InMemoryStorage() + if self._sampler: + sampler = self._sampler + elif isinstance(mode, list): + sampler = ot.samplers.MOTPESampler(seed=self._seed) + else: + sampler = ot.samplers.TPESampler(seed=self._seed) + if isinstance(mode, list): study_direction_args = dict( directions=[ @@ -337,7 +339,7 @@ def _setup_study(self, mode: str): self._ot_study = ot.study.create_study( storage=storage, - sampler=self._sampler, + sampler=sampler, pruner=pruner, study_name=self._study_name, load_if_exists=True, From 0317304479eebc577665e0a5f6f904a05db10b06 Mon Sep 17 00:00:00 2001 From: Antoni Baum Date: Wed, 17 Nov 2021 21:05:24 +0000 Subject: [PATCH 4/5] Fix --- python/ray/tune/suggest/optuna.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/python/ray/tune/suggest/optuna.py b/python/ray/tune/suggest/optuna.py index 0e6089071b82..883e8e2e5cf3 100644 --- a/python/ray/tune/suggest/optuna.py +++ b/python/ray/tune/suggest/optuna.py @@ -3,7 +3,7 @@ import pickle import functools import warnings -from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Union +from typing import Any, Callable, Dict, List, Optional, Tuple, Union from ray.tune.result import DEFAULT_METRIC, TRAINING_ITERATION from ray.tune.sample import Categorical, Domain, Float, Integer, LogUniform, \ @@ -257,8 +257,7 @@ def __init__(self, Tuple], Callable[["OptunaTrial"], Optional[Dict[ str, Any]]]]] = None, metric: Optional[Union[str, List[str]]] = None, - mode: Optional[Union[Literal["min"], Literal["max"], List[ - Union[Literal["min"], Literal["max"]]]]] = None, + mode: Optional[Union[str, List[str]]] = None, points_to_evaluate: Optional[List[Dict]] = None, sampler: Optional["BaseSampler"] = None, seed: Optional[int] = None, From 4ef26b9b0bf374e524e3b3734547e295bc4d7ae2 Mon Sep 17 00:00:00 2001 From: Antoni Baum Date: Thu, 18 Nov 2021 15:15:20 +0000 Subject: [PATCH 5/5] Fix --- python/ray/tune/suggest/optuna.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/python/ray/tune/suggest/optuna.py b/python/ray/tune/suggest/optuna.py index 883e8e2e5cf3..73424cc9daf8 100644 --- a/python/ray/tune/suggest/optuna.py +++ b/python/ray/tune/suggest/optuna.py @@ -3,6 +3,7 @@ import pickle import functools import warnings +from packaging import version from typing import Any, Callable, Dict, List, Optional, Tuple, Union from ray.tune.result import DEFAULT_METRIC, TRAINING_ITERATION @@ -108,9 +109,9 @@ class OptunaSearch(Searcher): for future parameters. Needs to be a list of dicts containing the configurations. sampler (optuna.samplers.BaseSampler): Optuna sampler used to - draw hyperparameter configurations. Defaults to ``TPESampler`` - for single-objective optimization and ``MOTPESampler`` for - multi-objective optimization. + draw hyperparameter configurations. Defaults to ``MOTPESampler`` + for multi-objective optimization with Optuna<2.9.0, and + ``TPESampler`` in every other case. seed (int): Seed to initialize sampler with. This parameter is only used when ``sampler=None``. In all other cases, the sampler you pass should be initialized with the seed already. @@ -295,10 +296,9 @@ def __init__(self, "and will be ignored.") elif sampler: assert isinstance( - self._sampler, - BaseSampler), ("You can only pass an instance of " - "`optuna.samplers.BaseSampler` " - "as a sampler to `OptunaSearcher`.") + sampler, BaseSampler), ("You can only pass an instance of " + "`optuna.samplers.BaseSampler` " + "as a sampler to `OptunaSearcher`.") self._sampler = sampler self._seed = seed @@ -322,7 +322,9 @@ def _setup_study(self, mode: Union[str, list]): if self._sampler: sampler = self._sampler - elif isinstance(mode, list): + elif isinstance(mode, list) and version.parse( + ot.__version__) < version.parse("2.9.0"): + # MOTPESampler deprecated in Optuna>=2.9.0 sampler = ot.samplers.MOTPESampler(seed=self._seed) else: sampler = ot.samplers.TPESampler(seed=self._seed)