-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
93 lines (77 loc) · 4.25 KB
/
script.py
File metadata and controls
93 lines (77 loc) · 4.25 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
import subprocess
import os
import datetime
# Paths
# input_folder = "./Benchmarks/qasms"
input_folder = "./Benchmarks/scalibility_qaoa"
output_folder = "./Outputs/qaoa/scalibility_qaoa_both_smt"
log_folder = "./Outputs//qaoa/scalibility_qaoa_both_smt"
summary_log_file = "./log/summarize/scalibility_qaoa_both_smt.log"
mode = "all"
# 1: only SMT, 2: reorder, 3: eager measurement, 4: both
# file_depth = {
# "4mod": 15,
# "multiply-13": 53,
# "system9": 128,
# "bv_10": 23,
# "qaoa5": 23,
# "qaoa10": 34,
# "dj": 22,
# "routing": 28,
# "tsp": 90,
# "simon_our": 15,
# }
# Ensure output and log folders exist
os.makedirs(output_folder, exist_ok=True)
os.makedirs(log_folder, exist_ok=True)
# Clear the old summary log file
with open(summary_log_file, "w") as log_file:
log_file.write("Batch Execution Summary\n")
log_file.write("=" * 50 + "\n\n")
# Get all .qasm files from the input folder
qasm_files = [f for f in os.listdir(input_folder) if f.endswith(".qasm")]
# Iterate through the files and execute the command
for qasm_file in qasm_files:
file_name_without_ext = os.path.splitext(qasm_file)[0]
# if file_name_without_ext == "simon_n16" or file_name_without_ext == "simon_n18" or file_name_without_ext == "simon_n20":
# continue
# if file_name_without_ext != "simon_our":
# continue
# if file_name_without_ext != "qaoa_n5_our" and file_name_without_ext != "qaoa_n7_our" and file_name_without_ext != "qaoa_n9_our" and file_name_without_ext != "qaoa_n11_our" and file_name_without_ext != "qaoa_n13_our" and file_name_without_ext != "qaoa_n15_our" and file_name_without_ext != "qaoa_n17_our":
# if file_name_without_ext != "qaoa_n19_our" and file_name_without_ext != "qaoa_n20_our" and file_name_without_ext != "qaoa_n25_our" and file_name_without_ext != "qaoa_n30_our":
# if file_name_without_ext != "qaoa_n35_our" and file_name_without_ext != "qaoa_n40_our" and file_name_without_ext != "qaoa_n45_our" and file_name_without_ext != "qaoa_n50_our":
# continue
if file_name_without_ext != "qaoa_n5_our" and file_name_without_ext != "qaoa_n7_our" and file_name_without_ext != "qaoa_n9_our" and file_name_without_ext != "qaoa_n11_our" and file_name_without_ext != "qaoa_n13_our" and file_name_without_ext != "qaoa_n15_our" and file_name_without_ext != "qaoa_n17_our" and file_name_without_ext != "qaoa_n19_our":
continue
input_path = os.path.join(input_folder, qasm_file)
output_qasm_path = os.path.join(output_folder, f"{file_name_without_ext}.qasm")
log_path = os.path.join(log_folder, f"{file_name_without_ext}.log")
# Command template
# command = f"python main.py --input {input_path} --output {output_qasm_path} --log {log_path} --mode {mode} --depth {file_depth[file_name_without_ext]}"
command = f"python main.py --input {input_path} --output {output_qasm_path} --log {log_path} --mode {mode}"
try:
print(f"Running command: {command}")
start_time = datetime.datetime.now()
# Run the command
result = subprocess.run(command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, timeout=1200)
end_time = datetime.datetime.now()
# Output results to terminal
print(result.stdout)
if result.stderr:
print(f"Error for {qasm_file}: {result.stderr}")
# Append results to the summary log file
with open(summary_log_file, "a") as log_file:
log_file.write(f"--- Execution for {qasm_file} ({start_time}) ---\n")
log_file.write(f"Command: {command}\n")
log_file.write(f"Start time: {start_time}\n")
log_file.write(f"End time: {end_time}\n")
log_file.write(f"Standard Output:\n{result.stdout}\n")
log_file.write(f"Standard Error:\n{result.stderr}\n")
log_file.write("\n")
except Exception as e:
print(f"An error occurred while running the command for {qasm_file}: {e}")
with open(summary_log_file, "a") as log_file:
log_file.write(f"--- Error for {qasm_file} ---\n")
log_file.write(f"Command: {command}\n")
log_file.write(f"Error: {e}\n\n")
print(f"Batch execution completed. Summary written to '{summary_log_file}'.")