-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun_slurm.py
80 lines (58 loc) · 1.93 KB
/
run_slurm.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'''
This script uses SLURM to run in parallel many trials of the same algorithm
on different environments with fixed random seed (seed = trial number).
Command
python3 run_slurm.py <ALG_NAME> <N_TRIALS> <ENV_LIST>
Example
python3 run_slurm.py ddpg.ddpg 5 Pendulum-v0 Swimmer-v2
One job per run will be submitted.
Data is still saved as usual in `data-trial`, but instead of the current date and time,
the seed (= trial number) is used. For example, for the above run data will be saved in
data-trial/ddpg/Pendulum-v0/0.dat
data-trial/ddpg/Pendulum-v0/1.dat
...
Additionally, stdout and stderr are flushed to log files. For example
logs-trial/stdout_ddpg.ddpg_Pendulum-v0_0
logs-trial/stderr_ddpg.ddpg_Pendulum-v0_0
...
NOTE: Change the slurm script according to your needs (activate virtual env,
request more memory, more computation time, ...).
'''
import os, errno, sys
logdir = 'logs-trial/' # directory to save log files (where stdout is flushed)
try:
os.makedirs(logdir)
except OSError as e:
if e.errno != errno.EEXIST:
raise
alg_name = sys.argv[1]
n_trials = int(sys.argv[2])
env_list = sys.argv[3:]
for env_name in env_list:
for trial in range(n_trials):
run_name = alg_name + '_' + env_name + '_' + str(trial)
text = """\
#!/bin/bash
# job name
#SBATCH -J """ + run_name + """\
# logfiles
#SBATCH -o """ + logdir + """stdout_""" + run_name + """\
#SBATCH -e """ + logdir + """stderr_""" + run_name + """\
# request computation time hh:mm:ss
#SBATCH -t 24:00:00
# request virtual memory in MB per core
#SBATCH --mem-per-cpu=1000
# nodes for a single job
#SBATCH -n 1
#SBATCH -C avx2
#SBATCH -c 4
# activate virtual env
module load intel python/3.6
source ../.bashrc
python3 -m """ + alg_name + """ """ + env_name + """ """ + str(trial) + """\
"""
text_file = open('r.sh', "w")
text_file.write(text)
text_file.close()
os.system('sbatch r.sh')
os.remove('r.sh')