-
Notifications
You must be signed in to change notification settings - Fork 1
/
ot_simulate.py
53 lines (45 loc) · 1.8 KB
/
ot_simulate.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import subprocess
import time
from concurrent.futures import ThreadPoolExecutor, as_completed
from pathlib import Path
def simulate(directory: Path):
start_time = time.time() # Start timing
python_files = [os.path.join(directory, file) for file in os.listdir(directory) if file.endswith(".py")]
if not python_files:
print(f"No python file in directory {directory}. Skipping...")
return
python_file = python_files[0] # Assuming there's only one .py file per directory
custom_labware_directory = Path(directory, "custom_labware")
custom_labware = []
if custom_labware_directory.exists() and custom_labware_directory.is_dir():
json_files = [file for file in custom_labware_directory.iterdir() if file.suffix == ".json"]
if json_files:
custom_labware = [
"-L",
custom_labware_directory.resolve(),
]
else:
print(f"No .json files in {custom_labware_directory}.")
if custom_labware == []:
command = [
"opentrons_simulate",
python_file,
]
else:
command = [
"opentrons_simulate",
python_file,
] + custom_labware
print(f"Running command: {command}")
subprocess.run(command, check=True)
end_time = time.time() # End timing
print(f"Simulate of {directory} completed in {end_time - start_time:.2f} seconds")
def run_simulate_in_parallel(directories):
with ThreadPoolExecutor() as executor:
futures = [executor.submit(simulate, Path(dir)) for dir in directories]
for future in as_completed(futures):
try:
future.result() # This blocks until the future is done
except Exception as e:
print(f"An error occurred: {e}")