-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcommon.py
More file actions
119 lines (93 loc) · 3.29 KB
/
Copy pathcommon.py
File metadata and controls
119 lines (93 loc) · 3.29 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import pathlib
import time
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from deephyper.hpo import CBO
from ackley import hp_problem
NUM_WORKERS = 5
SEARCH_TIMEOUT = 20
RUN_SLEEP = 1
def execute_search(evaluator):
t = time.time()
init_duration = t - evaluator.timestamp
evaluator.timestamp = t
search = CBO(
hp_problem, evaluator, surrogate_model="DUMMY", filter_duplicated=False
)
results = search.search(timeout=SEARCH_TIMEOUT)
results.to_csv("results.csv")
return init_duration
def get_profile_from_hist(hist):
n_processes = 0
profile_dict = dict(t=[0], n_processes=[0])
for e in sorted(hist):
t, incr = e
n_processes += incr
profile_dict["t"].append(t)
profile_dict["n_processes"].append(n_processes)
profile = pd.DataFrame(profile_dict)
return profile
def get_perc_util(profile):
csum = 0
for i in range(len(profile) - 1):
csum += (profile.loc[i + 1, "t"] - profile.loc[i, "t"]) * profile.loc[
i, "n_processes"
]
perc_util = csum / (profile["t"].iloc[-1] * 6)
return perc_util
def plot_profile(ax, profile, ylabel="None", color="blue"):
ax.step(profile["t"], profile["n_processes"], where="post", color=color)
ax.set_ylabel(ylabel)
ax.set_ylim(0, NUM_WORKERS + 1)
ax.yaxis.set_major_locator(ticker.MultipleLocator(1))
ax.grid()
def plot_sum_up(name, init_duration):
pathlib.Path("plots").mkdir(parents=False, exist_ok=True)
results = pd.read_csv("results.csv")
# compute profiles from results.csv
jobs_hist = []
runs_hist = []
for _, row in results.iterrows():
jobs_hist.append((row["timestamp_submit"], 1))
jobs_hist.append((row["timestamp_gather"], -1))
runs_hist.append((row["timestamp_start"], 1))
runs_hist.append((row["timestamp_end"], -1))
jobs_profile = get_profile_from_hist(jobs_hist)
runs_profile = get_profile_from_hist(runs_hist)
# compute average job and run durations
job_avrg_duration = (
results["timestamp_gather"] - results["timestamp_submit"]
).mean()
# compute perc_util
jobs_perc_util = get_perc_util(jobs_profile)
runs_perc_util = get_perc_util(runs_profile)
# compute total number of evaluations
total_num_eval = len(results)
# plot
fig, axs = plt.subplots(2, sharex=True)
fig.suptitle(name, fontsize=17)
plot_profile(axs[0], jobs_profile, ylabel="# jobs submitted", color="blue")
plot_profile(axs[1], runs_profile, ylabel="# jobs running", color="crimson")
fig.text(0.1, -0.1, f"init_duration: {init_duration:.2f}s.", fontsize=12)
fig.text(0.1, -0.2, f"job_avrg_duration: {job_avrg_duration:.2f}s.", fontsize=12)
fig.text(0.1, -0.3, f"total_num_eval: {total_num_eval}", fontsize=12)
fig.text(
0.6,
-0.1,
f"jobs_perc_util: {100*jobs_perc_util:.1f}%",
fontsize=12,
color="blue",
)
fig.text(
0.6,
-0.2,
f"runs_perc_util: {100*runs_perc_util:.1f}%",
fontsize=12,
color="crimson",
)
fig.tight_layout()
plt.savefig(f"plots/{name}.jpg", bbox_inches="tight")
def evaluate_and_plot(evaluator, name):
init_duration = execute_search(evaluator)
plot_sum_up(name, init_duration)