()
| 10 | |
| 11 | |
| 12 | def test_expr_to_config(): |
| 13 | z = hp.randint("z", 10) |
| 14 | a = hp.choice( |
| 15 | "a", |
| 16 | [ |
| 17 | hp.uniform("b", -1, 1) + z, |
| 18 | { |
| 19 | "c": 1, |
| 20 | "d": hp.choice( |
| 21 | "d", [3 + hp.loguniform("c", 0, 1), 1 + hp.loguniform("e", 0, 1)] |
| 22 | ), |
| 23 | }, |
| 24 | ], |
| 25 | ) |
| 26 | |
| 27 | expr = as_apply((a, z)) |
| 28 | |
| 29 | hps = {} |
| 30 | expr_to_config(expr, (True,), hps) |
| 31 | |
| 32 | for label, dct in list(hps.items()): |
| 33 | print(label) |
| 34 | print( |
| 35 | " dist: %s(%s)" |
| 36 | % ( |
| 37 | dct["node"].name, |
| 38 | ", ".join(map(str, [ii.eval() for ii in dct["node"].inputs()])), |
| 39 | ) |
| 40 | ) |
| 41 | if len(dct["conditions"]) > 1: |
| 42 | print(" conditions (OR):") |
| 43 | for condseq in dct["conditions"]: |
| 44 | print(" ", " AND ".join(map(str, condseq))) |
| 45 | elif dct["conditions"]: |
| 46 | for condseq in dct["conditions"]: |
| 47 | print(" conditions :", " AND ".join(map(str, condseq))) |
| 48 | |
| 49 | assert hps["a"]["node"].name == "randint" |
| 50 | assert hps["b"]["node"].name == "uniform" |
| 51 | assert hps["c"]["node"].name == "loguniform" |
| 52 | assert hps["d"]["node"].name == "randint" |
| 53 | assert hps["e"]["node"].name == "loguniform" |
| 54 | assert hps["z"]["node"].name == "randint" |
| 55 | |
| 56 | assert {(True, EQ("a", 0))} == {(True, EQ("a", 0))} |
| 57 | assert hps["a"]["conditions"] == {(True,)} |
| 58 | assert hps["b"]["conditions"] == {(True, EQ("a", 0))}, hps["b"]["conditions"] |
| 59 | assert hps["c"]["conditions"] == {(True, EQ("a", 1), EQ("d", 0))} |
| 60 | assert hps["d"]["conditions"] == {(True, EQ("a", 1))} |
| 61 | assert hps["e"]["conditions"] == {(True, EQ("a", 1), EQ("d", 1))} |
| 62 | assert hps["z"]["conditions"] == {(True,), (True, EQ("a", 0))} |
| 63 | |
| 64 | |
| 65 | def test_remove_allpaths(): |
nothing calls this directly
no test coverage detected