def suggest_multiple_from_name(dbname, host, port, bandit_algo_names, bandit_names, exp_keys, N, bandit_args_list, bandit_kwargs_list, bandit_algo_args_list, bandit_algo_kwargs_list, mql=1, refresh=False): port = int(port) trials = MongoTrials('mongo://%s:%d/%s/jobs' % (host, port, dbname), refresh=False) algos = [] for bn, ban, ba, bk, baa, bak, ek in zip(bandit_names, bandit_algo_names, bandit_args_list, bandit_kwargs_list, bandit_algo_args_list, bandit_algo_kwargs_list, exp_keys): bandit = json_call(bn, ba, bk) subtrials = MongoTrials('mongo://%s:%d/%s/jobs' % (host, port, dbname), refresh=False, exp_key=ek) if ba or bk: subtrials.attachments['bandit_data_' + ek] = cPickle.dumps((bn, ba, bk)) bak['cmd'] = ('driver_attachment', 'bandit_data_' + ek) else: bak['cmd'] = ('bandit_json evaluate', bn) algo = json_call(ban, (bandit,) + baa, bak) algos.append(algo) algo = InterleaveAlgo(algos, exp_keys) exp = hyperopt.Experiment(trials, algo, poll_interval_secs=.1) exp.max_queue_len = mql if N is not None: exp.run(N, block_until_done=True) else: return exp
def test_mongo_exp_is_picklable(): algo_jsons = [] algo_jsons.append('hyperopt.bandit_algos.Random') algo_jsons.append('hyperopt.theano_gp.HGP') algo_jsons.append('hyperopt.theano_gm.AdaptiveParzenGM') for algo_json in algo_jsons: with TempMongo() as tm: # this triggers if an old stale mongo is running assert len(TempMongo.mongo_jobs('foodb')) == 0 print 'pickling MongoExperiment with', algo_json bandit = json_call('hyperopt.bandits.GaussWave2') bandit_algo = json_call(algo_json, args=(bandit,)) exp = MongoExperiment( bandit_algo=bandit_algo, mongo_handle=tm.mongo_jobs('foodb'), workdir=tm.workdir, exp_key='exp_key', poll_interval_secs=1.0, cmd=('asdf', None)) exp_str = cPickle.dumps(exp) cpy = cPickle.loads(exp_str)
def test_mongo_exp_with_threads(): def worker(host_id, n_jobs, timeout): mw = MongoWorker( mj=TempMongo.mongo_jobs('foodb'), ) t0 = time.time() while n_jobs: mw.run_one(host_id, timeout) print 'worker: ran job' n_jobs -= 1 for bandit_json in ('hyperopt.bandits.GaussWave2', 'hyperopt.dbn.Dummy_DBN_Base',): with TempMongo() as tm: assert len(TempMongo.mongo_jobs('foodb')) == 0 bandit = json_call(bandit_json) exp = MongoExperiment( bandit_algo=HGP(bandit), mongo_handle=tm.mongo_jobs('foodb'), workdir=tm.workdir, exp_key='exp_key', poll_interval_secs=1.0, cmd=('bandit_json evaluate', bandit_json)) exp.ddoc_init() assert len(TempMongo.mongo_jobs('foodb')) == 0 for asdf in exp.mongo_handle: print asdf assert len(exp.mongo_handle) == 0 n_trials = 5 exp.bandit_algo.n_startup_jobs = 3 wthread = threading.Thread(target=worker, args=(('hostname', 0), n_trials, 660.0)) wthread.start() try: print 'running experiment' exp.run(n_trials, block_until_done=True) finally: print 'joining worker thread...' wthread.join() print exp.trials print exp.results assert len(exp.trials) == n_trials assert len(exp.results) == n_trials exp_str = cPickle.dumps(exp)