Total Complexity | 10 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # Author: Simon Blanke |
||
2 | # Email: [email protected] |
||
3 | # License: MIT License |
||
4 | |||
5 | from tqdm.auto import tqdm |
||
6 | |||
7 | |||
8 | class ProgressBar: |
||
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 ProgressBarLVL0(ProgressBar): |
||
20 | def __init__(self): |
||
21 | self.best_since_iter = 0 |
||
22 | |||
23 | def init_p_bar(self, _cand_, _core_): |
||
24 | self.p_bar = tqdm(**self._tqdm_dict(_cand_, _core_)) |
||
25 | |||
26 | def update_p_bar(self, n, _cand_): |
||
27 | self.p_bar.update(n) |
||
28 | |||
29 | def close_p_bar(self): |
||
30 | self.p_bar.close() |
||
31 | |||
32 | def _tqdm_dict(self, _cand_, _core_): |
||
33 | """Generates the parameter dict for tqdm in the iteration-loop of each optimizer""" |
||
34 | return { |
||
35 | "total": _core_.n_iter, |
||
36 | "desc": "Thread " |
||
37 | + str(_cand_.nth_process) |
||
38 | + " -> " |
||
39 | + _cand_._model_.func_.__name__, |
||
40 | "position": _cand_.nth_process, |
||
41 | "leave": True, |
||
42 | } |
||
43 | |||
44 | |||
45 | class ProgressBarLVL1(ProgressBarLVL0): |
||
46 | def __init__(self): |
||
47 | self.best_since_iter = 0 |
||
48 | |||
49 | def update_p_bar(self, n, _cand_): |
||
50 | self.p_bar.update(n) |
||
51 | self.p_bar.set_postfix( |
||
52 | best_score=str(_cand_.score_best), best_since_iter=self.best_since_iter |
||
53 | ) |
||
54 |