()
| 7 | |
| 8 | |
| 9 | def test_run_basic_search(): |
| 10 | def objective(args): |
| 11 | case, val = args |
| 12 | if case == "case 1": |
| 13 | return val |
| 14 | else: |
| 15 | return val ** 2 |
| 16 | |
| 17 | # define a search space |
| 18 | space = hp.choice( |
| 19 | "a", |
| 20 | [ |
| 21 | ("case 1", 1 + hp.lognormal("c1", 0, 1)), |
| 22 | ("case 2", hp.uniform("c2", -10, 10)), |
| 23 | ], |
| 24 | ) |
| 25 | |
| 26 | # minimize the objective over the space |
| 27 | # NOTE: Max evals should be greater than 10, as the first 10 runs are only the initialization rounds |
| 28 | best = fmin( |
| 29 | objective, |
| 30 | space, |
| 31 | algo=atpe.suggest, |
| 32 | max_evals=20, |
| 33 | rstate=np.random.default_rng(1), |
| 34 | ) |
| 35 | |
| 36 | assert best["a"] == 1 |
| 37 | assert space_eval(space, best)[0] == "case 2" |
nothing calls this directly
no test coverage detected