[tune] Fix up examples (#9201)

This commit is contained in:
Richard Liaw
2020-07-05 01:16:20 -07:00
committed by GitHub
parent f7ac495a68
commit b71c912da7
22 changed files with 380 additions and 243 deletions
+8 -10
View File
@@ -6,16 +6,16 @@ from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import time
import ray
from ray.tune import run
from ray import tune
from ray.tune.schedulers import AsyncHyperBandScheduler
from ray.tune.suggest.dragonfly import DragonflySearch
def objective(config, reporter):
import numpy as np
import time
time.sleep(0.2)
def objective(config):
for i in range(config["iterations"]):
vol1 = config["point"][0] # LiNO3
vol2 = config["point"][1] # Li2SO4
@@ -25,7 +25,7 @@ def objective(config, reporter):
conductivity = vol1 + 0.1 * (vol2 + vol3)**2 + 2.3 * vol4 * (vol1**1.5)
# Add Gaussian noise to simulate experimental noise
conductivity += np.random.normal() * 0.01
reporter(timesteps_total=i, objective=conductivity)
tune.report(timesteps_total=i, objective=conductivity)
time.sleep(0.02)
@@ -46,9 +46,6 @@ if __name__ == "__main__":
"config": {
"iterations": 100,
},
"stop": {
"timesteps_total": 100
},
}
domain_vars = [{
@@ -75,7 +72,8 @@ if __name__ == "__main__":
optimizer = EuclideanGPBandit(func_caller, ask_tell_mode=True)
algo = DragonflySearch(optimizer, metric="objective", mode="max")
scheduler = AsyncHyperBandScheduler(metric="objective", mode="max")
run(objective,
tune.run(
objective,
name="dragonfly_search",
search_alg=algo,
scheduler=scheduler,