Passed
Push — master ( 1a4396...e9038c )
by Simon
01:47
created

hyperactive.verb.Verbosity.init_p_bar()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nop 3
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
from tqdm.auto import tqdm
6
7
8
class Verbosity:
9
    def init_p_bar(self, _cand_, _core_):
10
        pass
11
12
    def update_p_bar(self, n, _cand_):
13
        pass
14
15
    def close_p_bar(self):
16
        pass
17
18
19
class VerbosityLVL0(Verbosity):
20
    def __init__(self):
21
        pass
22
23
    def print_start_point(self, _cand_):
24
        return _cand_._get_warm_start()
25
26
27
class VerbosityLVL1(VerbosityLVL0):
28
    def __init__(self):
29
        pass
30
31
    def print_start_point(self, _cand_):
32
        start_point = _cand_._get_warm_start()
33
        print("best para =", start_point)
34
        print("score     =", _cand_.score_best, "\n")
35
36
        return start_point
37
38
39
class VerbosityLVL2(VerbosityLVL1):
40
    def __init__(self):
41
        self.best_since_iter = 0
42
43
    def init_p_bar(self, _cand_, _core_):
44
        self.p_bar = tqdm(**self._tqdm_dict(_cand_, _core_))
45
46
    def update_p_bar(self, n, _cand_):
47
        self.p_bar.update(n)
48
49
    def close_p_bar(self):
50
        self.p_bar.close()
51
52
    def _tqdm_dict(self, _cand_, _core_):
53
        """Generates the parameter dict for tqdm in the iteration-loop of each optimizer"""
54
        return {
55
            "total": _core_.n_iter,
56
            "desc": "Thread "
57
            + str(_cand_.nth_process)
58
            + " -> "
59
            + _cand_._model_.func_.__name__,
60
            "position": _cand_.nth_process,
61
            "leave": True,
62
        }
63
64
65
class VerbosityLVL3(VerbosityLVL2):
66
    def __init__(self):
67
        self.best_since_iter = 0
68
69
    def update_p_bar(self, n, _cand_):
70
        self.p_bar.update(n)
71
        self.p_bar.set_postfix(
72
            best_score=str(_cand_.score_best), best_since_iter=self.best_since_iter
73
        )
74