
2022-02-09

Mac-Theobio COVID Modelling Group
Mac-Theobio COVID Modelling Group
What if two days becomes two hours?
More time modelling and communicating, less time waiting for results
Need a bit more background before answering …
As models get more complex, quantities that looked like this …
… become more complex
What if a few weeks becomes an afternoon?
Forecasts are delivered quickly, resulting in bigger public health impact
TMB: Time difference of 7.8s R: Time difference of 1741.0s Speedup: 224x
But to be conservative we were seeing 60x speedups regularly
Does this mean that a workflow that took an hour, will now take one minute?
Not necessarily
Split up code into two sets:
Simple but important insight:
If the code that is not refactored takes \(x\) minutes to run, the fastest run time that could be achieved by refactoring is \(x\) minutes
Two type of code that are in the “Not refactored” set
Run-times of two sets of code, in different states
The total run-time before refactoring: \[ t_{\text{before}} = r_{\text{before}} + r_{\text{not_done}} \]
The total run-time after refactoring: \[ t_{\text{after}} = r_{\text{after}} + r_{\text{not_done}} \]
Dimensionless measures of this system:
Expression for the realized speedups
Estimate fraction refactored, \(\rho\), by rearranging Amdahl’s Law
\[ \rho = \frac{1 - \frac{1}{\tau}}{1 - \frac{1}{\alpha}} \approx 0.85 \]
Has the performance optimization allowed people to do things that they couldn’t do before?
I just wanted to send out this email to express how impressed/happy I am running the new TMB version.
It is insanely fast and definitely saves me hours everyday and allows me to explore more scenarios.
I can do many more things I couldn’t before due to computation limitations.
Thank you, you guys are heroes!
state = c(S = 20000, I = 100, R = 0) params = c(gamma = 0.06, beta = 0.15, N = sum(state))
sir_model = (init_model(
params, state,
start_date = "2000-01-01",
end_date = "2000-05-01",
)
%>% add_rate("S", "I", ~ (1/N) * (beta) * (I))
%>% add_rate("I", "R", ~ (gamma))
)
(sir_model %>% simulate %>% filter(variable %in% names(state)) %>% rename(compartment = variable, state = value) %>% mutate(compartment = factor(compartment, names(sir_model$state))) %>% ggplot + geom_line(aes(x = Date, y = state, colour = compartment)) )
(sir_model %>% simulate(format = 'wide') %>% rename(`Force of Infection` = S_to_I) %>% ggplot + geom_line(aes(x = Date, y = `Force of Infection`)) )
Create symbolic vectors and matrices
C = vec('Ca', 'Cp', '(Cm) * (1 - iso_m)', '(Cs) * (1 - iso_s)')
Use vectors and matrices to define rates
%>% add_rate("S", "E", sum(I * C * beta * inverse_N))
Keep things compact even when the model gets complex
%>% vec_rate( "S" %_% vax_cat, "E" %_% vax_cat, kronecker(vax_trans_red, t(baseline_trans_rates)) %*% Istate )
m = 5 # number of E boxes (chained_E_boxes = "E" %_% 1:m)
## [1] "E_1" "E_2" "E_3" "E_4" "E_5"
# sojourn through exposed compartments
%>% rep_rate(
chained_E_boxes[1:(m-1)],
chained_E_boxes[2:m],
~ (m) * (sigma)
)
Full example online