()
| 125 | |
| 126 | |
| 127 | def test_vectorize_config0(): |
| 128 | p0 = hp_uniform("p0", 0, 1) |
| 129 | p1 = hp_loguniform("p1", 2, 3) |
| 130 | p2 = hp_choice("p2", [-1, p0]) |
| 131 | p3 = hp_choice("p3", [-2, p1]) |
| 132 | p4 = 1 |
| 133 | p5 = [3, 4, p0] |
| 134 | p6 = hp_choice("p6", [-3, p1]) |
| 135 | d = locals() |
| 136 | d["p1"] = None # -- don't sample p1 all the time, only if p3 says so |
| 137 | config = as_apply(d) |
| 138 | |
| 139 | N = as_apply("N:TBA") |
| 140 | expr = config |
| 141 | expr_idxs = scope.range(N) |
| 142 | vh = VectorizeHelper(expr, expr_idxs, build=True) |
| 143 | vconfig = vh.v_expr |
| 144 | |
| 145 | full_output = as_apply([vconfig, vh.idxs_by_label(), vh.vals_by_label()]) |
| 146 | |
| 147 | if 1: |
| 148 | print("=" * 80) |
| 149 | print("VECTORIZED") |
| 150 | print(full_output) |
| 151 | print("\n" * 1) |
| 152 | |
| 153 | fo2 = replace_repeat_stochastic(full_output) |
| 154 | if 0: |
| 155 | print("=" * 80) |
| 156 | print("VECTORIZED STOCHASTIC") |
| 157 | print(fo2) |
| 158 | print("\n" * 1) |
| 159 | |
| 160 | new_vc = recursive_set_rng_kwarg(fo2, as_apply(np.random.default_rng(1))) |
| 161 | if 0: |
| 162 | print("=" * 80) |
| 163 | print("VECTORIZED STOCHASTIC WITH RNGS") |
| 164 | print(new_vc) |
| 165 | |
| 166 | Nval = 10 |
| 167 | foo, idxs, vals = rec_eval(new_vc, memo={N: Nval}) |
| 168 | |
| 169 | print("foo[0]", foo[0]) |
| 170 | print("foo[1]", foo[1]) |
| 171 | assert len(foo) == Nval |
| 172 | if 0: # XXX refresh these values to lock down sampler |
| 173 | assert foo[0] == { |
| 174 | "p0": 0.39676747423066994, |
| 175 | "p1": None, |
| 176 | "p2": 0.39676747423066994, |
| 177 | "p3": 2.1281244479293568, |
| 178 | "p4": 1, |
| 179 | "p5": (3, 4, 0.39676747423066994), |
| 180 | } |
| 181 | assert (foo[1].keys() != foo[2].keys()) or (foo[1].values() != foo[2].values()) |
| 182 | |
| 183 | print(idxs) |
| 184 | print(vals["p3"]) |
nothing calls this directly
no test coverage detected