Passed
Push — master ( e635ae...dcb08f )
by Simon
02:09 queued 10s
created

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