-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_benchmark_table.py
More file actions
170 lines (131 loc) · 4.66 KB
/
make_benchmark_table.py
File metadata and controls
170 lines (131 loc) · 4.66 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
165
166
167
168
169
170
import pandas as pd
PROBLEMS = [
"huber",
"portfolio",
"multiperiod_portfolio",
"group_lasso",
"tv_denoising",
]
SOLVED_STRINGS = ["QOCO_SOLVED", "SOLVED", "Solved", "optimal"]
solvers = {
"QOCO-GPU": "qoco_cuda_results.csv",
"QOCO": "qoco_results.csv",
"CuClarabel": "cuclarabel_results.csv",
"Mosek": "mosek_results.csv",
"Gurobi": "gurobi_results.csv",
}
def latex_escape(s):
return (
str(s)
.replace("\\", r"\textbackslash ")
.replace("_", r"\_")
.replace("&", r"\&")
.replace("%", r"\%")
.replace("#", r"\#")
)
def load_problem(problem_name):
dfs = {}
for solver, file in solvers.items():
path = f"{problem_name}/{file}"
df = pd.read_csv(path)
df["runtime"] = df["setup_time"] + df["solve_time"]
# Compute setup fraction (only meaningful for QOCO-GPU)
if solver == "QOCO-GPU":
df["setup_frac"] = df["setup_time"] / df["runtime"]
else:
df["setup_frac"] = pd.NA
# Mark timeouts
df.loc[
(df["runtime"] > 3600.0) | (~df["status"].isin(SOLVED_STRINGS)),
"runtime"
] = pd.NA
df.loc[df["runtime"].isna(), "setup_frac"] = pd.NA
dfs[solver] = df[["name", "size", "runtime", "setup_frac"]]
merged = None
for solver, df in dfs.items():
df = df.rename(
columns={"runtime": solver, "setup_frac": f"{solver}_setup_frac"}
)
if merged is None:
merged = df
else:
merged = merged.merge(
df[["name", solver, f"{solver}_setup_frac"]], on="name", how="outer"
)
merged["size"] = merged["size"].ffill()
merged = merged.sort_values("size")
merged["problem_group"] = problem_name
return merged
def make_benchmark_table():
tables = [load_problem(p) for p in PROBLEMS]
merged = pd.concat(tables, ignore_index=True)
solver_names = list(solvers.keys())
lines = []
lines.append(r"{\footnotesize")
lines.append(r"\begin{longtable}{l r " + " ".join(["r"] * len(solver_names)) + "}")
lines.append(
r"\caption{\bf Runtime in seconds for benchmark problems (QOCO-GPU shows setup time percentage in parentheses)}"
)
lines.append(r"\label{tab:solver_benchmarks} \\")
lines.append("")
lines.append(r"\toprule")
lines.append("Problem & Size & " + " & ".join(solver_names) + r" \\")
lines.append(r"\midrule")
lines.append(r"\endfirsthead")
lines.append("")
lines.append(r"\toprule")
lines.append("Problem & Size & " + " & ".join(solver_names) + r" \\")
lines.append(r"\midrule")
lines.append(r"\endhead")
lines.append("")
lines.append(r"\midrule")
lines.append(
r"\multicolumn{"
+ str(len(solver_names) + 2)
+ r"}{r}{\footnotesize Continued on next page} \\"
)
lines.append(r"\endfoot")
lines.append("")
lines.append(r"\bottomrule")
lines.append(r"\endlastfoot")
current_group = None
for _, row in merged.iterrows():
if current_group is not None and row["problem_group"] != current_group:
lines.append(r"\midrule")
current_group = row["problem_group"]
# Determine best runtime (ignore NaNs)
runtimes = [row[s] for s in solver_names if not pd.isna(row[s])]
best = min(runtimes) if runtimes else None
cells = []
for s in solver_names:
val = row[s]
if pd.isna(val):
cells.append("-")
continue
frac = row.get(f"{s}_setup_frac", pd.NA)
# Format QOCO-GPU with optional setup %
if s == "QOCO-GPU":
if pd.isna(frac) or frac < 1e-6:
base = f"{val:.3f}"
else:
pct = int(round(100 * frac))
base = f"{val:.3f} ({pct}\\%)"
else:
base = f"{val:.3f}"
# Highlight winner (based on runtime only)
if best is not None and val == best:
if s == "QOCO-GPU" and not pd.isna(frac) and frac >= 1e-6:
pct = int(round(100 * frac))
base = f"\\winner {val:.3f} ({pct}\\%)"
else:
base = f"\\winner {val:.3f}"
cells.append(base)
name = latex_escape(row["name"])
line = f"{name} & {int(row['size'])} & " + " & ".join(cells) + r" \\"
lines.append(line)
lines.append(r"\end{longtable}")
lines.append(r"}")
with open("figures/benchmark_table.tex", "w") as f:
f.write("\n".join(lines))
if __name__ == "__main__":
make_benchmark_table()