def test_clone_merge_no_merge_literals(): a, b, c = as_apply((2, 3, 2)) d = (a + b) * (c + b) len_d = len(dfs(d)) e = clone_merge(d, merge_literals=False) assert len_d == len(dfs(d)) assert len_d == len(dfs(e)) assert e.eval() == d.eval()
def _validate_space_exhaustive_search(space): from hyperopt.pyll.base import dfs, as_apply from hyperopt.pyll.stochastic import implicit_stochastic_symbols supported_stochastic_symbols = ['randint', 'quniform', 'qloguniform', 'qnormal', 'qlognormal', 'categorical'] for node in dfs(as_apply(space)): if node.name in implicit_stochastic_symbols: if node.name not in supported_stochastic_symbols: raise ExhaustiveSearchError( 'Exhaustive search is only possible with the following stochastic symbols: ' '' + ', '.join(supported_stochastic_symbols) )
def test_dfs(): dd = as_apply({"c": 11, "d": 12}) d = {"a": 9, "b": dd, "y": dd, "z": dd + 1} ad = as_apply(d) order = dfs(ad) print([str(o) for o in order]) assert order[0]._obj == 9 assert order[1]._obj == 11 assert order[2]._obj == 12 assert order[3].named_args[0][0] == "c" assert order[4]._obj == 1 assert order[5].name == "add" assert order[6].named_args[0][0] == "a" assert len(order) == 7
def test_dfs(): dd = as_apply({'c': 11, 'd': 12}) d = {'a': 9, 'b': dd, 'y': dd, 'z': dd + 1} ad = as_apply(d) order = dfs(ad) print([str(o) for o in order]) assert order[0]._obj == 9 assert order[1]._obj == 11 assert order[2]._obj == 12 assert order[3].named_args[0][0] == 'c' assert order[4]._obj == 1 assert order[5].name == 'add' assert order[6].named_args[0][0] == 'a' assert len(order) == 7