MCPcopy
hub / github.com/hyperopt/hyperopt / _expr_to_config

Function _expr_to_config

hyperopt/pyll_utils.py:157–183  ·  view source on GitHub ↗
(expr, conditions, hps)

Source from the content-addressed store, hash-verified

155
156
157def _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
186def expr_to_config(expr, conditions, hps):

Callers 1

expr_to_configFunction · 0.85

Calls 2

DuplicateLabelClass · 0.85
inputsMethod · 0.80

Tested by

no test coverage detected