-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_html_benchmarks.py
More file actions
57 lines (46 loc) · 2.05 KB
/
generate_html_benchmarks.py
File metadata and controls
57 lines (46 loc) · 2.05 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
import os
from methods.methods import Method, OptimizationOptions
from methods.run_optimization import timed_run_optimization
from problems.problems import ProblemType, load_problem
from methods.timedelta_format import timedelta_format
def mkdir_generated():
try:
os.mkdir("generated")
except FileExistsError:
# already exists. ok
pass
def go():
mkdir_generated()
options = OptimizationOptions()
for problem_type in ProblemType:
problem = load_problem(ProblemType(problem_type))
print(f"loaded. problem={problem_type}")
file_path = os.path.join("generated", f"{problem_type}.html")
with open(file_path, 'w') as html_file:
html_file.write("<html><body>")
html_file.write("<div>")
html_file.write("<table>")
html_file.write("<tr>")
html_file.write("<th>method</th>")
html_file.write("<th>final f</th>")
html_file.write("<th>gradient norm</th>")
html_file.write("<th>steps</th>")
html_file.write("<th>time</th>")
html_file.write("<th>termination reason</th>")
html_file.write("</tr>")
for method in Method:
print(f"method={method}. problem={problem_type}")
results = timed_run_optimization(Method(method), problem, options)
html_file.write("<tr>")
html_file.write(f"<td>{method.name}</td>")
html_file.write(f"<td>{results.results.final_function_value:<14.5f}</td>")
html_file.write(f"<td>{results.results.final_gradient_norm:<10.5f}</td>")
html_file.write(f"<td>{len(results.results.steps)}</td>")
html_file.write(f"<td>{timedelta_format(results.run_time)}</td>")
html_file.write(f"<td>{results.results.termination_reason}</td>")
html_file.write("</tr>")
html_file.write("</table>")
html_file.write("</div>")
html_file.write("</body></html>")
if __name__ == '__main__':
go()