-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsubmit_slurm_script.py
63 lines (48 loc) · 1.59 KB
/
submit_slurm_script.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
54
55
56
57
58
59
60
61
62
63
"""
Quick script to run hydra with condor launcher
Run the file as
python submit_script.py <DIRECTORY> <NAME> dqrm_coffee_world.py <ARGS>
"""
import os
import shutil
import stat
import subprocess
import sys
import time
from typing import List
# Directory where temporary SLURM scripts are dumped
script_directory = "outputs"
# SLURM job specification that is shared among processes
def get_slurm_base_script(experiment_directory: str):
return f"""#!/bin/bash
#SBATCH --time=24:00:00
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=4
#SBATCH --mem=200G
eval "$($HOME/miniconda3/bin/conda shell.bash hook)"
export PATH=$PATH:$HOME/bin
cd $HOME/rm-marl
conda activate rm_marl
"""
def run_slurm(args, name, experiment_directory):
# get the python command with all the arguments
python_run = f"python {' '.join(args)}"
# generate scripts
slurm_out = f"{script_directory}/{experiment_directory}/{name}.sh"
if not os.path.exists(f"{script_directory}/{experiment_directory}"):
os.makedirs(f"{script_directory}/{experiment_directory}")
# Generate SLURM script
with open(slurm_out, 'w') as f:
f.write(get_slurm_base_script(experiment_directory))
f.write('\n')
f.write(python_run)
# Submit a script
result = subprocess.run(['sbatch', slurm_out], stdout=subprocess.PIPE, text=True)
print(result.stdout)
if __name__ == "__main__":
arguments = sys.argv
directory = arguments[1]
name = arguments[2]
args = arguments[3:]
os.makedirs(script_directory, exist_ok=True)
run_slurm(args, name, directory)