Skip to content

Coding Conventions

Tim Hallett edited this page Oct 12, 2021 · 2 revisions

When developing a disease module please refer to the checklist for developing a disease module The main coding conventions are detailed in skeleton.py These are additional conventions that have been agreed that cannot be represented in that file

File location and names

  • main module definition in /src/tlo/methods/
  • resource files in /resources/ [filename prefix ResourceFile_] (or consider making a folder if there are many files).
  • pytest in /tests/ [filename prefix test]
  • write-ups in docs/write-ups (pointed to in docs/write-up.rst): the filename should be the same as the module it describes.
  • analysis scripts in /src/scripts/YourModuleName/ [and this should expect to be run from the root path] [filename prefix analysis_]
  • files used formatting in /src/scripts/data file processing/ [filename prefix formatting]
  • outputs made at runtime (logfiles, figures etc) in /outputs/

NB. In all cases use Path() objects to make the identification of folders work well on both Mac and PC

Event naming and timing

If the disease module is driven by a regular recurring population-level event that will instigate transmission events, progression of disease etc:

  • Call the event ModuleName_Poll
  • The first of these events should occur on the first day of the simulation
  • This event can occur as regularly as you would like - but code the probabilities of events happening such that you can change this frequency later on.
  • Make sure that not all the things are changing on the same date.

A disease module will typically have a logging event that occurs at regular intervals to produce summary statistics for the population.

  • Call the event ModuleName_LoggingEvent
  • The first of these events should occur on the first day of the simulation

Using random numbers

Always use the module's random number generators (self.rng in the module and self.module.rng in the events)

Interacting with the Demography Module

  • Do not kill anyone! (never change the is_alive property in the population.props data frame)
  • To kill someone, call do_death or schedule InstantaneousDeath

Interacting with HealthBurden Module

  • Look-up the DALY weight for your disease using get_daly_weight() and store these as a variable (do not hard code)
  • The report_daly_values() method will be called every month: report the average daly weight for each alive persons during the previous month.

Interacting with the HealthSystem Module

  • All HSI events must be named like: HSI_<Module_Name>_Description_Of_What_Happens_In_The_Event
  • There may be many HSI Events and some of these may be used by several disease modules.
  • HSI Events do not have to 'owned' by any particular disease module

Running the simulation

See for the example of running a single simulation here

Clone this wiki locally