Passed
Push — master ( 23d304...5d9e6c )
by Simon
01:08
created

ProgressBarLVL0._tqdm_dict()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 4
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
import numpy as np
6
from tqdm.auto import tqdm
7
8
9
class ProgressBarLVL0:
10
    def __init__(self):
11
        pass
12
13
    def update(self, iter, score_new):
14
        pass
15
16
    def close(self):
17
        pass
18
19
    def _tqdm_dict(self, nth_process, n_iter, obj_func):
20
        pass
21
22
23
class ProgressBarLVL1:
24
    def __init__(self, nth_process, n_iter, obj_func):
25
        self.best_since_iter = 0
26
        self.score_best = -np.inf
27
        # tqdm.set_lock(tqdm.get_lock())
28
29
        self._tqdm = tqdm(**self._tqdm_dict(nth_process, n_iter, obj_func))
30
31
    def update(self, iter, score_new):
32
        self._tqdm.update(iter)
33
34
        if score_new > self.score_best:
35
            self.score_best = score_new
36
            self.best_since_iter = self._tqdm.n
37
            self._tqdm.set_postfix(
38
                best_score=str(score_new), best_since_iter=self.best_since_iter
39
            )
40
41
    def close(self):
42
        self._tqdm.close()
43
44
    def _tqdm_dict(self, nth_process, n_iter, obj_func):
45
        """Generates the parameter dict for tqdm in the iteration-loop of each optimizer"""
46
        return {
47
            "total": n_iter,
48
            "desc": "Process " + str(nth_process) + " -> " + obj_func.__name__,
49
            "position": nth_process,
50
            "leave": True,
51
        }
52
53