-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscale_script.py
More file actions
65 lines (52 loc) · 2.54 KB
/
scale_script.py
File metadata and controls
65 lines (52 loc) · 2.54 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
import subprocess
import os
import datetime
# Paths
input_folder = "./Benchmarks/scale_simon"
output_folder = "./Outputs/results/scale_simon_both_smt_k7"
log_folder = "./Outputs/results/scale_simon_both_smt_k7"
summary_log_file = "./log/summarize/scale_simon_both_smt_k7.log"
mode = "all"
# 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]
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_scale.py --input {input_path} --output {output_qasm_path} --log {log_path} --mode {mode} --k 7 --solver SMT"
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}'.")