in example_opt_root/opentuner_optimizer.py [0:0]
def build_manipulator(api_config):
"""Build a ConfigurationManipulator object to be used by opentuner.
Parameters
----------
api_config : dict-like of dict-like
Configuration of the optimization variables. See API description.
Returns
-------
manipulator : ConfigurationManipulator
Some over complexified class required by opentuner to run.
"""
manipulator = ConfigurationManipulator()
for pname in api_config:
ptype = api_config[pname]["type"]
pspace = api_config[pname].get("space", None)
pmin, pmax = api_config[pname].get("range", (None, None))
if ptype == "real":
if pspace in ("linear", "logit"):
ot_param = FloatParameter(pname, pmin, pmax)
elif pspace in ("log", "bilog"):
LogFloatParameter_ = ClippedParam(LogFloatParameter)
ot_param = LogFloatParameter_(pname, pmin, pmax)
else:
assert False, "unsupported param space = %s" % pspace
elif ptype == "int":
if pspace in ("linear", "logit"):
ot_param = IntegerParameter(pname, pmin, pmax)
elif pspace in ("log", "bilog"):
ot_param = LogIntegerParameter(pname, pmin, pmax)
else:
assert False, "unsupported param space = %s" % pspace
elif ptype == "bool":
# The actual bool parameter seems not to work in Py3 :(
ot_param = IntegerParameter(pname, 0, 1)
elif ptype in ("cat", "ordinal"):
# Treat ordinal and categorical variables the same for now.
assert "values" in api_config[pname]
pvalues = api_config[pname]["values"]
ot_param = EnumParameter(pname, pvalues)
else:
assert False, "type=%s/space=%s not handled in opentuner yet" % (ptype, pspace)
manipulator.add_parameter(ot_param)
return manipulator