mirror of
https://github.com/wassname/ray.git
synced 2026-07-09 10:37:48 +08:00
ea5a6f8455
Uses `tune.run` to execute experiments as preferred API. @noahgolmant This does not break backwards compat, but will slowly internalize `Experiment`. In a separate PR, Tune schedulers should only support 1 running experiment at a time.
61 lines
1.5 KiB
Python
61 lines
1.5 KiB
Python
"""This test checks that BayesOpt is functional.
|
|
|
|
It also checks that it is usable with a separate scheduler.
|
|
"""
|
|
from __future__ import absolute_import
|
|
from __future__ import division
|
|
from __future__ import print_function
|
|
|
|
import ray
|
|
from ray.tune import run
|
|
from ray.tune.schedulers import AsyncHyperBandScheduler
|
|
from ray.tune.suggest import BayesOptSearch
|
|
|
|
|
|
def easy_objective(config, reporter):
|
|
import time
|
|
time.sleep(0.2)
|
|
for i in range(config["iterations"]):
|
|
reporter(
|
|
timesteps_total=i,
|
|
neg_mean_loss=-(config["height"] - 14)**2 +
|
|
abs(config["width"] - 3))
|
|
time.sleep(0.02)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument(
|
|
"--smoke-test", action="store_true", help="Finish quickly for testing")
|
|
args, _ = parser.parse_known_args()
|
|
ray.init()
|
|
|
|
space = {'width': (0, 20), 'height': (-100, 100)}
|
|
|
|
config = {
|
|
"num_samples": 10 if args.smoke_test else 1000,
|
|
"config": {
|
|
"iterations": 100,
|
|
},
|
|
"stop": {
|
|
"timesteps_total": 100
|
|
}
|
|
}
|
|
algo = BayesOptSearch(
|
|
space,
|
|
max_concurrent=4,
|
|
reward_attr="neg_mean_loss",
|
|
utility_kwargs={
|
|
"kind": "ucb",
|
|
"kappa": 2.5,
|
|
"xi": 0.0
|
|
})
|
|
scheduler = AsyncHyperBandScheduler(reward_attr="neg_mean_loss")
|
|
run(easy_objective,
|
|
name="my_exp",
|
|
search_alg=algo,
|
|
scheduler=scheduler,
|
|
**config)
|