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_filter_data_0(): |
61
|
|
|
search_id1 = "test_model1" |
62
|
|
|
search_id2 = "test_model2" |
63
|
|
|
search_id3 = "test_model3" |
64
|
|
|
search_ids = [search_id1, search_id2, search_id3] |
65
|
|
|
|
66
|
|
|
def objective_function(opt): |
67
|
|
|
score = -opt["x1"] * opt["x1"] |
68
|
|
|
return score |
69
|
|
|
|
70
|
|
|
search_space = { |
71
|
|
|
"x1": np.arange(-100, 101, 1), |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
hyper = Hyperactive() |
75
|
|
|
hyper.add_search(objective_function, search_space, n_iter=200) |
76
|
|
|
hyper.run() |
77
|
|
|
search_data = hyper.results(objective_function) |
78
|
|
|
|
79
|
|
|
indices = list(search_space.keys()) + ["score"] |
80
|
|
|
filter_dict = { |
81
|
|
|
"parameter": indices, |
82
|
|
|
"lower bound": "---", |
83
|
|
|
"upper bound": "---", |
84
|
|
|
} |
85
|
|
|
filter_df = pd.DataFrame(filter_dict) |
86
|
|
|
threshold = -1000 |
87
|
|
|
filter_df["lower bound"].iloc[1] = threshold |
88
|
|
|
|
89
|
|
|
board = StreamlitBackend(search_ids) |
90
|
|
|
progress_data = board.filter_data(search_data, filter_df) |
91
|
|
|
|
92
|
|
|
assert not np.all(search_data["score"].values >= threshold) |
93
|
|
|
assert np.all(progress_data["score"].values >= threshold) |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
def test_streamlit_backend_0(): |
97
|
|
|
search_id1 = "test_model1" |
98
|
|
|
search_id2 = "test_model2" |
99
|
|
|
search_id3 = "test_model3" |
100
|
|
|
|
101
|
|
|
search_ids = [search_id1, search_id2, search_id3] |
102
|
|
|
|
103
|
|
|
board = StreamlitBackend(search_ids) |
104
|
|
|
progress_data = board.get_progress_data(search_id1) |
105
|
|
|
|
106
|
|
|
assert progress_data is None |
107
|
|
|
|
108
|
|
|
|
109
|
|
View Code Duplication |
def test_streamlit_backend_1(): |
|
|
|
|
110
|
|
|
search_id1 = "test_model1" |
111
|
|
|
search_id2 = "test_model2" |
112
|
|
|
search_id3 = "test_model3" |
113
|
|
|
|
114
|
|
|
search_ids = [search_id1, search_id2, search_id3] |
115
|
|
|
|
116
|
|
|
board = StreamlitBackend(search_ids) |
117
|
|
|
|
118
|
|
|
def objective_function(opt): |
119
|
|
|
score = -opt["x1"] * opt["x1"] |
120
|
|
|
return score |
121
|
|
|
|
122
|
|
|
search_space = { |
123
|
|
|
"x1": np.arange(-100, 101, 1), |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
hyper = Hyperactive() |
127
|
|
|
hyper.add_search(objective_function, search_space, n_iter=200) |
128
|
|
|
hyper.run() |
129
|
|
|
search_data = hyper.results(objective_function) |
130
|
|
|
search_data["nth_iter"] = 0 |
131
|
|
|
search_data["score_best"] = 0 |
132
|
|
|
search_data["nth_process"] = 0 |
133
|
|
|
|
134
|
|
|
pyplot_fig = board.pyplot(search_data) |
135
|
|
|
|
136
|
|
|
assert pyplot_fig is not None |
137
|
|
|
|
138
|
|
|
|
139
|
|
View Code Duplication |
def test_streamlit_backend_2(): |
|
|
|
|
140
|
|
|
search_id1 = "test_model1" |
141
|
|
|
search_id2 = "test_model2" |
142
|
|
|
search_id3 = "test_model3" |
143
|
|
|
|
144
|
|
|
search_ids = [search_id1, search_id2, search_id3] |
145
|
|
|
|
146
|
|
|
board = StreamlitBackend(search_ids) |
147
|
|
|
|
148
|
|
|
def objective_function(opt): |
149
|
|
|
score = -opt["x1"] * opt["x1"] |
150
|
|
|
return score |
151
|
|
|
|
152
|
|
|
search_space = { |
153
|
|
|
"x1": np.arange(-100, 101, 1), |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
hyper = Hyperactive() |
157
|
|
|
hyper.add_search(objective_function, search_space, n_iter=200) |
158
|
|
|
hyper.run() |
159
|
|
|
search_data = hyper.results(objective_function) |
160
|
|
|
search_data["nth_iter"] = 0 |
161
|
|
|
search_data["score_best"] = 0 |
162
|
|
|
search_data["nth_process"] = 0 |
163
|
|
|
|
164
|
|
|
plotly_fig = board.plotly(search_data, search_id1) |
165
|
|
|
|
166
|
|
|
assert plotly_fig is not None |
167
|
|
|
|
168
|
|
|
|
169
|
|
|
def test_streamlit_backend_3(): |
170
|
|
|
search_id1 = "test_model1" |
171
|
|
|
search_id2 = "test_model2" |
172
|
|
|
search_id3 = "test_model3" |
173
|
|
|
|
174
|
|
|
search_ids = [search_id1, search_id2, search_id3] |
175
|
|
|
|
176
|
|
|
board = StreamlitBackend(search_ids) |
177
|
|
|
|
178
|
|
|
df_empty = pd.DataFrame() |
179
|
|
|
|
180
|
|
|
board.pyplot(df_empty) |
181
|
|
|
|
182
|
|
|
|
183
|
|
|
def test_streamlit_backend_4(): |
184
|
|
|
search_id1 = "test_model1" |
185
|
|
|
search_id2 = "test_model2" |
186
|
|
|
search_id3 = "test_model3" |
187
|
|
|
|
188
|
|
|
search_ids = [search_id1, search_id2, search_id3] |
189
|
|
|
|
190
|
|
|
board = StreamlitBackend(search_ids) |
191
|
|
|
|
192
|
|
|
df_empty = pd.DataFrame([], columns=["nth_iter", "score_best", "nth_process"]) |
193
|
|
|
|
194
|
|
|
board.pyplot(df_empty) |
195
|
|
|
|
196
|
|
|
|
197
|
|
|
def test_streamlit_backend_3(): |
198
|
|
|
search_id1 = "test_model1" |
199
|
|
|
search_id2 = "test_model2" |
200
|
|
|
search_id3 = "test_model3" |
201
|
|
|
|
202
|
|
|
search_ids = [search_id1, search_id2, search_id3] |
203
|
|
|
|
204
|
|
|
board = StreamlitBackend(search_ids) |
205
|
|
|
|
206
|
|
|
df_empty = pd.DataFrame() |
207
|
|
|
|
208
|
|
|
board.plotly(df_empty, search_id1) |
209
|
|
|
|
210
|
|
|
|
211
|
|
|
def test_streamlit_backend_4(): |
212
|
|
|
search_id1 = "test_model1" |
213
|
|
|
search_id2 = "test_model2" |
214
|
|
|
search_id3 = "test_model3" |
215
|
|
|
|
216
|
|
|
search_ids = [search_id1, search_id2, search_id3] |
217
|
|
|
|
218
|
|
|
board = StreamlitBackend(search_ids) |
219
|
|
|
|
220
|
|
|
df_empty = pd.DataFrame([], columns=["nth_iter", "score_best", "nth_process"]) |
221
|
|
|
|
222
|
|
|
board.plotly(df_empty, search_id1) |
223
|
|
|
|