1
|
|
|
import os |
2
|
|
|
import numpy as np |
3
|
|
|
import pandas as pd |
4
|
|
|
from hyperactive import Hyperactive |
5
|
|
|
from hyperactive.dashboards import ProgressBoard |
6
|
|
|
from hyperactive.dashboards.progress_board.streamlit_backend import StreamlitBackend |
7
|
|
|
from hyperactive.dashboards.progress_board.progress_io import ProgressIO |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
def test_progress_io_0(): |
11
|
|
|
search_id = "test_model" |
12
|
|
|
|
13
|
|
|
_io_ = ProgressIO("./") |
14
|
|
|
_io_.get_filter_file_path(search_id) |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
def test_progress_io_1(): |
18
|
|
|
search_id = "test_model" |
19
|
|
|
|
20
|
|
|
_io_ = ProgressIO("./") |
21
|
|
|
_io_.get_progress_data_path(search_id) |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
def test_progress_io_2(): |
25
|
|
|
search_id = "test_model" |
26
|
|
|
|
27
|
|
|
_io_ = ProgressIO("./") |
28
|
|
|
_io_.remove_filter(search_id) |
29
|
|
|
filter_ = _io_.load_filter(search_id) |
30
|
|
|
|
31
|
|
|
assert filter_ is None |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
def test_progress_io_3(): |
35
|
|
|
search_id = "test_model" |
36
|
|
|
|
37
|
|
|
_io_ = ProgressIO("./") |
38
|
|
|
_io_.remove_progress(search_id) |
39
|
|
|
progress_ = _io_.load_progress(search_id) |
40
|
|
|
|
41
|
|
|
assert progress_ is None |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
def test_progress_io_4(): |
45
|
|
|
search_id = "test_model" |
46
|
|
|
|
47
|
|
|
search_space = { |
48
|
|
|
"x1": np.arange(-100, 101, 1), |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
_io_ = ProgressIO("./") |
52
|
|
|
_io_.remove_progress(search_id) |
53
|
|
|
_io_.create_filter(search_id, search_space) |
54
|
|
|
|
55
|
|
|
progress_ = _io_.load_filter(search_id) |
56
|
|
|
|
57
|
|
|
assert progress_ is not None |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
def test_progress_board_0(): |
61
|
|
|
search_id = "test_model" |
62
|
|
|
|
63
|
|
|
search_space = { |
64
|
|
|
"x1": np.arange(-100, 101, 1), |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
board = ProgressBoard() |
68
|
|
|
board.init_paths(search_id=search_id, search_space=search_space) |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
def test_streamlit_backend_0(): |
72
|
|
|
search_id1 = "test_model1" |
73
|
|
|
search_id2 = "test_model2" |
74
|
|
|
search_id3 = "test_model3" |
75
|
|
|
|
76
|
|
|
search_ids = [search_id1, search_id2, search_id3] |
77
|
|
|
|
78
|
|
|
board = StreamlitBackend(search_ids) |
79
|
|
|
progress_data = board.get_progress_data(search_id1) |
80
|
|
|
|
81
|
|
|
assert progress_data is None |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
def test_filter_data_0(): |
85
|
|
|
search_id1 = "test_model1" |
86
|
|
|
search_id2 = "test_model2" |
87
|
|
|
search_id3 = "test_model3" |
88
|
|
|
search_ids = [search_id1, search_id2, search_id3] |
89
|
|
|
|
90
|
|
|
def objective_function(opt): |
91
|
|
|
score = -opt["x1"] * opt["x1"] |
92
|
|
|
return score |
93
|
|
|
|
94
|
|
|
search_space = { |
95
|
|
|
"x1": np.arange(-100, 101, 1), |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
hyper = Hyperactive() |
99
|
|
|
hyper.add_search(objective_function, search_space, n_iter=200) |
100
|
|
|
hyper.run() |
101
|
|
|
search_data = hyper.results(objective_function) |
102
|
|
|
|
103
|
|
|
indices = list(search_space.keys()) + ["score"] |
104
|
|
|
filter_dict = { |
105
|
|
|
"parameter": indices, |
106
|
|
|
"lower bound": "lower", |
107
|
|
|
"upper bound": "upper", |
108
|
|
|
} |
109
|
|
|
filter_df = pd.DataFrame(filter_dict) |
110
|
|
|
threshold = -1000 |
111
|
|
|
filter_df.iloc[1, 1] = threshold |
112
|
|
|
|
113
|
|
|
board = StreamlitBackend(search_ids) |
114
|
|
|
progress_data = board.filter_data(search_data, filter_df) |
115
|
|
|
|
116
|
|
|
assert not np.all(search_data["score"].values >= threshold) |
117
|
|
|
assert np.all(progress_data["score"].values >= threshold) |
118
|
|
|
|