Skip to main content

COVID-19 Agent-based Simulator

Project description

About Covasim

Covasim is a stochastic agent-based simulator for performing COVID-19 analyses. These include projections of indicators such as numbers of infections and peak hospital demand. Covasim can also be used to explore the potential impact of different interventions, including social distancing, school closures, testing, contact tracing, quarantine, and vaccination.

The scientific paper describing Covasim is available at http://paper.covasim.org. The recommended citation is:

Covasim: an agent-based model of COVID-19 dynamics and interventions. Kerr CC, Stuart RM, Mistry D, Abeysuriya RG, Rosenfeld R, Hart G, Núñez RC, Cohen JA, Selvaraj P, Hagedorn B, George L, Jastrzębski M, Izzo A, Fowler G, Palmer A, Delport D, Scott N, Kelly S, Bennette C, Wagner B, Chang S, Oron AP, Wenger E, Panovska-Griffiths J, Famulare M, Klein DJ (under review; posted 2020-05-15). medRxiv 2020.05.10.20097469; doi: https://doi.org/10.1101/2020.05.10.20097469.

The Covasim webapp is available at http://app.covasim.org, and the repository for it is available here.

Covasim was developed by the Institute for Disease Modeling, with additional contributions from the University of Copenhagen, the Burnet Institute, GitHub, and Microsoft.

Questions or comments can be directed to covasim@idmod.org, or on this project’s GitHub page. Full information about Covasim is provided in the documentation.

Background

Covasim has been used for analyses in over a dozen countries, both to inform policy decisions (including in the US, UK, and Australia), and as part of research studies. Academic papers that have been written using Covasim include:

  1. Controlling COVID-19 via test-trace-quarantine. Kerr CC, Mistry D, Stuart RM, Rosenfeld R, Hart G, Núñez RC, Selvaraj P, Cohen JA, Abeysuriya RG, George L, Hagedorn B, Jastrzębski M, Fagalde M, Duchin J, Famulare M, Klein DJ (under review; posted 2020-07-16). medRxiv 2020.07.15.20154765; doi: https://doi.org/10.1101/2020.07.15.20154765.

  2. Determining the optimal strategy for reopening schools, the impact of test and trace interventions, and the risk of occurrence of a second COVID-19 epidemic wave in the UK: a modelling study. Panovska-Griffiths J, Kerr CC, Stuart RM, Mistry D, Klein DJ, Viner R, Bonnell C (2020-08-03). Lancet Child and Adolescent Health S2352-4642(20) 30250-9. doi: https://doi.org/10.1016/S2352-4642(20)30250-9.

  3. Estimating and mitigating the risk of COVID-19 epidemic rebound associated with reopening of international borders in Vietnam: a modelling study. Pham QD, Stuart RM, Nguyen TV, Luong QC, Tran DQ, Phan LT, Dang TQ, Tran DN, Mistry D, Klein DJ, Abeysuriya RG, Oron AP, Kerr CC (2021-04-12). Lancet Global Health S2214-109X(21) 00103-0; doi: https://doi.org/10.1016/S2214-109X(21)00103-0.

  4. Modelling the impact of reducing control measures on the COVID-19 pandemic in a low transmission setting. Scott N, Palmer A, Delport D, Abeysuriya RG, Stuart RM, Kerr CC, Mistry D, Klein DJ, Sacks-Davis R, Heath K, Hainsworth S, Pedrana A, Stoove M, Wilson DP, Hellard M (in press; accepted 2020-09-02). Medical Journal of Australia [Preprint]; doi: https://doi.org/10.1101/2020.06.11.20127027.

  5. The role of masks, testing and contact tracing in preventing COVID-19 resurgences: a case study from New South Wales, Australia. Stuart RM, Abeysuriya RG, Kerr CC, Mistry D, Klein DJ, Gray R, Hellard M, Scott N (in press; accepted 2021-03-19). BMJ Open; doi: https://doi.org/10.1101/2020.09.02.20186742.

  6. The potential contribution of face coverings to the control of SARS-CoV-2 transmission in schools and broader society in the UK: a modelling study. Panovska-Griffiths J, Kerr CC, Waites W, Stuart RM, Mistry D, Foster D, Klein DJ, Viner R, Bonnell C (in press; accepted 2021-04-08). Nature Scientific Reports; doi: https://doi.org/10.1101/2020.09.28.20202937.

  7. Schools are not islands: Balancing COVID-19 risk and educational benefits using structural and temporal countermeasures. Cohen JA, Mistry D, Kerr CC, Klein DJ (under review; posted 2020-09-10). medRxiv 2020.09.08.20190942; doi: https://doi.org/10.1101/2020.09.08.20190942.

  8. COVID-19 reopening strategies at the county level in the face of uncertainty: Multiple Models for Outbreak Decision Support. Shea K, Borchering RK, Probert WJM, et al. (under review; posted 2020-11-05). medRxiv 2020.11.03.20225409; doi: https://doi.org/10.1101/2020.11.03.20225409.

  9. Preventing a cluster from becoming a new wave in settings with zero community COVID-19 cases. Abeysuriya RG, Delport D, Stuart RM, Sacks-Davis R, Kerr CC, Mistry D, Klein DJ, Hellard M, Scott N (under review; posted 2020-12-22). medRxiv 2020.12.21.20248595; doi: https://doi.org/10.1101/2020.12.21.20248595.

  10. Modelling the impact of reopening schools in early 2021 in the presence of the new SARS-CoV-2 variant in the UK. Panovska-Griffiths J, Kerr CC, Waites W, Stuart RM, Mistry D, Foster D, Klein DJ, Viner R, Bonnell C (under review; posted 2021-02-09). medRxiv 2021.02.07.21251287; doi: https://doi.org/10.1101/2021.02.07.21251287.

