mirror of
https://github.com/wassname/ray.git
synced 2026-07-14 11:17:54 +08:00
[tune] nevergrad add points_to_evaluate (#12207)
This commit is contained in:
@@ -567,6 +567,49 @@ class SearchSpaceTest(unittest.TestCase):
|
||||
self.assertTrue(5 <= config["a"] <= 6)
|
||||
self.assertTrue(8 <= config["b"] <= 9)
|
||||
|
||||
def testNevergradBestParams(self):
|
||||
from ray.tune.suggest.nevergrad import NevergradSearch
|
||||
import nevergrad as ng
|
||||
|
||||
config = {
|
||||
"metric": tune.sample.Categorical([1, 2, 3, 4]).uniform(),
|
||||
"a": tune.sample.Categorical(["t1", "t2", "t3", "t4"]).uniform(),
|
||||
"b": tune.sample.Integer(0, 5),
|
||||
"c": tune.sample.Float(1e-4, 1e-1).loguniform()
|
||||
}
|
||||
|
||||
best_params = [{
|
||||
"metric": 1,
|
||||
"a": "t1",
|
||||
"b": 1,
|
||||
"c": 1e-1
|
||||
}, {
|
||||
"metric": 2,
|
||||
"a": "t2",
|
||||
"b": 2,
|
||||
"c": 1e-2
|
||||
}]
|
||||
|
||||
searcher = NevergradSearch(
|
||||
optimizer=ng.optimizers.OnePlusOne, points_to_evaluate=best_params)
|
||||
analysis = tune.run(
|
||||
_mock_objective,
|
||||
config=config,
|
||||
metric="metric",
|
||||
mode="max",
|
||||
search_alg=searcher,
|
||||
num_samples=5)
|
||||
|
||||
for i in range(len(best_params)):
|
||||
trial_config = analysis.trials[i].config
|
||||
trial_config_dict = {
|
||||
"metric": trial_config["metric"],
|
||||
"a": trial_config["a"],
|
||||
"b": trial_config["b"],
|
||||
"c": trial_config["c"]
|
||||
}
|
||||
self.assertDictEqual(trial_config_dict, best_params[i])
|
||||
|
||||
def testConvertOptuna(self):
|
||||
from ray.tune.suggest.optuna import OptunaSearch, param
|
||||
from optuna.samplers import RandomSampler
|
||||
|
||||
Reference in New Issue
Block a user