MRC-CSO-SPHSU / UKSEABMLib.jl

MIT License
1 stars 1 forks source link

Return values of simulation functions #29

Closed AtiyahElsheikh closed 1 year ago

AtiyahElsheikh commented 1 year ago

continuing #2

Summary:

doX!(*)

to return named tuple as outputs, i.e.

output1 = ... , output2 = ... , etc.

Particularly useful would be to return the indices of a concerned sub-population, e.g.

deads = .. , indexInPeople = ...

Here indexInPeople gives the indices of deads in a given population.

AtiyahElsheikh commented 1 year ago

The caller can retain a particular output easily, e.g.

function doDeaths(...) 
   ...
   return (deads = .. , deadsind = ...) 
end

The caller

(; deadsind) = doDeaths(model, allParameters(model))

AtiyahElsheikh commented 1 year ago

Functions s.a. doDeaths and doBirths create arrays of references every iteration. Avoiding this seems to significantly improve the memory usage and performance.

Therefore it is desired to allow function calls that don't return any output and performs the desired operation in place. This is realized by additional traits type NoReturn or WithReturn, .e.g. the default behavior of dodeaths:

dodeaths!(model, time) = 
    dodeaths!(model, time, AlivePopulation(), NoReturn())

Alternatively the function call

dodeaths!(model, time, AlivePopulation(), WithReturn())

returns outputs.

It is also thinkable to allow outputs to be placed in the first argument. This is can be done when needed.

AtiyahElsheikh commented 1 year ago

instead of traits, the API looks now as follows:

the third argument, popfeature, is related to #21

ret can take one of the following values: