def serial_evaluate(self, N=-1): for trial in self.trials._dynamic_trials: if trial['state'] == base.JOB_STATE_NEW: trial['state'] = base.JOB_STATE_RUNNING now = coarse_utcnow() trial['book_time'] = now trial['refresh_time'] = now spec = base.spec_from_misc(trial['misc']) ctrl = base.Ctrl(self.trials, current_trial=trial) try: result = self.domain.evaluate(spec, ctrl) except Exception as e: logger.info('job exception: %s' % str(e)) trial['state'] = base.JOB_STATE_ERROR trial['misc']['error'] = (str(type(e)), str(e)) trial['refresh_time'] = coarse_utcnow() if not self.catch_eval_exceptions: # -- JOB_STATE_ERROR means this trial # will be removed from self.trials.trials # by this refresh call. self.trials.refresh() raise else: trial['state'] = base.JOB_STATE_DONE trial['result'] = result trial['refresh_time'] = coarse_utcnow() N -= 1 if N == 0: break self.trials.refresh()
def examples_to_trials(examples, params): """Create hyperopt trials from the given examples.""" trials = [] NA = object() # used to mark missing values for tid, ex in enumerate(examples): _coconut_match_to_0 = ex _coconut_match_check_0 = False _coconut_match_set_name_gain = _coconut_sentinel if _coconut.isinstance(_coconut_match_to_0, _coconut.abc.Mapping): _coconut_match_temp_4 = _coconut_match_to_0.get("gain", _coconut_sentinel) if _coconut_match_temp_4 is not _coconut_sentinel: _coconut_match_set_name_gain = _coconut_match_temp_4 _coconut_match_check_0 = True if _coconut_match_check_0: if _coconut_match_set_name_gain is not _coconut_sentinel: gain = _coconut_match_set_name_gain if _coconut_match_check_0: loss = negate_objective(gain) else: loss = ex["loss"] result = {"status": STATUS_OK, "loss": loss} vals = {} idxs = {} for k, v in get_names_and_features(ex["values"], params, fallback_func=lambda name, func, *args, **kwargs: NA, converters={"choice": lambda val, choices: choices.index(val), "randrange": lambda val, start, stop, step: val - start}, convert_fallback=False): vals[k] = [v,] if v is not NA else [] idxs[k] = [tid,] if v is not NA else [] misc = {"tid": tid, "idxs": idxs, "vals": vals, "cmd": None} trials.append({"tid": tid, "result": result, "misc": misc, "spec": spec_from_misc(misc), "state": JOB_STATE_DONE, "owner": None, "book_time": None, "refresh_time": None, "exp_key": None}) return trials
def fmin(self, fn, space, algo, max_evals, random_state=0, verbose=0, ): lb_view = self._client.load_balanced_view() random_state = check_random_state(random_state) domain = Domain(fn, space, rseed=int(random_state.randint(2^20))) while len(self.trials) < max_evals: if lb_view.queue_status()['unassigned']: sleep(1e-3) continue self.refresh() if verbose: print 'fmin : %4i/%4i/%4i/%4i %f' % ( self.count_by_state_unsynced(JOB_STATE_NEW), self.count_by_state_unsynced(JOB_STATE_RUNNING), self.count_by_state_unsynced(JOB_STATE_DONE), self.count_by_state_unsynced(JOB_STATE_ERROR), min([float('inf')] + [l for l in self.losses() if l is not None]) ) new_ids = self.new_trial_ids(1) new_trials = algo(new_ids, domain, self) if new_trials is StopExperiment: stopped = True break elif len(new_trials) == 0: break else: assert len(new_trials) == 1 task = lb_view.apply_async( call_domain, domain, spec_from_misc(new_trials[0]['misc']), ) # -- XXX bypassing checks because 'ar' # is not ok for SONify... but should check # for all else being SONify tid, = self.insert_trial_docs(new_trials) assert self._dynamic_trials[-1]['tid'] == tid self._dynamic_trials[-1]['ar'] = task
def _get_spec_from_trial(trial): return base.spec_from_misc(trial["misc"])
def _get_spec_from_trial(trial): return base.spec_from_misc(trial['misc'])