Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 59 additions & 50 deletions benchmark/benchmark.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module MocosSimBenchmark

using MocosSim
using CodecZlib
using FileIO
Expand All @@ -7,44 +9,6 @@ using FixedPointNumbers
using Random
using Profile


individuals_df = load( (@__DIR__) * "/wroclaw_v4.jld2", "individuals_df")
rng = Random.MersenneTwister(0);

@info "creating state"
@time state = MocosSim.SimState(nrow(individuals_df))

@info "loading data"
@time params = MocosSim.load_params(
population=individuals_df,
mild_detection_prob=0.4,
backward_tracing_prob=0.2,
forward_tracing_prob=0.2,
constant_kernel_param=0.7425,
household_kernel_param=0.07,
british_strain_multiplier=1.7,

age_coupling_thresholds=[0, 18, 40],
age_coupling_weights=[1.1 1.2 1.3;
2.1 2.2 2.3;
3.1 3.2 3.3],
age_coupling_use_genders=false,
age_coupling_param=1.0,

infection_modulation_name="TanhModulation",
infection_modulation_params=(
scale=12500,
loc=300000,
weight_detected=1,
weight_deaths=0,
limit_value=0.545455
),

forward_detection_delay=1.75,
backward_detection_delay=1.75,
testing_time=3.0
);

mutable struct Callback
max_time::Float64
num_events::Int
Expand All @@ -55,17 +19,62 @@ function (cb::Callback)(event::MocosSim.Event, ::MocosSim.SimState, ::MocosSim.S
MocosSim.time(event) < cb.max_time
end

@info "initializing state"
@time MocosSim.reset!(state, MersenneTwister(0))
@time MocosSim.InstantOutsideCases(;num_infections=100)(state, params)
function run()
individuals_df = load( (@__DIR__) * "/wroclaw_v4.jld2", "individuals_df")

@info "creating state"
@time state = MocosSim.SimState(nrow(individuals_df))

@info "loading data"
@time params = MocosSim.load_params(
population=individuals_df,
mild_detection_prob=0.4,
backward_tracing_prob=0.2,
forward_tracing_prob=0.2,
constant_kernel_param=0.7425,
household_kernel_param=0.07,
british_strain_multiplier=1.7,

age_coupling_thresholds=[0, 18, 40],
age_coupling_weights=[1.1 1.2 1.3;
2.1 2.2 2.3;
3.1 3.2 3.3],
age_coupling_use_genders=false,
age_coupling_param=1.0,

infection_modulation_name="TanhModulation",
infection_modulation_params=(
scale=12500,
loc=300000,
weight_detected=1,
weight_deaths=0,
limit_value=0.545455
),

forward_detection_delay=1.75,
backward_detection_delay=1.75,
testing_time=3.0
);

@info "initializing state"
@time MocosSim.reset!(state, MersenneTwister(0))
@time MocosSim.InstantOutsideCases(;num_infections=100)(state, params)

@info "warm-up"
cb = Callback(50, 0)
@time MocosSim.simulate!(state, params, cb)

@info "events executed = $(cb.num_events), simtime=$(state.time), measuring allocations"

cb = Callback(100, 0)
Profile.clear_malloc_data()
@time MocosSim.simulate!(state, params, cb)
end

precompile(MocosSim.simulate!, (MocosSim.SimState, MocosSim.SimParams, Callback))
precompile(run, ())

end

@info "warm-up"
cb = Callback(50, 0)
@time MocosSim.simulate!(state, params, cb)
@info "events executed = $(cb.num_events), simtime=$(state.time)"
MocosSimBenchmark.run()

@info "measuring allocations"
cb = Callback(100, 0)
Profile.clear_malloc_data()
@time MocosSim.simulate!(state, params, cb)
@info "events executed = $(cb.num_events)"
2 changes: 2 additions & 0 deletions src/MocosSim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@ function simulate!(state::SimState, params::SimParams, callback)
nothing
end

precompile(simulate!, (SimState, SimParams))

end #module