|
1
|
|
|
import numpy as np |
|
2
|
|
|
from tqdm import tqdm |
|
3
|
|
|
from hyperactive import Hyperactive |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
def objective_function(opt): |
|
7
|
|
|
score = -opt["x1"] * opt["x1"] |
|
8
|
|
|
return score |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
search_space = { |
|
12
|
|
|
"x1": np.arange(-100, 101, 1), |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
def test_n_jobs_0(): |
|
17
|
|
|
hyper = Hyperactive() |
|
18
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=2) |
|
19
|
|
|
hyper.run() |
|
20
|
|
|
|
|
21
|
|
|
assert len(hyper.results_list) == 2 |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
def test_n_jobs_1(): |
|
25
|
|
|
hyper = Hyperactive() |
|
26
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=4) |
|
27
|
|
|
hyper.run() |
|
28
|
|
|
|
|
29
|
|
|
assert len(hyper.results_list) == 4 |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
def test_n_jobs_2(): |
|
33
|
|
|
hyper = Hyperactive() |
|
34
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=8) |
|
35
|
|
|
hyper.run() |
|
36
|
|
|
|
|
37
|
|
|
assert len(hyper.results_list) == 8 |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
def test_n_jobs_3(): |
|
41
|
|
|
hyper = Hyperactive() |
|
42
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15) |
|
43
|
|
|
hyper.run() |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
def test_n_jobs_4(): |
|
47
|
|
|
hyper = Hyperactive() |
|
48
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=100) |
|
49
|
|
|
hyper.run() |
|
50
|
|
|
|
|
51
|
|
|
assert len(hyper.results_list) == 100 |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
def test_n_jobs_5(): |
|
55
|
|
|
hyper = Hyperactive() |
|
56
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=2) |
|
57
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=2) |
|
58
|
|
|
|
|
59
|
|
|
hyper.run() |
|
60
|
|
|
|
|
61
|
|
|
assert len(hyper.results_list) == 4 |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
def test_n_jobs_6(): |
|
65
|
|
|
hyper = Hyperactive() |
|
66
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=2) |
|
67
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=2) |
|
68
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=2) |
|
69
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=2) |
|
70
|
|
|
|
|
71
|
|
|
hyper.run() |
|
72
|
|
|
|
|
73
|
|
|
assert len(hyper.results_list) == 8 |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
def test_multiprocessing_0(): |
|
77
|
|
|
hyper = Hyperactive(distribution="multiprocessing") |
|
78
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=2) |
|
79
|
|
|
hyper.run() |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
def test_multiprocessing_1(): |
|
83
|
|
|
hyper = Hyperactive( |
|
84
|
|
|
distribution={ |
|
85
|
|
|
"multiprocessing": { |
|
86
|
|
|
"initializer": tqdm.set_lock, |
|
87
|
|
|
"initargs": (tqdm.get_lock(),), |
|
88
|
|
|
} |
|
89
|
|
|
}, |
|
90
|
|
|
) |
|
91
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=2) |
|
92
|
|
|
hyper.run() |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
def test_joblib_0(): |
|
96
|
|
|
hyper = Hyperactive(distribution="joblib") |
|
97
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=2) |
|
98
|
|
|
hyper.run() |
|
99
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
def test_joblib_1(): |
|
102
|
|
|
from joblib import Parallel, delayed |
|
103
|
|
|
|
|
104
|
|
|
def joblib_wrapper(process_func, search_processes_paras, n_jobs, **kwargs): |
|
105
|
|
|
n_jobs = len(search_processes_paras) |
|
106
|
|
|
|
|
107
|
|
|
jobs = [ |
|
108
|
|
|
delayed(process_func)(**info_dict) for info_dict in search_processes_paras |
|
109
|
|
|
] |
|
110
|
|
|
results = Parallel(n_jobs=n_jobs, **kwargs)(jobs) |
|
111
|
|
|
|
|
112
|
|
|
return results |
|
113
|
|
|
|
|
114
|
|
|
hyper = Hyperactive(distribution=joblib_wrapper) |
|
115
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=2) |
|
116
|
|
|
|
|
117
|
|
|
hyper.run() |
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
def test_n_processes_0(): |
|
121
|
|
|
hyper = Hyperactive(n_processes=1) |
|
122
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=2) |
|
123
|
|
|
hyper.run() |
|
124
|
|
|
|
|
125
|
|
|
assert len(hyper.results_list) == 2 |
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
def test_n_processes_1(): |
|
129
|
|
|
hyper = Hyperactive(n_processes=2) |
|
130
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=2) |
|
131
|
|
|
hyper.run() |
|
132
|
|
|
|
|
133
|
|
|
assert len(hyper.results_list) == 2 |
|
134
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
def test_n_processes_2(): |
|
137
|
|
|
hyper = Hyperactive(n_processes=4) |
|
138
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=2) |
|
139
|
|
|
hyper.run() |
|
140
|
|
|
|
|
141
|
|
|
assert len(hyper.results_list) == 2 |
|
142
|
|
|
|
|
143
|
|
|
|
|
144
|
|
|
def test_n_processes_3(): |
|
145
|
|
|
hyper = Hyperactive(n_processes=4) |
|
146
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=3) |
|
147
|
|
|
hyper.run() |
|
148
|
|
|
|
|
149
|
|
|
assert len(hyper.results_list) == 3 |
|
150
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
def test_n_processes_4(): |
|
153
|
|
|
hyper = Hyperactive(n_processes=-1) |
|
154
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=4) |
|
155
|
|
|
hyper.run() |
|
156
|
|
|
|
|
157
|
|
|
assert len(hyper.results_list) == 4 |
|
158
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
def test_n_processes_5(): |
|
161
|
|
|
hyper = Hyperactive(n_processes=-1) |
|
162
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=4) |
|
163
|
|
|
hyper.add_search(objective_function, search_space, n_iter=15, n_jobs=4) |
|
164
|
|
|
hyper.run() |
|
165
|
|
|
|
|
166
|
|
|
assert len(hyper.results_list) == 8 |