Fix exception in CFO's _create_condition if all candidate start points didn't return yet (#263)

* Fix exception if first trial returns None

* Add test
This commit is contained in:
Antoni Baum
2021-10-29 20:44:16 +02:00
committed by GitHub
parent 94a81a95ad
commit e0155c2339
2 changed files with 69 additions and 3 deletions

View File

@@ -0,0 +1,62 @@
import numpy as np
from flaml import tune
from flaml import BlendSearch, CFO
def _invalid_objective(config):
# DragonFly uses `point`
metric = "point" if "point" in config else "report"
if config[metric] > 4:
tune.report(float("inf"))
elif config[metric] > 3:
tune.report(float("-inf"))
elif config[metric] > 2:
tune.report(np.nan)
else:
tune.report(float(config[metric]) or 0.1)
config = {"report": tune.uniform(0.0, 5.0)}
def test_blendsearch():
out = tune.run(
_invalid_objective,
search_alg=BlendSearch(
points_to_evaluate=[
{"report": 1.0},
{"report": 2.1},
{"report": 3.1},
{"report": 4.1},
]
),
config=config,
metric="_metric",
mode="max",
num_samples=16,
)
best_trial = out.best_trial
assert best_trial.config["report"] <= 2.0
def test_cfo():
out = tune.run(
_invalid_objective,
search_alg=CFO(
points_to_evaluate=[
{"report": 1.0},
{"report": 2.1},
{"report": 3.1},
{"report": 4.1},
]
),
config=config,
metric="_metric",
mode="max",
num_samples=16,
)
best_trial = out.best_trial
assert best_trial.config["report"] <= 2.0