-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_script.py
More file actions
60 lines (46 loc) · 2.22 KB
/
test_script.py
File metadata and controls
60 lines (46 loc) · 2.22 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
import subprocess
import os
import datetime
# Paths
# input_folder = "./Benchmarks/qasms"
input_folder = "./Outputs/small/design_both_depth"
summary_log_file = "./log/depth/design_both_ilp.log"
# 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)
# Command template
command = f"python test.py --input {input_path}"
# command = f"python main.py --input {input_path} --output {output_qasm_path} --log {log_path} --mode {mode} --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}'.")