-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_performance_profiles.py
More file actions
164 lines (107 loc) · 3.59 KB
/
plot_performance_profiles.py
File metadata and controls
164 lines (107 loc) · 3.59 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import math
PROBLEMS = [
"group_lasso",
"huber",
"portfolio",
"multiperiod_portfolio",
"tv_denoising",
]
SOLVED_STRINGS = ["QOCO_SOLVED", "SOLVED", "Solved", "optimal"]
solvers = {
"QOCO": "qoco_results.csv",
"QOCO-GPU": "qoco_cuda_results.csv",
"CuClarabel": "cuclarabel_results.csv",
"Mosek": "mosek_results.csv",
"Gurobi": "gurobi_results.csv",
}
COLOR = {
"QOCO": "black",
"QOCO-GPU": "mediumseagreen",
"CuClarabel": "darkviolet",
"Mosek": "firebrick",
"Gurobi": "coral",
}
def load_all_runtimes(tmax):
t = {s: [] for s in solvers}
for problem in PROBLEMS:
for solver, file in solvers.items():
path = os.path.join(problem, file)
df = pd.read_csv(path)
runtime = df["setup_time"] + df["solve_time"]
if "status" in df.columns:
status = df["status"]
else:
status = ["optimal"] * len(df)
for r, st in zip(runtime, status):
if r > tmax or math.isnan(r) or st not in SOLVED_STRINGS:
t[solver].append(tmax)
else:
t[solver].append(r)
return t
def compute_relative_profile(t, xrange=(0, 2.6), n_tau=3600):
solver_names = list(t.keys())
n_prob = len(next(iter(t.values())))
r = {s: np.zeros(n_prob) for s in solver_names}
for p in range(n_prob):
min_time = min(t[s][p] for s in solver_names)
for s in solver_names:
r[s][p] = t[s][p] / min_time
tau_vec = np.logspace(xrange[0], xrange[1], n_tau)
rho = {"tau": tau_vec}
for s in solver_names:
rvals = np.array(r[s])
rho[s] = np.array([np.sum(rvals <= tau) / n_prob for tau in tau_vec])
df = pd.DataFrame(rho)
df.to_csv("relative_profile.csv", index=False)
return df
def compute_absolute_profile(t, xrange=(-3, 3.5), n_tau=3600):
solver_names = list(t.keys())
n_prob = len(next(iter(t.values())))
tau_vec = np.logspace(xrange[0], xrange[1], n_tau)
rho = {"tau": tau_vec}
for s in solver_names:
times = np.array(t[s])
rho[s] = np.array([np.sum(times <= tau) / n_prob for tau in tau_vec])
df = pd.DataFrame(rho)
df.to_csv("absolute_profile.csv", index=False)
return df
def plot_relative_profile(df):
plt.rcParams.update({"text.usetex": True, "font.family": "serif"})
plt.figure()
for col in df.columns[1:]:
plt.plot(df["tau"], df[col], label=col, color=COLOR[col])
plt.xscale("log")
plt.xlabel("Performance ratio", fontsize=14)
plt.ylabel("Fraction of problems", fontsize=14)
plt.legend()
plt.grid(True)
plt.savefig("figures/benchmark_relative_profile.pdf", bbox_inches="tight")
plt.close()
def plot_absolute_profile(df):
plt.rcParams.update({"text.usetex": True, "font.family": "serif"})
plt.figure()
for col in df.columns[1:]:
plt.plot(df["tau"], df[col], label=col, color=COLOR[col])
plt.xscale("log")
plt.xlabel("Runtime (seconds)", fontsize=14)
plt.ylabel("Fraction of problems", fontsize=14)
plt.legend()
plt.grid(True)
plt.savefig("figures/benchmark_absolute_profile.pdf", bbox_inches="tight")
plt.close()
def main():
tmax = 3600
# load runtimes
t = load_all_runtimes(tmax)
# compute profiles
df_rel = compute_relative_profile(t)
df_abs = compute_absolute_profile(t)
# plot
plot_relative_profile(df_rel)
plot_absolute_profile(df_abs)
if __name__ == "__main__":
main()