-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_utils.py
60 lines (51 loc) · 1.81 KB
/
run_utils.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
import os, yaml, argparse
from pathlib import Path
from itertools import count
parser = argparse.ArgumentParser(description='PyTorch Epipolicy SAC/PPO runs generation')
parser.add_argument(
'--algo',
# default='sac',
type=str,
required=True,
help=' reinforcement learning algorithm'
)
args = parser.parse_args()
dumpdir = "runs/"
if not os.path.isdir(dumpdir):
os.mkdir(dumpdir)
fixed_text = "#!/bin/bash\n"\
"#SBATCH --nodes=1\n"\
"#SBATCH --cpus-per-task=16 \n"\
"#SBATCH --time=4:00:00\n"\
"#SBATCH --mem=20GB\n"\
# "#SBATCH --gres=gpu:1\n"
config_file = "configs/sac.yaml" if args.algo == 'sac' else "configs/ppo.yaml"
with open(config_file, "r") as stream:
try: config = yaml.safe_load(stream)
except yaml.YAMLError as exc: print(exc)
for scenario in ['SIRV_A', 'SIRV_B', 'SIR_A', 'SIR_B']:
# for scenario in ['COVID_A', 'COVID_B', 'COVID_C']:
for exp in config:
command = fixed_text + "#SBATCH --job-name="+exp+"\n#SBATCH --output="+exp+".out\n"
command += "\nsource ../venvs/epipolicy/bin/activate\n"\
"\nmodule load python/intel/3.8.6\n"\
"module load openmpi/intel/4.0.5\n"\
"time python3 runner.py "
command = ' '.join([
command,
'--exp', exp,
"--config", config_file,
'--scenario', 'jsons/'+scenario+'.json',
'--algo', args.algo
])
# print(command)
log_dir = Path(dumpdir)
for i in count(1):
temp = log_dir/('run{}.sh'.format(i))
if temp.exists():
pass
else:
with open(temp, "w") as f:
f.write(command)
log_dir = temp
break