-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreproduce_runs.py
394 lines (298 loc) · 13.3 KB
/
reproduce_runs.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
""" Running this script will launch simulations for collecting all results in the paper.
"""
import sys
sys.path.append(".")
import gym
import copy
from lib.wordcraft.utils.task_utils import recipe_book_info
from gym.wrappers import FlattenObservation
from lib.wordcraft.wrappers.squash_wrapper import SquashWrapper
import lib.wordcraft
from lib.wordcraft.wordcraft.env_nogoal import WordCraftEnvNoGoal
from sapiens.sapiens import Sapiens
from scripts.evaluate import evaluate_project
from scripts.script_utils import build_envs
def run_all_main():
""" Runs all experiments used in plots in the main paper.
In particular, we run the five social network topologies on the three tasks for 10 agents. We do not keep track
of mnemonic metrics (doing so requires a lot of additional memory).
"""
project_dir = top_dir + "/paper/main"
shapes = [ "no-sharing", "ring" , "fully-connected" ]
n_agents = 10
gamma = 0.9
buffer_size = 5000
batch_size = 64
num_neurons = 64
num_layers = 2
n_trials = 10
#tasks = {"single_path": 50000, "merging_paths": 500000, "bestoften_paths": 500000}
#tasks = {"bestoften_paths": 500000}
tasks = {"merging_paths": 500000}
for trial in range(n_trials):
for task, total_episodes in tasks.items():
for shape in shapes:
project_path = project_dir + "/task_" + task + "/shape_" + shape
train_envs = []
eval_envs = []
for i in range(n_agents):
env_config["log_path"] = project_path
env_config["data_path"] = recipe_book_info[task]["path"]
train_env = build_envs(env_config)
eval_env = build_envs(env_config)
train_envs.append(train_env)
eval_envs.append(eval_env)
group = Sapiens(gamma=gamma,
buffer_size=buffer_size,
batch_size=batch_size,
num_neurons=num_neurons,
num_layers=num_layers,
n_agents=n_agents,
shape=shape,
train_envs=train_envs,
eval_envs=eval_envs,
project_path=project_path,
total_episodes=total_episodes,
trial=trial)
# train
group.learn()
# evaluate
evaluate_project(project_path)
def run_scaling():
""" Runs experiments studying the effect of group size.
In particular, we run the five social network topologies on the three tasks for 10 agents. We do not keep track
of mnemonic metrics (doing so requires a lot of additional memory).
"""
top_dir = "/media/elena/LaCie/SAPIENS/projects/paper/appendix/scaling"
shapes = ["fully-connected", "small-world", "ring", "dynamic-Boyd"]
gamma = 0.9
buffer_size = 5000
batch_size = 64
num_neurons = 64
num_layers = 2
group_sizes = [6, 20, 50]
tasks = {"single_path": 50000, "merging_paths": 500000, "bestoften_paths": 500000}
for task, total_episodes in tasks.items():
for shape in shapes:
for n_agents in group_sizes:
project_path = top_dir + "/task_" + task + "/shape_" + shape + "/size_" + str(n_agents)
train_envs = []
eval_envs = []
for i in range(n_agents):
env_config["log_path"] = project_path
env_config["data_path"] = recipe_book_info[task]["path"]
train_env = build_envs(env_config)
eval_env = build_envs(env_config)
train_envs.append(train_env)
eval_envs.append(eval_env)
group = Sapiens(gamma=gamma,
buffer_size=buffer_size,
batch_size=batch_size,
num_neurons=num_neurons,
num_layers=num_layers,
n_agents=n_agents,
shape=shape,
train_envs=train_envs,
eval_envs=eval_envs,
project_path=project_path,
total_episodes=total_episodes,
n_trials=10)
# train
group.learn()
# evaluate
evaluate_project(project_path)
def run_varying_dynamic_topologies():
""" Runs experiments studying the effect of group size.
In particular, we run the five social network topologies on the three tasks for 10 agents. We do not keep track
of mnemonic metrics (doing so requires a lot of additional memory).
"""
top_dir = "/media/elena/LaCie/SAPIENS/projects/paper/appendix/varying_dynamic/dynamic_Boyd"
shape = "dynamic-Boyd"
gamma = 0.9
buffer_size = 5000
batch_size = 64
num_neurons = 64
num_layers = 2
n_agents = 10
# configure dynamic topology
migrate_rates = [0.005, 0.01, 0.1, 0.5]
visit_durations = [10, 100, 100]
tasks = {"merging_paths": 500000, "bestoften_paths": 500000}
for task, total_episodes in tasks.items():
for migrate_rate in migrate_rates:
for visit_duration in visit_durations:
project_path = top_dir + "/task_" + task + "/migrate_" + str(migrate_rate) + "_duration_" + str(
visit_duration)
train_envs = []
eval_envs = []
for i in range(n_agents):
env_config["log_path"] = project_path
env_config["data_path"] = recipe_book_info[task]["path"]
train_env = build_envs(env_config)
eval_env = build_envs(env_config)
train_envs.append(train_env)
eval_envs.append(eval_env)
group = Sapiens(gamma=gamma,
buffer_size=buffer_size,
batch_size=batch_size,
num_neurons=num_neurons,
num_layers=num_layers,
n_agents=n_agents,
shape=shape,
train_envs=train_envs,
eval_envs=eval_envs,
project_path=project_path,
total_episodes=total_episodes,
visit_duration=visit_duration,
migrate_rate=migrate_rate,
n_trials=10)
# train
group.learn()
# evaluate
evaluate_project(project_path)
# ----- tuning dynamic-periodic
top_dir = "/media/elena/LaCie/SAPIENS/projects/paper/appendix/varying_dynamic/dynamic_Boyd"
shape = "dynamic-periodic"
gamma = 0.9
buffer_size = 5000
batch_size = 64
num_neurons = 64
num_layers = 2
n_agents = 10
# configure dynamic topology
phase_period_values = [[10,10],[10,100],[10,1000],[100,10],[100,100],[100,1000],[1000,10],[1000,100],[1000,1000]]
tasks = {"merging_paths": 500000, "bestoften_paths": 500000}
for task, total_episodes in tasks.items():
for phase_periods in phase_period_values:
project_path = top_dir + "/task_" + task + "/migrate_" + str(migrate_rate) + "_duration_" + str(
visit_duration)
train_envs = []
eval_envs = []
for i in range(n_agents):
env_config["log_path"] = project_path
env_config["data_path"] = recipe_book_info[task]["path"]
train_env = build_envs(env_config)
eval_env = build_envs(env_config)
train_envs.append(train_env)
eval_envs.append(eval_env)
group = Sapiens(gamma=gamma,
buffer_size=buffer_size,
batch_size=batch_size,
num_neurons=num_neurons,
num_layers=num_layers,
n_agents=n_agents,
shape=shape,
train_envs=train_envs,
eval_envs=eval_envs,
project_path=project_path,
total_episodes=total_episodes,
phase_periods=phase_periods,
n_trials=10)
# train
group.learn()
# evaluate
evaluate_project(project_path)
def run_mnemonic():
""" Runs all experiments used in plots in the main paper.
In particular, we run the five social network topologies on the three tasks for 10 agents. We keep track
of diversity and intra-group alignment by activating the study_mnemonic flag
"""
top_dir = "/media/elena/LaCie/SAPIENS/projects/paper/mnemonic"
shapes = ["no-sharing", "fully-connected", "small-world", "ring", "dynamic-Boyd"]
n_agents = 10
gamma = 0.9
buffer_size = 5000
batch_size = 64
num_neurons = 64
num_layers = 2
tasks = {"single_path": 50000, "merging_paths": 500000, "bestoften_paths": 500000}
for task, total_episodes in tasks.items():
for shape in shapes:
project_path = top_dir + "/task_" + task + "/shape_" + shape
train_envs = []
eval_envs = []
for i in range(n_agents):
env_config["log_path"] = project_path
env_config["data_path"] = recipe_book_info[task]["path"]
train_env = build_envs(env_config)
eval_env = build_envs(env_config)
train_envs.append(train_env)
eval_envs.append(eval_env)
group = Sapiens(gamma=gamma,
buffer_size=buffer_size,
batch_size=batch_size,
num_neurons=num_neurons,
num_layers=num_layers,
n_agents=n_agents,
shape=shape,
train_envs=train_envs,
eval_envs=eval_envs,
project_path=project_path,
total_episodes=total_episodes,
measure_mnemonic=True,
n_trials=10)
# train
group.learn()
# evaluate
evaluate_project(project_path)
def run_intergroup_alignment():
""" Runs all experiments used in plots in the main paper.
In particular, we run the five social network topologies on the three tasks for 10 agents. We keep track
of diversity and intra-group alignment by activating the measure_intergroup_alignment flag
"""
top_dir = "/media/elena/LaCie/SAPIENS/projects/paper/mnemonic"
shapes = ["no-sharing", "fully-connected", "small-world", "ring", "dynamic-Boyd"]
n_agents = 10
gamma = 0.9
buffer_size = 5000
batch_size = 64
num_neurons = 64
num_layers = 2
tasks = {"single_path": 50000, "merging_paths": 50000, "bestoften_paths": 50000}
for task, total_episodes in tasks.items():
for shape in shapes:
project_path = top_dir + "/task_" + task + "/shape_" + shape
train_envs = []
eval_envs = []
for i in range(n_agents):
env_config["log_path"] = project_path
env_config["data_path"] = recipe_book_info[task]["path"]
train_env = build_envs(env_config)
eval_env = build_envs(env_config)
train_envs.append(train_env)
eval_envs.append(eval_env)
group = Sapiens(gamma=gamma,
buffer_size=buffer_size,
batch_size=batch_size,
num_neurons=num_neurons,
num_layers=num_layers,
n_agents=n_agents,
shape=shape,
train_envs=train_envs,
eval_envs=eval_envs,
project_path=project_path,
total_episodes=total_episodes,
measure_intergroup_alignment=True,
n_trials=10)
# train
group.learn()
# evaluate
evaluate_project(project_path)
if __name__ == "__main__":
env_config = {
"seed": None,
"recipe_book_path": None,
"feature_type": "one_hot",
"shuffle_features": False,
"random_feature_size": 300,
"max_depth": 8,
"split": "by_recipe",
"train_ratio": 1.0,
"num_distractors": 0,
"uniform_distractors": False,
"max_mix_steps": 8,
"subgoal_rewards": True,
"proportional": True}
top_dir = "projects"
# reproduce experiments analysed in the main paper
run_all_main()