metawards.Networks

class metawards.Networks(overall: Optional[metawards._network.Network] = None, subnets: List[metawards._network.Network] = <factory>, demographics: Optional[metawards._demographics.Demographics] = None)[source]

This is a combination of Network objects which together represent an entire diverse population. Each individual Network is used to model the disease outbreak within a single demographic of the population. Multiple demographics are modelled by combining multiple networks. Special merge functions enable joint FOIs to be calculated, through which an outbreak in one network can cross-infect a demographic in another network.

The Networks can be very independent, and don’t necessarily need to have the same links. However, it is assumed (and checked) that each network will have the same nodes.

__init__(overall: Optional[metawards._network.Network] = None, subnets: List[metawards._network.Network] = <factory>, demographics: Optional[metawards._demographics.Demographics] = None) None

Methods

__delattr__(name, /)

Implement delattr(self, name).

__dir__()

Default dir() implementation.

__eq__(other)

Return self==value.

__format__(format_spec, /)

Default object formatter.

__ge__(value, /)

Return self>=value.

__getattribute__(name, /)

Return getattr(self, name).

__gt__(value, /)

Return self>value.

__init__([overall, subnets, demographics])

__init_subclass__

This method is called when a class is subclassed.

__le__(value, /)

Return self<=value.

__lt__(value, /)

Return self<value.

__ne__(value, /)

Return self!=value.

__new__(**kwargs)

__reduce__()

Helper for pickle.

__reduce_ex__(protocol, /)

Helper for pickle.

__repr__()

Return repr(self).

__setattr__(name, value, /)

Implement setattr(self, name, value).

__sizeof__()

Size of object in memory, in bytes.

__str__()

Return str(self).

__subclasshook__

Abstract classes can override this to customize issubclass().

aggregate([profiler, nthreads])

Aggregate all of the sub-network population infection data so that this is available in the overall network

assert_sane(profiler)

Assert that the networks is sane.

build(network, demographics[, profiler, ...])

Build the set of networks that will model the passed demographics based on the overall population model in the passed network

copy()

Return a copy of this Networks.

initialise_infections([nthreads])

Initialise and return the space that will be used to track infections

move_from_play_to_work([nthreads, profiler])

Move the population from play to work

num_demographics()

Return the number of demographics

rescale_play_matrix([nthreads, profiler])

Rescale the play matrix

reset_everything([nthreads, profiler])

Resets the networks ready for a new run of the model

run(population, output_dir[, seed, nsteps, ...])

Run the model simulation for the passed population.

update(params[, demographics, population, ...])

Update this network with a new set of parameters (and optionally demographics).

Attributes

__annotations__

__dataclass_fields__

__dataclass_params__

__dict__

__doc__

__hash__

__module__

__weakref__

list of weak references to the object (if defined)

demographics

Metadata about each of the demographics being modelled.

overall

The overall Network, which contains a combination of all of the sub-networks.

params

The overall parameters that are then specialised for the different demographics.

subnets

The list of Networks, one for each demographic, ordered in the same order as the "Demographics" object.

__eq__(other)

Return self==value.

__hash__ = None
__init__(overall: Optional[metawards._network.Network] = None, subnets: List[metawards._network.Network] = <factory>, demographics: Optional[metawards._demographics.Demographics] = None) None
__repr__()

Return repr(self).

aggregate(profiler=None, nthreads: int = 1)[source]

Aggregate all of the sub-network population infection data so that this is available in the overall network

assert_sane(profiler: None)[source]

Assert that the networks is sane. This checks that the networks and all of the demographic sub-networks are laid out correctly in memory and that they don’t have anything unexpected. Checking here will prevent us from having to check every time the networks are accessed

static build(network: metawards._network.Network, demographics: metawards._demographics.Demographics, profiler=None, nthreads: int = 1)[source]

Build the set of networks that will model the passed demographics based on the overall population model in the passed network

Parameters
  • network (Network) – The overall population model - this contains the base parameters, wards, work and play links that define the model outbreak

  • demographics (Demographics) – Information about each of the demographics to be modelled. Note that the sum of the “work” and “play” populations across all demographics must be 1.0 in all wards in the model

  • profiler (Profiler) – Optional profiler used to profile this build

  • nthreads (int) – Number of threads over which to distribute the work

Returns

networks – The set of Networks that represent the model run over the full set of different demographics

Return type

Networks

copy()[source]

Return a copy of this Networks. Use this to hold a copy of the networks that you can use to reset between runs

demographics: metawards._demographics.Demographics = None

Metadata about each of the demographics being modelled. This is None if only a single demographic is modelled

initialise_infections(nthreads: int = 1)[source]

Initialise and return the space that will be used to track infections

move_from_play_to_work(nthreads: int = 1, profiler=None)[source]

Move the population from play to work

num_demographics() int[source]

Return the number of demographics

overall: metawards._network.Network = None

The overall Network, which contains a combination of all of the sub-networks. This is used for summary analysis and also as a means of merging and distributing data between sub-networks

property params: int

The overall parameters that are then specialised for the different demographics. Note that this returns a copy, so changing this will not change any parameters in the networks

rescale_play_matrix(nthreads: int = 1, profiler=None)[source]

Rescale the play matrix

reset_everything(nthreads: int = 1, profiler=None)[source]

Resets the networks ready for a new run of the model

run(population: metawards._population.Population, output_dir: metawards._outputfiles.OutputFiles, seed: Optional[int] = None, nsteps: Optional[int] = None, nthreads: Optional[int] = None, iterator=None, extractor=None, mover=None, mixer=None, profiler=None) metawards._population.Population[source]

Run the model simulation for the passed population. The random number seed is given in ‘seed’. If this is None, then a random seed is used.

All output files are written to ‘output_dir’

The simulation will continue until the infection has died out or until ‘nsteps’ has passed (keep as ‘None’ to prevent exiting early).

Parameters
  • population (Population) – The initial population at the start of the model outbreak. This is also used to set start date and day of the model outbreak

  • output_dir (OutputFiles) – The directory to write all of the output into

  • seed (int) – The random number seed used for this model run. If this is None then a very random random number seed will be used

  • nsteps (int) – The maximum number of steps to run in the outbreak. If None then run until the outbreak has finished

  • profiler (Profiler) – The profiler to use - a new one is created if one isn’t passed

  • nthreads (int) – Number of threads over which to parallelise this model run

  • iterator (function) – Function that is called at each iteration to get the functions that are used to advance the model

  • extractor (function) – Function that is called at each iteration to get the functions that are used to extract data for analysis or writing to files

  • mixer (function) – Function that is called to mix the data calculated for each of the sub-networks for the different demographics and merge it together so that this is shared

  • mover (function) – Function that is called to move the population between different demographics

Returns

population – The final population at the end of the run

Return type

Population

subnets: List[metawards._network.Network]

The list of Networks, one for each demographic, ordered in the same order as the “Demographics” object. This is empty if only a single demographic is modelled

update(params: metawards._parameters.Parameters, demographics=None, population=None, nthreads: int = 1, profiler=None)[source]

Update this network with a new set of parameters (and optionally demographics).

This is used to update the parameters for the network for a new run. The network will be reset and ready for a new run.

Parameters
  • params (Parameters) – The new parameters with which to update this Network

  • demographics (Demographics) – The new demographics with which to update this Network. Note that this will return a Network object that contains the specilisation of this Network

  • nthreads (int) – Number of threads over which to parallelise this update

  • profiler (Profiler) – The profiler used to profile this update

Returns

network – Either this Network after it has been updated, or the resulting Networks from specialising this Network using Demographics

Return type

Network or Networks