Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make options and expt_dir args to main.main #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

craffel
Copy link

@craffel craffel commented Jul 3, 2015

Hi, I'd like to propose that instead of calling get_options in main.main to retrieve options and expt_dir, they are instead passed as arguments to main.main. As it currently is, the only way to run a Spearmint experiment is to run python main.py. With this change, that option is still available, but it will also be possible to run main.main from within a Python script - something like the following:

import spearmint.main
import os
import numpy as np

def branin(x, y):
    result = np.square(y - (5.1/(4*np.square(np.pi)))*np.square(x) +
         (5/np.pi)*x - 6) + 10*(1-(1./(8*np.pi)))*np.cos(x) + 10
    result = float(result)
    print 'Result = %f' % result
    return result

def main(job_id, params):
    return branin(params['x'], params['y'])

options = {'language' : 'PYTHON',
           'main-file' : os.path.basename(__file__),
           'experiment-name' : 'noconfig',
           'likelihood' : 'NOISELESS',
           'variables' : {"x" : {"type" : "FLOAT",
                                 "size" : 1,
                                 "min"  : -5,
                                 "max"  : 10},
                          "y" : {"type" : "FLOAT",
                                 "size" : 1,
                                 "min"  : 0,
                                 "max"  : 15}}}

if __name__ == '__main__':
    spearmint.main.main(options, os.getcwd())

Note that this consolidates the main.py file and the experiment file, makes the 'main-file' option resilient to filename changes, and also obviates the need for a config file - we can just turn the config into a dict in the experiment file. And, again, it doesn't change the existing behavior. If there's something fundamental I'm missing here which suggests this is a bad idea, please correct me, but otherwise I think this small change would substantially clean up many use-cases! Thanks.

@jan-glx
Copy link

jan-glx commented Aug 27, 2015

I like this a lot. But just encountered a problem which I could solve by renaming my script with the nice name "main.py" to something else. Could be that that problem existed before however. best, Jan

  File "c:\[...]\spearmint\main.py", line 233, in main
    options['chooser']  = options.get('chooser', 'default_chooser')
AttributeError: 'int' object has no attribute 'get'

@craffel
Copy link
Author

craffel commented Aug 27, 2015

Hm, I would assume this was there before; apparently main is getting passed an int instead of a dict. Can you post your full code example and the full traceback?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants