-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_shor_log.py
39 lines (33 loc) · 1.11 KB
/
parse_shor_log.py
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
import json
import pandas as pd
import re
results = []
with open("shor_output_11.log", "r") as f:
lines = f.read()
segments = lines.split("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
for segment in segments:
segment = segment.strip()
match = re.search(r"RUNNING SHOR: N=(\d+), a=(\d+), ver=(\d+)", segment)
if match:
current_N = int(match.group(1))
current_a = int(match.group(2))
current_version = int(match.group(3))
continue
if segment.startswith("{") and segment.endswith("}"):
try:
stats = json.loads(segment)
results.append(
{
"N": current_N,
"a": current_a,
"version": current_version,
"num_qubits": stats.get("num_qubits"),
"num_gates": stats.get("num_gates"),
"gate_types": stats.get("gate_types"),
}
)
except json.JSONDecodeError as e:
print("Failed to parse JSON:", e)
df = pd.DataFrame(results)
print(df)
df.to_csv("shor_stats_11.csv", index=False)