Пример #1
0
 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"})
Пример #2
0
 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']
Пример #3
0
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
Пример #4
0
 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']
Пример #5
0
    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
Пример #6
0
    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
Пример #7
0
 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_
     })
Пример #8
0
 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)
Пример #9
0
def test_label_share_dict_keys(data):
    l1 = Label('123', '456', 'abc')
    l2 = Label('123', '456', 'abc')
    d = {l1: None}
    assert l2 in d
Пример #10
0
 def command(self):
     json = request.get_json()
     json['label'] = Label(json['exp'], json['sha1'], json['name'])
     self.queue.put(json)
     return jsonify({"command": "success"})
Пример #11
0
 def get_config(self, exp, sha1, name):
     label = Label(exp, sha1, name)
     res = {"config": self.results.get_config(label)}
     return jsonify(res)
Пример #12
0
 def kill(self, exp, sha1, name):
     label = Label(exp, sha1, name)
     msg = {'command': 'kill', 'label': label}
     self.queue.put(msg)
     return jsonify({"command": "kill"})
Пример #13
0
 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)
Пример #14
0
 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))
Пример #15
0
 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)
Пример #16
0
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)
Пример #17
0
 def get_xpctl(self, exp, sha1, name):
     label = Label(exp, sha1, name)
     id_ = self.results.get_xpctl(label)
     return jsonify(dict(id=id_, **label))
Пример #18
0
 def get_label_prefix(self, label):
     resp = self.get("{url}/label/{name}".format(url=self.url, name=label))
     return resp['name'], Label(**resp)
Пример #19
0
 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
Пример #20
0
 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)
Пример #21
0
def test_label_not_equal(data):
    l1 = Label('123', '456', 'abc')
    l2 = Label('123', '456', 'def')
    assert not l1 is l2
    assert l1 != l2