MCPcopy Index your code
hub / github.com/hyperopt/hyperopt / IPythonTrials

Class IPythonTrials

hyperopt/ipy.py:31–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29
30
31class IPythonTrials(Trials):
32 def __init__(self, client, job_error_reaction="raise", save_ipy_metadata=True):
33 self._client = client
34 self._clientlbv = client.load_balanced_view()
35 self.job_map = {}
36 self.job_error_reaction = job_error_reaction
37 self.save_ipy_metadata = save_ipy_metadata
38 Trials.__init__(self)
39 self._testing_fmin_was_called = False
40
41 def _insert_trial_docs(self, docs):
42 rval = [doc["tid"] for doc in docs]
43 self._dynamic_trials.extend(docs)
44 return rval
45
46 def refresh(self):
47 job_map = {}
48
49 # -- carry over state for active engines
50 for eid in self._client.ids:
51 job_map[eid] = self.job_map.pop(eid, (None, None))
52
53 # -- deal with lost engines, abandoned promises
54 for eid, (p, tt) in list(self.job_map.items()):
55 if self.job_error_reaction == "raise":
56 raise LostEngineError(p)
57 elif self.job_error_reaction == "log":
58 tt["error"] = "LostEngineError (%s)" % str(p)
59 tt["state"] = JOB_STATE_ERROR
60 else:
61 raise ValueError(self.job_error_reaction)
62
63 # -- remove completed jobs from job_map
64 for eid, (p, tt) in list(job_map.items()):
65 if p is None:
66 continue
67 if p.ready():
68 try:
69 tt["result"] = p.get()
70 tt["state"] = JOB_STATE_DONE
71 job_map[eid] = (None, None)
72 except Exception as e:
73 if self.job_error_reaction == "raise":
74 raise
75 elif self.job_error_reaction == "log":
76 tt["error"] = str(e)
77 tt["state"] = JOB_STATE_ERROR
78 else:
79 raise ValueError(self.job_error_reaction)
80 if self.save_ipy_metadata:
81 tt["ipy_metadata"] = p.metadata
82 tt["refresh_time"] = coarse_utcnow()
83 del job_map[eid]
84
85 self.job_map = job_map
86 Trials.refresh(self)
87
88 def fmin(self, fn, space, **kw):

Callers 2

test0Function · 0.90
test_fmin_fnFunction · 0.90

Calls

no outgoing calls

Tested by 2

test0Function · 0.72
test_fmin_fnFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…