-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_exp.jl
102 lines (78 loc) · 2.2 KB
/
run_exp.jl
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
using Distributed, Serialization, ArgParse, Dates
# using DataStructures
# Parse arguments
s = ArgParseSettings()
@add_arg_table s begin
"--chunk"
help = "TODO"
arg_type = Int
default = 1
"--no_chunks"
help = "TODO"
arg_type = Int
default = 1
"config"
help = "configuration file"
required = true
end
parsed_args = parse_args(s)
config = parsed_args["config"]
chunk = parsed_args["chunk"]
no_chunks = parsed_args["no_chunks"]
if chunk > no_chunks
println("ERROR: chunk has to be <= no_chunks")
exit(1)
end
include("model/model.jl")
include("$config")
print("Preparing workers... ")
@everywhere function load_config(config)
include(config)
end
@everywhere function execute_task(task)
println("Running ", task[:exp_name], "/", task[:run], "...")
model = initialize(task[:properties], num_consumers, num_producers)
agent_data, model_data = run!(model, dummystep, model_step!, iterations; adata = adata, mdata = mdata, when=when_collect)
return Dict(:exp_name => task[:exp_name], :run => task[:run], :agent_data => agent_data, :model_data => model_data)
end
# Create list of task ids
all_task_ids = Vector{String}()
for (exp_name, props) in experiments
for run in 1:no_runs
push!(all_task_ids, "$exp_name-$run")
end
end
sort!(all_task_ids)
tasks_per_junk = ceil(length(all_task_ids) / no_chunks)
from = Int((chunk-1)*tasks_per_junk+1)
to = Int(min(from+tasks_per_junk-1, length(all_task_ids)))
my_task_ids = all_task_ids[from:to]
# Create list of tasks matching ids in my_task_ids
tasks = Dict[]
for (exp_name, props) in experiments
for run in 1:no_runs
if "$exp_name-$run" in my_task_ids
properties = deepcopy(baseline_properties)
properties[:run_id] = run
for (prop, value) in props
properties[prop] = value
end
task = Dict(:exp_name => exp_name, :run => run, :properties => properties)
push!(tasks, task)
end
end
end
println("DONE")
print("Loading config... ")
@everywhere include("model/model.jl")
for i in workers()
@spawnat i load_config("$config")
end
println("DONE")
# run parallel
@time results = pmap(execute_task, tasks)
# Save data
if !isdir(folder)
mkdir(folder)
end
serialize("$folder/data-$chunk.dat", results)