metawards.Network

class metawards.Network(nodes: metawards._nodes.Nodes = None, to_links: metawards._links.Links = None, play: metawards._links.Links = None, weekend: metawards._links.Links = None, nnodes: int = 0, nlinks: int = 0, plinks: int = 0, max_nodes: int = 16384, max_links: int = 4194304, info: metawards._wardinfo.WardInfos = WardInfos(wards=[]), to_seed: List[int] = None, params: metawards._parameters.Parameters = None)[source]

This class represents a network of wards. The network comprises nodes (representing wards), connected with links which represent work (predictable) links. There are also additional links for play (unpredictable/random) and weekend

__init__(nodes: metawards._nodes.Nodes = None, to_links: metawards._links.Links = None, play: metawards._links.Links = None, weekend: metawards._links.Links = None, nnodes: int = 0, nlinks: int = 0, plinks: int = 0, max_nodes: int = 16384, max_links: int = 4194304, info: metawards._wardinfo.WardInfos = WardInfos(wards=[]), to_seed: List[int] = None, params: metawards._parameters.Parameters = None) → None

Methods

__init__(nodes, to_links, play, weekend, …)
add_distances([distance_function]) Read in the positions of all of the nodes (wards) and calculate the distances of the links.
assert_sane(profiler) Assert that this network is sane.
build(params, calculate_distances[, …]) Builds and returns a new Network that is described by the passed parameters.
get_min_max_distances(nthreads[, profiler]) Calculate and return the minimum and maximum distances between nodes in the network
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
rescale_play_matrix(nthreads[, profiler]) Rescale the play matrix
reset_everything(nthreads[, profiler]) Resets the network ready for a new run of the model
run(population, output_dir, seed, nsteps, …) Run the model simulation for the passed population.
update(params, nthreads, profile) Update this network with a new set of parameters.

Attributes

info The metadata for all of the wards
max_links The maximum allowable number of links in the network
max_nodes The maximum allowable number of nodes in the network
nlinks The number of links in the network
nnodes The number of nodes in the network
nodes The list of nodes (wards) in the network
params The parameters used to generate this network
play The links between nodes (play)
plinks The number of play links in the network
to_links The links between nodes (work)
to_seed To seed provides additional seeding information
weekend The links between nodes (weekend)
add_distances(distance_function=None, nthreads: int = 1)[source]

Read in the positions of all of the nodes (wards) and calculate the distances of the links.

Optionally you can specify the function to use to read the positions and calculate the distances. By default this is mw.utils.add_wards_network_distance

assert_sane(profiler: None)[source]

Assert that this network is sane. This checks that the network is laid out correctly in memory and that it doesn’t have anything unexpected. Checking here will prevent us from having to check every time the network is accessed

static build(params: metawards._parameters.Parameters, calculate_distances: bool = True, build_function=None, distance_function=None, max_nodes: int = 16384, max_links: int = 4194304, nthreads: int = 1, profile: bool = True, profiler=None)[source]

Builds and returns a new Network that is described by the passed parameters. If ‘calculate_distances’ is True, then this will also read in the ward positions and add the distances between the links.

Optionally you can supply your own function to build the network, by supplying ‘build_function’. By default, this is metawards.utils.build_wards_network.

Optionally you can supply your own function to read and calculate the distances by supplying ‘build_function’. By default this is metawards.add_wards_network_distance

The network is built in allocated memory, so you need to specify the maximum possible number of nodes and links. The memory buffers will be shrunk back after building.

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

Calculate and return the minimum and maximum distances between nodes in the network

info = WardInfos(wards=[])

The metadata for all of the wards

initialise_infections(nthreads: int = 1)[source]

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

The maximum allowable number of links in the network

max_nodes = 16384

The maximum allowable number of nodes in the network

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

Move the population from play to work

The number of links in the network

nnodes = 0

The number of nodes in the network

nodes = None

The list of nodes (wards) in the network

params = None

The parameters used to generate this network

play = None

The links between nodes (play)

The number of play links in the network

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

Rescale the play matrix

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

Resets the network ready for a new run of the model

run(population: metawards._population.Population, output_dir: metawards._outputfiles.OutputFiles, seed: int = None, nsteps: int = None, profile: bool = True, s: int = None, nthreads: int = None, iterator=None, extractor=None, profiler=None)[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).

s is used to select the ‘to_seed’ entry to seed the nodes

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
  • profile (bool) – Whether or not to profile the model run and print out the results
  • profiler (Profiler) – The profiler to use - a new one is created if one isn’t passed
  • s (int) – Index of the seeding parameter to use
  • 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

The links between nodes (work)

to_seed = None

To seed provides additional seeding information

update(params: metawards._parameters.Parameters, nthreads: int = 1, profile: bool = False)[source]

Update this network with a new set of parameters. 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.

weekend = None

The links between nodes (weekend)