autogen/test/tune/test_constraints.py
Chi Wang 569908fbe6
fix issues in logging, bug in space.py, constraint sign, and improve code coverage (#388)
* console log handler

* version update

* doc

* skippable steps

* notebook update

* constraint sign

* doc for constraints

* bug fix: define-by-run and unflatten_hierarchical

* const

* handle nested space in indexof()

* test grid search

* test suggestion

* model test

* >1 ckpts

* always increase iter count

* log total # iterations

* security patch

* make iter_per_learner consistent
2022-01-14 13:39:09 -08:00

26 lines
701 B
Python

def test_config_constraint():
from flaml import tune
# Test dict return value
def evaluate_config_dict(config):
metric = (round(config["x"]) - 85000) ** 2 - config["x"] / config["y"]
return {"metric": metric}
def config_constraint(config):
if config["y"] >= config["x"]:
return 1
else:
return 0
tune.run(
evaluate_config_dict,
config={
"x": tune.qloguniform(lower=1, upper=100000, q=1),
"y": tune.qrandint(lower=2, upper=100000, q=2),
},
config_constraints=[(config_constraint, ">", 0.5)],
metric="metric",
mode="max",
num_samples=100,
)