-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulations_cluster.jl
executable file
·145 lines (111 loc) · 6.05 KB
/
simulations_cluster.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
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
using Distributed
using Base.Filesystem
using DataFrames
using CSV,Statistics,Query,ClusterManagers
using Dates
using DelimitedFiles
## load the packages by covid19abm
#using covid19abm
#addprocs(4, exeflags="--project=.")
#@everywhere using covid19abm
addprocs(SlurmManager(500), N=16, topology=:master_worker, exeflags = "--project=.")
@everywhere using Parameters, Distributions, StatsBase, StaticArrays, Random, Match, DataFrames
@everywhere include("covid19abm.jl")
@everywhere const cv=covid19abm
function run(myp::cv.ModelParameters, nsims=1000, folderprefix="./")
println("starting $nsims simulations...\nsave folder set to $(folderprefix)")
#dump(myp)
# will return 6 dataframes. 1 total, 4 age-specific
cdr = pmap(1:nsims) do x
cv.runsim(x, myp)
end
println("simulations finished")
println("total size of simulation dataframes: $(Base.summarysize(cdr))")
## write the infectors
## write contact numbers
#writedlm("$(folderprefix)/ctnumbers.dat", [cdr[i].ct_numbers for i = 1:nsims])
## stack the sims together
allag = vcat([cdr[i].a for i = 1:nsims]...)
working = vcat([cdr[i].work for i = 1:nsims]...)
ag1 = vcat([cdr[i].g1 for i = 1:nsims]...)
ag2 = vcat([cdr[i].g2 for i = 1:nsims]...)
ag3 = vcat([cdr[i].g3 for i = 1:nsims]...)
ag4 = vcat([cdr[i].g4 for i = 1:nsims]...)
ag5 = vcat([cdr[i].g5 for i = 1:nsims]...)
ag6 = vcat([cdr[i].g6 for i = 1:nsims]...)
ag7 = vcat([cdr[i].g7 for i = 1:nsims]...)
mydfs = Dict("all" => allag, "ag1" => ag1, "ag2" => ag2, "ag3" => ag3, "ag4" => ag4, "ag5" => ag5, "ag6" => ag6,"ag7" => ag7, "working"=>working)
#mydfs = Dict("all" => allag, "working"=>working, "kids"=>kids)
#mydfs = Dict("all" => allag)
#c1 = Symbol.((:LAT, :PRE, :MILD, :INF, :HOS, :ICU, :DED,:LAT2, :PRE2, :MILD2, :INF2, :HOS2, :ICU2, :DED2,:LAT3, :PRE3, :MILD3, :INF3, :HOS3, :ICU3, :DED3), :_INC)
c1 = Symbol.((:LAT, :MILD, :INF, :HOS, :ICU, :DED,:LAT2, :MILD2, :INF2, :HOS2, :ICU2, :DED2,:LAT3, :MILD3, :INF3, :HOS3, :ICU3, :DED3), :_INC)
#c2 = Symbol.((:LAT, :HOS, :ICU, :DED,:LAT2, :HOS2, :ICU2, :DED2,:LAT3, :HOS3, :ICU3, :DED3), :_PREV)
#c2 = Symbol.((:LAT, :HOS, :ICU, :DED,:LAT2, :HOS2, :ICU2, :DED2), :_PREV)
for (k, df) in mydfs
println("saving dataframe sim level: $k")
# simulation level, save file per health status, per age group
#for c in vcat(c1..., c2...)
for c in vcat(c1...)
#for c in vcat(c2...)
udf = unstack(df, :time, :sim, c)
fn = string("$(folderprefix)/simlevel_", lowercase(string(c)), "_", k, ".dat")
CSV.write(fn, udf)
end
println("saving dataframe time level: $k")
# time level, save file per age group
#yaf = compute_yearly_average(df)
#fn = string("$(folderprefix)/timelevel_", k, ".dat")
#CSV.write(fn, yaf)
end
writedlm(string(folderprefix,"/R01.dat"),[cdr[i].R0 for i=1:nsims])
writedlm(string(folderprefix,"/year_of_death.dat"),hcat([cdr[i].vector_dead for i=1:nsims]...))
writedlm(string(folderprefix,"/npcr.dat"),hcat([cdr[i].npcr for i=1:nsims]...))
writedlm(string(folderprefix,"/nra.dat"),hcat([cdr[i].nra for i=1:nsims]...))
writedlm(string(folderprefix,"/niso_t_p.dat"),hcat([cdr[i].niso_t_p for i=1:nsims]...))
writedlm(string(folderprefix,"/niso_t_w.dat"),hcat([cdr[i].niso_t_w for i=1:nsims]...))
writedlm(string(folderprefix,"/niso_f_p.dat"),hcat([cdr[i].niso_f_p for i=1:nsims]...))
writedlm(string(folderprefix,"/niso_f_w.dat"),hcat([cdr[i].niso_f_w for i=1:nsims]...))
writedlm(string(folderprefix,"/nleft.dat"),hcat([cdr[i].nleft for i=1:nsims]...))
writedlm(string(folderprefix,"/totalisog.dat"),vcat([cdr[i].giso for i=1:nsims]))
writedlm(string(folderprefix,"/totalisow.dat"),vcat([cdr[i].wiso for i=1:nsims]))
return mydfs
end
function create_folder(ip::cv.ModelParameters,province="ontario")
#RF = string("heatmap/results_prob_","$(replace(string(ip.β), "." => "_"))","_vac_","$(replace(string(ip.vaccine_ef), "." => "_"))","_herd_immu_","$(ip.herd)","_$strategy","cov_$(replace(string(ip.cov_val)))") ##
main_folder = "/data/thomas-covid/testing_canada"
#main_folder = "."
secondaryfolder = string(main_folder,"/fmild_$(ip.fmild)_fwork_$(ip.fwork)") ##
RF = string(secondaryfolder,"/results_prob_","$(replace(string(ip.β), "." => "_"))","_herd_immu_","$(ip.herd)","_idx_$(ip.file_index)_$(province)_strain_$(ip.strain)_scen_$(ip.scenariotest)_test_$(ip.test_ra)_eb_$(ip.extra_booster)_size_$(ip.size_threshold)") ##
if !Base.Filesystem.isdir(secondaryfolder)
Base.Filesystem.mkpath(secondaryfolder)
end
if !Base.Filesystem.isdir(RF)
Base.Filesystem.mkpath(RF)
end
return RF
end
function run_param_scen_cal(b::Float64,province::String="ontario",h_i::Int64 = 0,ic1::Int64=1,strains::Int64 = 1,index::Int64 = 0,scen::Int64 = 0,tra::Int64 = 0,eb::Int64 = 0,wpt::Int64 = 100,mt::Int64=300,test_time::Int64 = 1,test_dur::Int64=112,mildcomp::Float64 = 1.0,workcomp::Float64 = 1.0,dayst::Vector{Int64} = [1;4],trans_omicron::Float64 = 1.0,immu_omicron::Float64 = 0.0,rc=[1.0],dc=[1],nsims::Int64=500)
@everywhere ip = cv.ModelParameters(β=$b,
herd = $(h_i),start_several_inf=true,
initialinf = $ic1,
file_index = $index,
modeltime=$mt, prov = Symbol($province),
time_change_contact = $dc,
change_rate_values = $rc,
n_boosts = 1,
scenariotest = $scen,
extra_booster = $eb,
size_threshold = $wpt,
test_ra = $tra,
testing_days = $dayst,
strain = $strains,
immunity_omicron = $immu_omicron,
transmissibility_omicron = $trans_omicron,
start_testing = $test_time,
test_for = $test_dur,
fmild = $mildcomp,
fwork = $workcomp)
folder = create_folder(ip,province)
run(ip,nsims,folder)
#run(ip,4,folder)
end