SciCompMod / memilio

Modular spatio-temporal models for epidemic and pandemic simulations
https://scicompmod.github.io/memilio/
Apache License 2.0
55 stars 16 forks source link

Reduce use of methods of StateAgeFunction in IDE model to reduce run time #1117

Closed annawendler closed 2 months ago

annawendler commented 2 months ago

Motivation / Current Behaviour

In this issue we want to examine if it is better regarding run time to reduce the use of the methods of StateAgeFunction when solving the model. We proceed as follows. See run time results in the comments.

  1. Currently, whenever we calculate a sum to compute flows or compartments, we determine the support_max via the corresponding StateAgeFunction. We have observed that the StateAgeFunction is accessed a lot in simulations and this may be an issue regarding performance.
  2. When computing the flows, the derivative is always evaluated at the same time points. So far, we have computed the derivative in every time step. Now, we do this once at the beginning, store the results in some vector and then access this vector in each time step. Analogously, we do this for the contributions of survival functions and transition probabilities in the force of infection term.

Enhancement description

Compute the necessary support_max values once at the beginning of the simulation and store them. We want to try out if this has an impact on performance.

Additional context

No response

Checklist

annawendler commented 2 months ago

To compare run times we did 10 simulations from t0=0 until tmax=50 on the HPDA cluster on an exclusive node (see also examples/ide_secir_time.cpp) in Release mode. After storing the necessary values for the support_max values (see 1.) and flows and the force of infection time (see 2.) we made the following measurements: For dt=1e-2:

For dt=1e-3:

We observe a decrease of 75.3% for dt=1e-2 and a decrease of 74.6% for dt=1e-3 in run time for the new implementation.