-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstat_tol_synthesis_cupy.py
75 lines (62 loc) · 1.87 KB
/
stat_tol_synthesis_cupy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import scipy.optimize
import cupy as cp
from tolerance_optimization.cupy_analysis import StatisticalToleranceSynthesis as StatisticalToleranceSynthesisCuPy
solver = StatisticalToleranceSynthesisCuPy
dev = cp.cuda.Device()
def callback(*args, **kwargs):
dev.synchronize()
print(args, kwargs)
floattype = cp.float32
def main():
mempool = cp.get_default_memory_pool()
mempool.get_limit()
opti_vector = [0.1, 0.2, 0.1, 0.2, 0.2, 0.1, 0.2]
mean = [7.5, 5.1, 17.5, 5.1, 5.05, 12.5, 5.1]
variable_costs = [1, 9, 5, 15, 2, 11, 18]
distributions = [1, 0, 1, 0, 1, 1, 0]
bounds = [(0, 0.7)] * len(opti_vector)
sample_size = [
10_000,
50_000,
100_000,
500_000,
1_000_000,
2_000_000,
4_000_000,
6_000_000,
8_000_000,
10_000_000,
]
number_of_runs = 10
for samplesize in sample_size:
for k in range(number_of_runs):
mempool.free_all_blocks()
c = solver(
sample_size=samplesize,
mean=mean,
fixed_costs=0,
variable_costs=variable_costs,
distributions=distributions,
usl=0.1,
float_type=floattype,
)
result = scipy.optimize.differential_evolution(
c.cost_function_tolerance_optimization,
bounds,
strategy="best1bin",
maxiter=100,
popsize=25,
tol=0.01,
mutation=(0.5, 1),
recombination=0.5,
seed=1992,
callback=callback,
disp=True,
polish=False,
init="latinhypercube",
updating="deferred",
atol=0,
workers=1,
)
if __name__ == "__main__":
main()