Cohort

This module provides support for population models. For each cohort, a separate Model should be defined (a single Process instance may be used for multiple cohorts). A Cohort instance should be created for each cohort. These objects can then be used to create a PopulationModel, which can be run with almost exactly the same arguments as a regular Model.

class miscore.tools.cohort.Cohort(name, model=None, universes=None)[source]

A cohort to be used in a PopulationModel.

Parameters:
  • name (str) – The name of the cohort. This name will be used by PopulationModel to categorize the output.

  • model (Model | None) – The model Model belonging to this cohort.

  • universes (Sequence[Universe] | None) – Instead of passing a model, a list of Universe objects can be passed. These universes will be used to create a Model.

Raises:

ValueError – Raises an error if both model and universes are passed or if none of these two arguments is passed.

class miscore.tools.cohort.PopulationModel(cohorts)[source]

A population model, consisting of one or more Cohort objects. This model can be run with almost exactly the same arguments as a regular Model.

Parameters:

cohorts (Sequence[Cohort]) – The cohorts constituting the model. Each Cohort should have a unique name.

Raises:

AssertionError – Duplicate cohort name.

run(n, cores=None, seed=None, seeds_properties=None, seeds_properties_tmp=None, seeds_random=None, properties=None, block_size=2000, verbose=False, **run_arguments)[source]

Runs the model and returns the result.

Parameters:
  • n (Dict[str, SupportsInt]) – A dictionary mapping each cohort name to the number of individuals to simulate.

  • cores (int | str | None) – The number of CPU processes to create to run the model. If None (the default), no new processes are created. If ‘all’, a process is created for each detected CPU.

  • seed (int | None) – If required seeds are missing in ‘seeds_properties’, ‘seeds_properties_tmp’ or ‘seeds_random’, these seeds will be drawn using a random number generator seeded with ‘seed’.

  • seeds_properties (Dict[str, int] | None) – The seeds to use for the properties() method of each Process in the model. If no seed is provided for a Process that implemented the properties() method, a random seed is drawn. All used seeds are stored in the returned Result.

  • seeds_properties_tmp (Dict[str, int] | None) – The seeds to use for the properties_tmp() method of each Process in the model. If no seed is provided for a Process that implemented the properties_tmp() method, a random seed is drawn. All used seeds are stored in the returned Result.

  • seeds_random (Dict[str, int] | None) – The seeds to use for the random number generators accessible during the simulation. If no seed is provided for a random number generator, a random seed is drawn. All used seeds are stored in the returned Result.

  • properties (Dict[str, Dict[str, ndarray]] | None) – Maps cohort name to a dictionary with individuals properties.

  • block_size (int) – During a simulation, the population is split up in ‘blocks’. For each block and each process, a seed is generated and passed to the properties_tmp() method of each process to use for the generation of temporary properties. The number of individuals in each block is equal to ‘block_size’. If this variable is set to a too high value, memory issues may arise. However, low values may decrease performance. By default, this variable is set to 2000.

  • verbose (bool) – Whether or not to print progress during the simulation. Set to False by default.

  • run_arguments – Any other keyword arguments will be passed to run().

Return type:

Result

Returns:

The output of the simulation.

Raises:
  • ValueError – Raised if cohorts in n are not defined in the model.

  • ValueError – Raised when the sum of n is not positive.

  • ValueError – Raised when the cores parameter is not an integer.