-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_reinf_rate_optim.py
executable file
·104 lines (79 loc) · 3.15 KB
/
run_reinf_rate_optim.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#! /usr/bin/env python
""" Figure out the best learning parameters for the reinforcement-based
simulations. """
import sys
import os
import time
import numpy as np
import cPickle as pickle
try:
from argparse import ArgumentParser
from subprocess import check_output
except:
sys.exit("Need Python version 2.7. Make sure the right module is loaded.")
if __name__ == '__main__':
version = sys.version_info
if version.major != 2 or version.minor < 7:
sys.exit("Need Python version 2.7. Make sure the right module is loaded.")
parser = ArgumentParser(description="Create and run job files for finding" +
" good learning rates for reinforcement simulations.")
parser.add_argument('--defaults', help="pickle containing default parameters",
required=True)
parser.add_argument('--nreps', help="number of steps per simulation",
default=6000)
parser.add_argument('--n_per_job', help="number of simulations per job",
default=3)
args = parser.parse_args()
plasticity_rates = np.arange(0.01, 0.12, 0.01)*1e-8
tutor_rates = np.arange(0.003, 0.012, 0.001)
time_tag = time.strftime("%y%m%d.%H%M")
all_rates = [(ip, it) for ip in xrange(len(plasticity_rates))
for it in xrange(len(tutor_rates))]
n_jobs = int(np.ceil(float(len(all_rates))/args.n_per_job))
crt_rate_idx = 0
for i in xrange(n_jobs):
crt_rates = all_rates[crt_rate_idx:crt_rate_idx+args.n_per_job]
run_name = "job/job_bird_reinf_optim_{}.sh".format(i)
job_name = "reinf_opt{}".format(i)
job_script = """#!/bin/bash
#!/bin/bash
#PBS -q production
#PBS -N {job_name}
#PBS -l select=1:ncpus=1
#PBS -l walltime=36:00:00
#PBS -l place=free
#PBS -V
date
cd $PBS_O_WORKDIR
SCRIPT_PATH=songbird/batch
SCRIPT_NAME=run_once.py
SCRIPT_FULL="$SCRIPT_PATH/$SCRIPT_NAME"
""".format(job_name=job_name)
for j in xrange(len(crt_rates)):
ip, it = crt_rates[j]
plasticity_rate = plasticity_rates[ip]
tutor_rate = tutor_rates[it]
base_name = "song_reinf_optim_batch_{}.{}".format(ip, it) + "." + time_tag
# start setting up the command line options
cmdline_opts = "--tutor_tau_out=40.0 --tutor_rule_type=reinforcement"
cmdline_opts += " --plasticity_learning_rate={}".format(plasticity_rate)
cmdline_opts += " --tutor_rule_learning_rate={}".format(tutor_rate)
cmdline_opts += " --relaxation=200.0 --relaxation_conductor=200.0"
cmdline_opts += " --tutor_rule_relaxation=0 --tutor_rule_tau=0"
cmdline_opts += " --tutor_rule_compress_rates=True"
cmdline_opts += " --nreps={} --defaults={}".format(args.nreps,
args.defaults)
log_name = "log/" + base_name + "_out.txt"
cmdline_opts += " --out=out/" + base_name + ".pkl"
cmdline_opts += " --log=" + log_name
job_script += "$SCRIPT_FULL {cmdline_opts} 2>&1\n\n".format(
cmdline_opts=cmdline_opts)
job_script += "\ndate\n"
with open(run_name, 'wt') as out:
out.write(job_script)
# and now submit them
qsub_opts = run_name
print("About to call qsub " + qsub_opts + "...")
out = check_output(['qsub'] + qsub_opts.split())
print("Answer: " + out)
crt_rate_idx += args.n_per_job