tlo.analysis.performance module
- class PerformanceMonitor(**kwargs)
Bases:
Module
- Register in simulation:
- PerformanceMonitor(log_perf=True,
log_perf_freq=2, log_pop_hash=True, save_sim=True, save_sim_freq=3, save_sim_on_end=True)
Construct a new disease module ready to be included in a simulation.
Initialises an empty parameters dictionary and module-specific random number generator.
- Parameters:
name – the name to use for this module. Defaults to the concrete subclass’ name.
- read_parameters(data_folder: str | Path) None
Read parameter values from file, if required.
Must be implemented by subclasses.
- Parameters:
data_folder – path of a folder supplied to the Simulation containing data files. Typically, modules would read a particular file within here.
- initialise_simulation(sim: Simulation) None
Get ready for simulation start.
Must be implemented by subclasses.
This method is called just before the main simulation loop begins, and after all modules have read their parameters and the initial population has been created. It is a good place to add initial events to the event queue.
- on_birth(mother_id: int, child_id: int) None
Initialise our properties for a newborn individual.
Must be implemented by subclasses.
This is called by the simulation whenever a new person is born.
- Parameters:
mother_id – the person id for the mother of this child (can be -1 if the mother is not identified).
child_id – the person id of new child
- on_simulation_end() None
This is called after the simulation has ended. Modules do not need to declare this.
- parameters
- class SaveSimulation(module, frequency_months)
Bases:
RegularEvent
,PopulationScopeEventMixin
Create a new regular event.
- Parameters:
module – the module that created this event
frequency (pandas.tseries.offsets.DateOffset) – the interval from one occurrence to the next (must be supplied as a keyword argument)
- apply(population)
Apply this event to the given target.
This is a no-op; subclasses should override this method.
- Parameters:
target – the target of the event
- class LogPerfProfile(module, frequency_months, do_hash)
Bases:
RegularEvent
,PopulationScopeEventMixin
Create a new regular event.
- Parameters:
module – the module that created this event
frequency (pandas.tseries.offsets.DateOffset) – the interval from one occurrence to the next (must be supplied as a keyword argument)
- apply(population)
Apply this event to the given target.
This is a no-op; subclasses should override this method.
- Parameters:
target – the target of the event
- make_pickle_filename(sim_date)
- profile_statistics(sim, do_hash)
- memory_statistics() dict[str, float]
Extract memory usage statistics in current process using psutil if available. Statistics are returned as a dictionary. If psutil not installed an empty dict is returned.
Key / value pairs are: memory_rss_MiB: float
Resident set size in mebibytes. The non-swapped physical memory the process has used.
- memory_vms_MiB: float
Virtual memory size in mebibytes. The total amount of virtual memory used by the process.
- memory_uss_MiB: float
Unique set size in mebibytes. The memory which is unique to a process and which would be freed if the process was terminated right now