def launch(self): # TODO: Comment on what should be in json to launch json = request.get_json() json['label'] = Label(json['exp'], json['sha1'], json['name']) json['command'] = 'launch' self.queue.put(json) return jsonify({"command": "launch"})
def get_best_per_label(self, exp, phase, metric): resp = self.get( "{url}/results/best/{exp}/{phase}/{metric}".format( url=self.url, exp=exp, phase=phase, metric=metric ) ) labels = [Label(e, s, n) for e, s, n in zip(resp['exps'], resp['sha1s'], resp['names'])] return labels, resp['values'], resp['steps']
def test_label_unpacking(): exp = str(random.randint(1000, 9000)) sha1 = str(random.randint(1000, 9000)) name = str(random.randint(1000, 9000)) gold = {'exp': exp, 'sha1': sha1, 'name': name} label = Label(exp, sha1, name) res = dict(**label) assert res == gold
def find_best(self, exp, phase, metric): resp = self.get( "{url}/result/best/{exp}/{phase}/{metric}".format( url = self.url, exp=exp, phase=phase, metric=metric ) ) label = Label(resp['exp'], resp['sha1'], resp['name']) if resp['exp'] is not None else None return label, resp['value'], resp['tick']
def get(self): """Get logs. Returns: Tuple[id, data] if data is available, else None, None """ try: data = self.q.get(timeout=self.timeout) except Empty: data = None if data is not None: label = Label.parse(data['label']) return label, data['msg'] return None, None
def sample(self): """Replace values with the sampled ones. :returns: tuple, (hpctl.utils.Label dict): [0]: The label [3]: The config. """ s = deepcopy(self.config) for sampler in self.samplers.values(): sampled = sampler.sample() for k, v in sampled.items(): tmp = s for x in k[:-1]: tmp = tmp[x] tmp[k[-1]] = v hashed = hash_config(s) label = Label(self.exp, hashed, random_name()) return label, s
def put_result(self, exp, sha1, name): label = Label(exp, sha1, name) if self.xpctl is None: return jsonify({ "command": "putresults", "status": "failed", "id": "FAILED" }) if not self.results.get_xpctl(label): id_ = self.xpctl.put_result(label) self.results.set_xpctl(label, id_) id_ = str(id_) else: id_ = self.results.get_xpctl(label) return jsonify({ "command": "putresults", "status": "success", "id": id_ })
def recent_result(self, exp, sha1, name, phase, metric): label = Label(exp, sha1, name) val = self.results.get_recent(label, phase, metric) res = dict(phase=phase, metric=metric, value=val, **label) return jsonify(res)
def test_label_share_dict_keys(data): l1 = Label('123', '456', 'abc') l2 = Label('123', '456', 'abc') d = {l1: None} assert l2 in d
def command(self): json = request.get_json() json['label'] = Label(json['exp'], json['sha1'], json['name']) self.queue.put(json) return jsonify({"command": "success"})
def get_config(self, exp, sha1, name): label = Label(exp, sha1, name) res = {"config": self.results.get_config(label)} return jsonify(res)
def kill(self, exp, sha1, name): label = Label(exp, sha1, name) msg = {'command': 'kill', 'label': label} self.queue.put(msg) return jsonify({"command": "kill"})
def find_best_across(self, exp, phase, metric): label, val, idx = self.results.find_best(exp, phase, metric) if label is None: label = Label(None, None, None) res = dict(phase=phase, metric=metric, value=val, tick=idx, **label) return jsonify(res)
def get_metrics(self, exp, sha1, name, phase): label = Label(exp, sha1, name) metrics = self.results.get_metrics(label, phase) return jsonify(dict(phase=phase, metrics=metrics, **label))
def best_result(self, exp, sha1, name, phase, metric): label = Label(exp, sha1, name) val, idx = self.results.get_best(label, phase, metric) res = dict(phase=phase, metric=metric, value=val, tick=idx, **label) return jsonify(res)
def test_label_same_hash(data): l1 = Label('123', '456', 'abc') l2 = Label('123', '456', 'abc') assert not l1 is l2 assert hash(l1) == hash(l2)
def get_xpctl(self, exp, sha1, name): label = Label(exp, sha1, name) id_ = self.results.get_xpctl(label) return jsonify(dict(id=id_, **label))
def get_label_prefix(self, label): resp = self.get("{url}/label/{name}".format(url=self.url, name=label)) return resp['name'], Label(**resp)
def get_labels(self, exp_hash): resp = self.get("{url}/labels/{exp}".format(url=self.url, exp=exp_hash)) labels = [] for res in resp: labels.append(Label(exp_hash, res['sha1'], res['name'])) return labels
def get_state(self, exp, sha1, name): label = Label(exp, sha1, name) state = self.results.get_state(label) state = str(state).decode('utf-8') if six.PY2 else str(state) res = dict(state=state, **label) return jsonify(res)
def test_label_not_equal(data): l1 = Label('123', '456', 'abc') l2 = Label('123', '456', 'def') assert not l1 is l2 assert l1 != l2