-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsolver.py
More file actions
71 lines (54 loc) · 3.06 KB
/
solver.py
File metadata and controls
71 lines (54 loc) · 3.06 KB
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
import numpy as np
from math import floor
from scipy.optimize import minimize, NonlinearConstraint, Bounds
from constraints import calculate_mem_constraint, calculate_speed_constraint, calculate_capacity_constraint, calculate_wait_constraint, calculate_speed_constants
class InfrascaleSolver:
"""Solveur du problème d'optimisation d'Infrascale avec [l'implémentation scipy de l'algorithme de Nelder-Mead](https://docs.scipy.org/doc/scipy/tutorial/optimize.html).
L'algorithme est théoriquement sensible aux conditions initiales mais du fait de la forme de la fonction objectif
(produit de fonctions monotones croissantes sur R+) on s'attend à ce qu'il converge systématiquement vers
la solution optimale.
Paramètres:
- logger: logger
- **kwargs: paramètres du problème
"""
def __init__(self, logger, **kwargs):
self.params = kwargs
self.logger = logger
def _objective_function(self, x):
S, N, B, Q = x
return S * N
def _constraints_function(self, x, **kwargs):
S, N, B, Q = x
kwargs['batch_size'] = 2**B
return calculate_mem_constraint(S, **kwargs), \
calculate_speed_constraint(S, N, B, Q, **kwargs), \
calculate_capacity_constraint(N, B, Q, **kwargs), \
calculate_wait_constraint(Q, B, **kwargs)
def solve(self):
"""Résolution du problème d'optimisation d'Infrascale. Voir [l'implémentation scipy de l'algorithme de Nelder-Mead](https://docs.scipy.org/doc/scipy/tutorial/optimize.html).
Args:
**params: Paramètres du problème
Returns:
dict: Résultats de la résolution
"""
params = self.params
constraints = NonlinearConstraint(lambda x: self._constraints_function(x, **params), lb=-np.inf, ub=[0, 0, 0, 0])
bounds = Bounds([1, 1, 1, 0.1], [np.inf, np.inf, 9, np.inf]) # On pose max(B) = 9 car 2^9 = 512 et plus serait irréaliste
intermediate_results = minimize(self._objective_function, x0=[1, 1, 1, 1], bounds=bounds, constraints=constraints)
S, N, B, Q = intermediate_results.x
# On veut un nombre entier pour B donc une fois qu'on a une solution, on borne B à l'entier inférieur
bounds = Bounds([1, 1, 1, 0.1], [np.inf, np.inf, floor(B), np.inf])
return minimize(self._objective_function, x0=[1, 1, 1, 1], bounds=bounds, constraints=constraints)
def get_metrics(self, S, N):
throughput_per_gpu = calculate_speed_constants(7, **self.params)[0]
throughput_per_node = throughput_per_gpu * (1 + self.params['efficiency_factor'] * (S - 1))
throughput_total = throughput_per_node * N
throughput_per_user = throughput_total / self.params['users']
tpot = 1 / throughput_per_node
return {
'throughput_per_gpu': throughput_per_gpu,
'throughput_per_node': throughput_per_node,
'throughput_total': throughput_total,
'throughput_per_user': throughput_per_user,
'tpot': tpot
}