(expr, conditions, hps)
| 155 | |
| 156 | |
| 157 | def _expr_to_config(expr, conditions, hps): |
| 158 | if expr.name == "switch": |
| 159 | idx = expr.inputs()[0] |
| 160 | options = expr.inputs()[1:] |
| 161 | assert idx.name == "hyperopt_param" |
| 162 | assert idx.arg["obj"].name in ( |
| 163 | "randint", # -- in case of hp.choice |
| 164 | "categorical", # -- in case of hp.pchoice |
| 165 | ) |
| 166 | _expr_to_config(idx, conditions, hps) |
| 167 | for ii, opt in enumerate(options): |
| 168 | _expr_to_config(opt, conditions + (EQ(idx.arg["label"].obj, ii),), hps) |
| 169 | elif expr.name == "hyperopt_param": |
| 170 | label = expr.arg["label"].obj |
| 171 | if label in hps: |
| 172 | if hps[label]["node"] != expr.arg["obj"]: |
| 173 | raise DuplicateLabel(label) |
| 174 | hps[label]["conditions"].add(conditions) |
| 175 | else: |
| 176 | hps[label] = { |
| 177 | "node": expr.arg["obj"], |
| 178 | "conditions": {conditions}, |
| 179 | "label": label, |
| 180 | } |
| 181 | else: |
| 182 | for ii in expr.inputs(): |
| 183 | _expr_to_config(ii, conditions, hps) |
| 184 | |
| 185 | |
| 186 | def expr_to_config(expr, conditions, hps): |
no test coverage detected