forked from abides-sim/abides
-
Notifications
You must be signed in to change notification settings - Fork 0
/
single_config_parallel.py
162 lines (135 loc) · 6.49 KB
/
single_config_parallel.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import argparse
import os
from multiprocessing import Pool
import psutil
import datetime as dt
import numpy as np
from dateutil.parser import parse
import pyDOE
def run_in_parallel(num_simulations, num_parallel, config, log_folder, verbose,
book_freq, hist_date, mkt_start_time, mkt_end_time, noise):
global_seeds = np.random.randint(0, 2 ** 31, num_simulations)
print(f'Global Seeds: {global_seeds}')
time_config = np.array([["20210325", "08:00:00", "16:00:00"],
["20210325", "16:00:00", "23:59:59"],
["20210326", "00:00:00", "08:00:00"],
["20210326", "08:00:00", "16:00:00"],
["20210326", "16:00:00", "23:59:59"],
["20210327", "00:00:00", "08:00:00"],
["20210327", "08:00:00", "16:00:00"],
["20210327", "16:00:00", "23:59:59"],
["20210328", "00:00:00", "08:00:00"],
["20210328", "08:00:00", "16:00:00"],
["20210328", "16:00:00", "23:59:59"],
["20210329", "00:00:00", "08:00:00"],
["20210329", "08:00:00", "16:00:00"],
["20210329", "16:00:00", "23:59:59"]])
# initialise processes
processes = []
# iterate over number of simulations
for i in range(len(time_config)):
# set seed according to global seed
seed = global_seeds[i]
# assign number of atents according to predetermined configeration
zi_count = 764#int(agent_config[i][0]) 800
zip_count = 91#int(agent_config[i][1]) 100
mmt_count = 144#int(agent_config[i][2]) 50
mr_count = 0#int(agent_config[i][3]) 50
mm_count = 1
# assign times
hist_date = time_config[i][0]
mkt_start_time = time_config[i][1]
mkt_end_time = time_config[i][2]
print(f"current config: {time_config[i][0]}, {time_config[i][1]}, {time_config[i][2]}")
processes.append(f'python -u abides.py -c {config} -l {time_config[i][0]}_{time_config[i][1]}_{time_config[i][2]}_45000 \
{"-v" if verbose else ""} -s {seed} -b {book_freq} -d {time_config[i][0]} -st {time_config[i][1]} -et {time_config[i][2]} \
-zi {zi_count} -zip {zip_count} -mmt {mmt_count} -mr {mr_count} -mm {mm_count} -n {noise}')
print(processes)
pool = Pool(processes=num_parallel)
pool.map(run_process, processes)
def run_process(process):
os.system(process)
if __name__ == "__main__":
start_time = dt.datetime.now()
parser = argparse.ArgumentParser(description='Main config to run multiple ABIDES simulations in parallel')
parser.add_argument('-c', '--config',
required=True,
help='Name of config file to execute'
)
parser.add_argument('-ns', '--num_simulations',
type=int,
default=1,
help='Total number of simulations to run')
parser.add_argument('-np', '--num_parallel',
type=int,
default=None,
help='Number of simulations to run in parallel')
parser.add_argument('-l', '--log_folder',
required=True,
help='Log directory name')
parser.add_argument('-b', '--book_freq',
default=None,
help='Frequency at which to archive order book for visualization'
)
parser.add_argument('-n', '--obs_noise',
type=float,
default=1000000,
help='Observation noise variance for zero intelligence agents (sigma^2_n)'
)
parser.add_argument('-o', '--log_orders',
action='store_true',
help='Log every order-related action by every agent.'
)
parser.add_argument('-s', '--seed',
type=int,
default=None,
help='numpy.random.seed() for simulation'
)
parser.add_argument('-v', '--verbose',
action='store_true',
help='Maximum verbosity!'
)
parser.add_argument('--config_help',
action='store_true',
help='Print argument options for this config file'
)
parser.add_argument('-d', '--historical_date',
required=True,
help='historical date being simulated in format YYYYMMDD.'
)
parser.add_argument('-st', '--start_time',
default='09:30:00',
help='Starting time of simulation.'
)
parser.add_argument('-et', '--end_time',
default='16:00:00',
help='Ending time of simulation.'
)
args, remaining_args = parser.parse_known_args()
seed = args.seed
num_simulations = args.num_simulations
num_parallel = args.num_parallel if args.num_parallel else psutil.cpu_count() # count of the CPUs on the machine
config = args.config
log_folder = args.log_folder
verbose = args.verbose
book_freq = args.book_freq
hist_date = args.historical_date
mkt_start_time = args.start_time
mkt_end_time = args.end_time
noise = args.obs_noise
print(f'Total number of simulation: {num_simulations}')
print(f'Number of simulations to run in parallel: {num_parallel}')
print(f'Configuration: {config}')
np.random.seed(seed)
run_in_parallel(num_simulations = num_simulations,
num_parallel = num_parallel,
config = config,
log_folder = log_folder,
verbose = verbose,
book_freq = book_freq,
hist_date = hist_date,
mkt_start_time = mkt_start_time,
mkt_end_time = mkt_end_time,
noise = noise)
end_time = dt.datetime.now()
print(f'Total time taken to run in parallel: {end_time - start_time}')