automl / labwatch

An extension to Sacred for automated hyperparameter optimization.
59 stars 19 forks source link

Argument error in ConfigSpace when using SMAC optimizer #10

Closed fortuin closed 6 years ago

fortuin commented 6 years ago

I am trying to use the SMAC optimizer in the simple branin example script:

#!/usr/bin/env python
# coding=utf-8
from __future__ import division, print_function, unicode_literals

from sacred import Experiment
from labwatch.assistant import LabAssistant
from labwatch.hyperparameters import UniformFloat
from labwatch.optimizers.smac_wrapper import SMAC
import numpy as np

ex = Experiment()
a = LabAssistant(ex, "test", optimizer=SMAC)

@ex.config
def cfg():
    x = (0., 5.)

@a.search_space
def search_space():
    x = (UniformFloat(-5, 10), UniformFloat(0, 15))

@ex.automain
def branin(x):
    x1, x2 = x
    print("{:.2f}, {:.2f}".format(x1, x2))
    y = (x2 - (5.1 / (4 * np.pi ** 2)) * x1 ** 2 + 5 * x1 / np.pi - 6) ** 2
    y += 10 * (1 - 1 / (8 * np.pi)) * np.cos(x1) + 10

    return y

I get the following error:

Traceback (most recent call last):
  File "labwatch_test.py", line 26, in <module>
    @ex.automain
  File "/cluster/home/miniconda3/envs/lib/python3.5/site-packages/sacred/experiment.py", line 132, in automain
    self.run_commandline()
  File "/cluster/home/miniconda3/envs/lib/python3.5/site-packages/sacred/experiment.py", line 250, in run_commandline
    return self.run(cmd_name, config_updates, named_configs, {}, args)
  File "/cluster/home/miniconda3/envs/lib/python3.5/site-packages/sacred/experiment.py", line 198, in run
    meta_info, options)
  File "/cluster/home/miniconda3/envs/lib/python3.5/site-packages/sacred/experiment.py", line 423, in _create_run
    force=options.get(ForceOption.get_flag(), False))
  File "/cluster/home/miniconda3/envs/lib/python3.5/site-packages/sacred/initialize.py", line 332, in create_run
    ncfg_updates = scaff.run_named_config(cfg_name)
  File "/cluster/home/miniconda3/envs/lib/python3.5/site-packages/sacred/initialize.py", line 93, in run_named_config
    fallback=self.fallback)
  File "/cluster/home/miniconda3/envs/lib/python3.5/site-packages/labwatch/assistant.py", line 190, in _search_space_wrapper
    self.optimizer = self.optimizer_class(self.current_search_space)
  File "/cluster/home/miniconda3/envs/lib/python3.5/site-packages/labwatch/optimizers/smac_wrapper.py", line 71, in __init__
    super(SMAC, self).__init__(sacred_space_to_configspace(config_space))
  File "/cluster/home/miniconda3/envs/lib/python3.5/site-packages/labwatch/converters/convert_to_configspace.py", line 110, in sacred_space_to_configspace
    converted_param = convert_simple_param(name, param)
  File "/cluster/home/miniconda3/envs/lib/python3.5/site-packages/labwatch/converters/convert_to_configspace.py", line 56, in convert_simple_param
    log=param["log_scale"])
  File "ConfigSpace/hyperparameters.pyx", line 331, in ConfigSpace.hyperparameters.UniformFloatHyperparameter.__init__
TypeError: __init__() got an unexpected keyword argument 'default'

From looking at the code I believe that the ConfigSpace package expects the keyword argument to be called "default_value" instead of "default". Is this a problem of version compatibility? Are there any versions which work well together without being deprecated?

fortuin commented 6 years ago

The same thing happens with the BayesianOptimizer.