Passed
Push — master ( e1930b...2ca354 )
by Simon
01:19
created

hyperactive.verb.VerbosityLVL3.__init__()   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 1
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__(self):
10
        pass
11
12
    def init_p_bar(self, _cand_, _core_):
13
        pass
14
15
    def update_p_bar(self, n, _cand_):
16
        pass
17
18
    def close_p_bar(self):
19
        pass
20
21
22
class VerbosityLVL0(Verbosity):
23
    def __init__(self):
24
        pass
25
26
    def print_start_point(self, _cand_):
27
        return _cand_._get_warm_start()
28
29
30
class VerbosityLVL1(VerbosityLVL0):
31
    def __init__(self):
32
        pass
33
34
    def print_start_point(self, _cand_):
35
        start_point = _cand_._get_warm_start()
36
        print("best para =", start_point)
37
        print("score     =", _cand_.score_best, "\n")
38
39
        return start_point
40
41
42
class VerbosityLVL2(VerbosityLVL1):
43
    def __init__(self):
44
        self.best_since_iter = 0
45
46
    def init_p_bar(self, _cand_, _core_):
47
        self.p_bar = tqdm(**self._tqdm_dict(_cand_, _core_))
48
49
    def update_p_bar(self, n, _cand_):
50
        self.p_bar.update(n)
51
52
    def close_p_bar(self):
53
        self.p_bar.close()
54
55
    def _tqdm_dict(self, _cand_, _core_):
56
        """Generates the parameter dict for tqdm in the iteration-loop of each optimizer"""
57
        return {
58
            "total": _core_.n_iter,
59
            "desc": "Thread "
60
            + str(_cand_.nth_process)
61
            + " -> "
62
            + _cand_._model_.func_.__name__,
63
            "position": _cand_.nth_process,
64
            "leave": True,
65
        }
66
67
68
class VerbosityLVL3(VerbosityLVL2):
69
    def __init__(self):
70
        self.best_since_iter = 0
71
72
    def update_p_bar(self, n, _cand_):
73
        self.p_bar.update(n)
74
        self.p_bar.set_postfix(
75
            best_score=str(_cand_.score_best), best_since_iter=self.best_since_iter
76
        )
77