-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_multiproc.py
49 lines (38 loc) · 1.3 KB
/
run_multiproc.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
'''
This script uses MULTIPROCESSING to run in parallel many trials of the same algorithm
on different environments with fixed random seed (seed = trial number).
Command
python3 run_multiproc.py <ALG_NAME> <N_TRIALS> <ENV_LIST>
Example
python3 run_multiproc.py 5 ddpg.ddpg Pendulum-v0 Swimmer-v2
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
...
WARNING!
The script will run ALL trials in parallel! If you run too many
trials/environments this may clog your computer. Alternatively, you can use
`Pool` but there may be problems using it with Tensorflow.
Another option is to use `run_joblib.py`, but it is usually slower.
'''
import sys
from multiprocessing import Process
alg_name = sys.argv[1]
n_trials = int(sys.argv[2])
env_list = sys.argv[3:]
from importlib import import_module
alg = import_module(alg_name)
# create a list of arguments, one for each run
args = []
for trial in range(n_trials):
for env_name in env_list:
args.append((env_name, trial, str(trial)))
# submit procs
ps = []
for a in args:
p = Process(target=alg.main, args=a)
p.start()
ps.append(p)
for p in ps:
p.join()