If you have written a paper or report using Covasim, we’d love to know about it! Please write to us here.

Requirements

Python 3.7 or 3.8 (64-bit). (Note: Python 2.7 and Python 3.9 are not supported.)

We also recommend, but do not require, installing Covasim in a virtual environment. For more information, see documentation for e.g. Anaconda.

Quick start guide

Install with pip install covasim. If everything is working, the following Python commands should bring up a plot:

import covasim as cv
sim = cv.Sim()
sim.run()
sim.plot()

Full installation instructions

If you would rather download the source code rather than using the pip package, follow these steps:

  1. Clone a copy of the repository. If you intend to make changes to the code, we recommend that you fork it first.

  2. (Optional) Create and activate a virtual environment.

  3. Navigate to the root of the repository and install the Covasim Python package using one of the following options:

    • For normal installation (recommended):

      pip install -e .
    • To install Covasim and optional dependencies (be aware this may fail since it relies on nonstandard packages):

      pip install -e .[full]

    The module should then be importable via import covasim as cv.

Usage examples

There are several examples in the examples folder. These can be run as follows:

  • python examples/simple.py

    This example creates a figure using default parameter values.

  • python examples/run_sim.py

    This shows a slightly more detailed example, including creating an intervention and saving to disk.

  • python examples/run_scenarios.py

    This shows a more complex example, including running an intervention scenario, plotting uncertainty, and performing a health systems analysis.

Other examples in that folder are taken from the tutorials.

Module structure

All core model code is located in the covasim subfolder; standard usage is import covasim as cv. The data subfolder is described below.

The model consists of two core classes: the Person class (which contains information on health state), and the Sim class (which contains methods for running, calculating results, plotting, etc.).

