class Sim(pars=None, datafile=None, label=None, popfile=None, popdict=None, people=None, version=None, hiv_datafile=None, art_datafile=None, **kwargs)[source]#

Bases: BaseSim



Count the number of people -- if it fails, assume none


load_data(datafile=None, **kwargs)[source]#

Load the data to calibrate against, if provided

initialize(reset=False, init_states=True, init_analyzers=True, **kwargs)[source]#

Perform all initializations on the sim.


Attempt to retrieve the current layer keys.

reset_layer_pars(layer_keys=None, force=False)[source]#

Reset the parameters to match the population.

  • layer_keys (list) – override the default layer keys (use stored keys by default)

  • force (bool) – reset the parameters even if they already exist


Handle layer parameters, since they need to be validated after the population creation, rather than before.


Check that 1/dt is an integer value, otherwise results and time vectors will have mismatching shapes. init_results explicitly makes this assumption by casting resfrequency = int(1/dt).


Some parameters can take multiple types; this makes them consistent.


validate_layers (bool) – whether to validate layer parameters as well via validate_layer_pars() – usually yes, except during initialization


Construct vectors things that keep track of time


Initial prevalence values can be supplied with different amounts of detail. Here we flesh out any missing details so that the initial prev values are by age and genotype. We also check the prevalence values are ok.


Initialize the genotype parameters

init_results(frequency='annual', add_data=True)[source]#

Create the main results structure. The prefix “n” is used for stock variables, i.e. counting the total number in any given state (sus/inf/etc) on any particular timestep

  • sim (hpv.Sim) – a sim

  • frequency (str or float) – the frequency with which to save results: accepts ‘annual’, ‘dt’, or a float which is interpreted as a fraction of a year, e.g. 0.2 will save results every 0.2 years

  • add_data (bool) – whether or not to add data to the result structures


Initialize and validate the interventions

init_people(popdict=None, init_states=False, reset=False, verbose=None, **kwargs)[source]#

Create the people and the network.

Use init_states=False for creating a fresh People object for use in future simulations

  • popdict (any) – pre-generated people of various formats.

  • init_states (bool) – whether to initialize states (default false when called directly)

  • reset (bool) – whether to regenerate the people even if they already exist

  • verbose (int) – detail to print

  • kwargs (dict) – passed to hpv.make_people()


Initialize the analyzers


Initialize immunity matrices and cumulative dysplasia


Initialize states, attributes, and parameters relating to HIV

init_states(age_brackets=None, init_hpv_prev=None, init_cin_prev=None, init_cancer_prev=None)[source]#

Initialize prior immunity and seed infections


Step through time and update values

run(do_plot=False, until=None, restore_pars=True, reset_seed=True, verbose=None, **kwargs)[source]#

Run the model once

finalize(verbose=None, restore_pars=True)[source]#

Compute final results


Perform final calculations on the results


Compute prevalence, incidence, and other states.

compute_summary(t=None, update=True, output=False, full=False, require_run=False)[source]#

Compute the summary dict and string for the sim. Used internally; see sim.summarize() for the user version.

  • t (int/str) – day or date to compute summary for (by default, the last point)

  • update (bool) – whether to update the stored sim.summary

  • output (bool) – whether to return the summary

  • require_run (bool) – whether to raise an exception if simulations have not been run yet

summarize(full=False, t=None, sep=None, output=False)[source]#

Print a medium-length summary of the simulation, drawing from the last time point in the simulation by default. Called by default at the end of a sim run. point in the simulation by default. Called by default at the end of a sim run. See also sim.disp() (detailed output) and sim.brief() (short output).

  • full (bool) – whether or not to print all results (by default, only cumulative)

  • t (int/str) – day or date to compute summary for (by default, the last point)

  • sep (str) – thousands separator (default ‘,’)

  • output (bool) – whether to return the summary instead of printing it


sim = hpv.Sim(label='Example sim', verbose=0) # Set to run silently # Run the sim
sim.summarize() # Print medium-length summary of the sim
sim.summarize(t=24, full=True) # Print a "slice" of all sim results on day 24
plot(*args, **kwargs)[source]#

Plot the outputs of the model


Compute fit between model and data.