Skip to content

Commit cbfbd2f

Browse files
authored
Merge pull request #83 from davidkastner/cluster-submit-bug
Fixed a bug for the cluster submitter
2 parents 03cfaab + a9bdd25 commit cbfbd2f

File tree

1 file changed

+57
-53
lines changed

1 file changed

+57
-53
lines changed

pyqmmm/io/submit_clustering.py

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,67 @@
11
import os
22
import subprocess
33

4-
# Get the current working directory
5-
cwd = os.getcwd()
4+
def main():
5+
# Get the current working directory
6+
cwd = os.getcwd()
67

7-
# Function to check if a directory contains any .out file
8-
def has_out_file(dir_path):
9-
for file in os.listdir(dir_path):
10-
if file.endswith('.out'):
11-
return True
12-
return False
8+
# Function to check if a directory contains any .out file
9+
def has_out_file(dir_path):
10+
for file in os.listdir(dir_path):
11+
if file.endswith('.out'):
12+
return True
13+
return False
1314

14-
# Iterate over all items in the cwd
15-
for item in os.listdir(cwd):
16-
item_path = os.path.join(cwd, item)
17-
18-
# Check if it's a directory and not "1_cluster"
19-
if os.path.isdir(item_path) and item != "1_cluster":
20-
# Path to 2_analysis
21-
analysis_dir = os.path.join(item_path, "2_analysis")
15+
# Iterate over all items in the cwd
16+
for item in os.listdir(cwd):
17+
item_path = os.path.join(cwd, item)
2218

23-
# Check if 2_analysis exists
24-
if os.path.exists(analysis_dir) and os.path.isdir(analysis_dir):
25-
# Path to 1_cluster inside 2_analysis
26-
cluster_dir = os.path.join(analysis_dir, "1_cluster")
19+
# Check if it's a directory and not "1_cluster"
20+
if os.path.isdir(item_path) and item != "1_cluster":
21+
# Path to 2_analysis
22+
analysis_dir = os.path.join(item_path, "2_analysis")
2723

28-
# Check if 1_cluster exists
29-
if os.path.exists(cluster_dir) and os.path.isdir(cluster_dir):
30-
# Iterate over subdirectories in 1_cluster
31-
for sub_item in os.listdir(cluster_dir):
32-
sub_item_path = os.path.join(cluster_dir, sub_item)
33-
34-
# Check if it's a directory
35-
if os.path.isdir(sub_item_path):
36-
# Path to cluster.sh
37-
sh_file = os.path.join(sub_item_path, "cluster.sh")
24+
# Check if 2_analysis exists
25+
if os.path.exists(analysis_dir) and os.path.isdir(analysis_dir):
26+
# Path to 1_cluster inside 2_analysis
27+
cluster_dir = os.path.join(analysis_dir, "1_cluster")
28+
29+
# Check if 1_cluster exists
30+
if os.path.exists(cluster_dir) and os.path.isdir(cluster_dir):
31+
# Iterate over subdirectories in 1_cluster
32+
for sub_item in os.listdir(cluster_dir):
33+
sub_item_path = os.path.join(cluster_dir, sub_item)
3834

39-
# Check if cluster.sh exists
40-
if os.path.exists(sh_file):
41-
# Check for .out files
42-
if has_out_file(sub_item_path):
43-
# Prompt user
44-
response = input(f"Job might be running in {sub_item_path}. Resubmit? (y/N): ").strip().lower()
45-
if response != 'y':
46-
print(f"Skipping resubmission for {sub_item_path}")
47-
continue
35+
# Check if it's a directory
36+
if os.path.isdir(sub_item_path):
37+
# Path to cluster.sh
38+
sh_file = os.path.join(sub_item_path, "cluster.sh")
4839

49-
# Submit the job
50-
try:
51-
result = subprocess.run(['sbatch', sh_file], capture_output=True, text=True, cwd=sub_item_path)
52-
if result.returncode == 0:
53-
print(f"Submitted job for {sub_item_path}: {result.stdout.strip()}")
54-
else:
55-
print(f"Error submitting job for {sub_item_path}: {result.stderr.strip()}")
56-
except Exception as e:
57-
print(f"Exception submitting job for {sub_item_path}: {str(e)}")
58-
else:
59-
print(f"cluster.sh not found in {sub_item_path}")
40+
# Check if cluster.sh exists
41+
if os.path.exists(sh_file):
42+
# Check for .out files
43+
if has_out_file(sub_item_path):
44+
# Prompt user
45+
response = input(f"Job might be running in {sub_item_path}. Resubmit? (y/N): ").strip().lower()
46+
if response != 'y':
47+
print(f"Skipping resubmission for {sub_item_path}")
48+
continue
49+
50+
# Submit the job
51+
try:
52+
result = subprocess.run(['sbatch', sh_file], capture_output=True, text=True, cwd=sub_item_path)
53+
if result.returncode == 0:
54+
print(f"Submitted job for {sub_item_path}: {result.stdout.strip()}")
55+
else:
56+
print(f"Error submitting job for {sub_item_path}: {result.stderr.strip()}")
57+
except Exception as e:
58+
print(f"Exception submitting job for {sub_item_path}: {str(e)}")
59+
else:
60+
print(f"cluster.sh not found in {sub_item_path}")
61+
else:
62+
print(f"1_cluster not found in {analysis_dir}")
6063
else:
61-
print(f"1_cluster not found in {analysis_dir}")
62-
else:
63-
print(f"2_analysis not found in {item_path}")
64+
print(f"2_analysis not found in {item_path}")
65+
66+
if __name__ == "__main__":
67+
main()

0 commit comments

Comments
 (0)