The structure of the covasim folder is as follows, roughly in the order in which the modules are imported, building from most fundamental to most complex:

  • version.py: Version, date, and license information.

  • requirements.py: A simple module to check that imports succeeded, and turn off features if they didn’t.

  • utils.py: Functions for choosing random numbers, many based on Numba, plus other helper functions.

  • misc.py: Miscellaneous helper functions.

  • settings.py: User-customizable options for Covasim (e.g. default font size).

  • defaults.py: The default colors, plots, etc. used by Covasim.

  • parameters.py: Functions for creating the parameters dictionary and loading the input data.

  • plotting.py: Plotting scripts, including Plotly graphs for the webapp (used in other Covasim classes, and hence defined first).

  • base.py: The ParsObj class, the fundamental class used in Covasim, plus basic methods of the BaseSim and BasePeople classes, and associated functions.

  • people.py: The People class, for handling updates of state for each person.

  • population.py: Functions for creating populations of people, including age, contacts, etc.

  • interventions.py: The Intervention class, for adding interventions and dynamically modifying parameters, and classes for each of the specific interventions derived from it.

  • immunity.py: The strain class, and functions for computing waning immunity and neutralizing antibodies.

  • sim.py: The Sim class, which performs most of the heavy lifting: initializing the model, running, and plotting.

  • run.py: Functions for running simulations (e.g. parallel runs and the Scenarios and MultiSim classes).

  • analysis.py: The Analyzers class (for performing analyses on the sim while it’s running), the Fit class (for calculating the fit between the model and the data), the TransTree class, and other classes and functions for analyzing simulations.

The data folder within the Covasim package contains loading scripts for the epidemiological data in the root data folder, as well as data on age distributions for different countries and household sizes.

Other folders

Please see the readme in each subfolder for more information.

Bin

This folder contains a command-line interface (CLI) version of Covasim; example usage:

covasim --pars "{pop_size:20000, pop_infected:1, n_days:360, rand_seed:1}"

Note: the CLI is currently not compatible with Windows. You will need to add this folder to your path to run from other folders.

Data

Scripts to automatically scrape data (including demographics and COVID epidemiology data), and the data files themselves (which are not part of the repository).

Tutorials

This folder contains Jupyter notebooks for nine tutorials that walk you through using Covasim, from absolute basics to advanced topics such as calibration and creating custom populations.

Examples

This folder contains demonstrations of simple Covasim usage, with most examples taken from the tutorials.

Cruise ship

An early application of Covasim to the Diamond Princess cruise ship.

Calibration

Examples of how to calibrate simulations, including Optuna (also covered in the tutorial) and Weights and Biases.

Licenses

Licensing information and legal notices.

Tests

Integration, development, and unit tests. While not (yet) beautifully curated, these folders contain many usage examples. See the tests README for more information.

Disclaimer

The code in this repository was developed by IDM to support our research in disease transmission and managing epidemics. We’ve made it publicly available under the Creative Commons Attribution-ShareAlike 4.0 International License to provide others with a better understanding of our research and an opportunity to build upon it for their own work. We make no representations that the code works as intended or that we will provide support, address issues that are found, or accept pull requests. You are welcome to create your own fork and modify the code to suit your own modeling needs as contemplated under the Creative Commons Attribution-ShareAlike 4.0 International License. See the contributing and code of conduct READMEs for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

covasim-3.0.5.tar.gz (311.2 kB view details)

Uploaded Source

Built Distribution

covasim-3.0.5-py3-none-any.whl (207.5 kB view details)

Uploaded Python 3

File details

Details for the file covasim-3.0.5.tar.gz.

File metadata

  • Download URL: covasim-3.0.5.tar.gz
  • Upload date:
  • Size: 311.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for covasim-3.0.5.tar.gz
Algorithm Hash digest
SHA256 302be0f154d0a9f6f0589f6e910989923cd7bcd877a2c4b08fc6d18135c5bb97
MD5 6a38c797d9eefad76d440713cfced75a
BLAKE2b-256 dd648d6559643f59b27d63ea933bebb1a992e3fd85361c2948de20f8f6ff1484

See more details on using hashes here.

Provenance

File details

Details for the file covasim-3.0.5-py3-none-any.whl.

File metadata

  • Download URL: covasim-3.0.5-py3-none-any.whl
  • Upload date:
  • Size: 207.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for covasim-3.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 aab31b5635ecdff1893b3896d335755e70c441955f2a4abde0f2986d370d2205
MD5 c687ca26fa96ea383658ee86140dee69
BLAKE2b-256 8a5ad1eb7019c7408aa4acb36d297867ee5deee7508eeb02720a26138f809c3f

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page