Skip to main content

A fast, flexible agent-based disease modeling framework

Project description

Starsim

PyPI version Downloads Tests

Starsim is an agent-based modeling framework designed for simulating the spread of diseases among agents via dynamic transmission networks. Starsim supports the co-transmission of multiple diseases at once, capturing how they interact biologically and behaviorally. Additionally, users can also include non-infectious diseases either on their own or as factors affecting infectious diseases. To enable the study of birth-related diseases, Starsim allows detailed modeling of mother-child relationships starting from conception. Finally, Starsim lets users compare different intervention strategies, such as vaccines or treatments, to examine their impact through various delivery methods such as mass campaigns or targeted outreach.

Examples of systems that have already been implemented in Starsim include sexually transmitted infections (HIV, HPV, and syphilis, including co-transmission), respiratory infections (tuberculosis and RSV), other infectious diseases (Ebola and cholera), and underlying determinants of health (such as malnutrition).

Note: Starsim is a general-purpose, multi-disease framework that builds on our previous suite of disease-specific models, which included Covasim, HPVsim, and FPsim. In cases where a distinction needs to be made, Starsim is also known as "the Starsim framework" or "Starsim Core," while this collection of other models is known as the "Starsim suite."

For more information about Starsim, please see the documentation. Information about Starsim for R is available at r.starsim.org.

Requirements

Python 3.10-3.13 or R.

We recommend, but do not require, installing Starsim in a virtual environment, such as Miniconda.

Installation

Python

Starsim is most easily installed via PyPI:

pip install starsim

Or with uv:

uv init example
cd example
uv add starsim

Starsim can also be installed locally (including optional dependencies for testing and documentation). To do this, clone first this repository, then run:

pip install -e .[dev]

(Note: if after doing this, Starsim works, but you see "Import could not be resolved" in your editor, use pip install -e . --config-settings editable_mode=strict instead; more info here.)

R

R-Starsim is still under development. You can install it with:

# install.packages("devtools")
devtools::install_github("starsimhub/rstarsim")
library(starsim)
init_starsim()

See r.starsim.org for more information.

Usage and documentation

Full documentation, including tutorials and an API reference, is available at docs.starsim.org.

You can run a simple demo via:

import starsim as ss
ss.demo()

Here is a slightly more realistic example of an SIR model with random connections between agents:

import starsim as ss

# Define the parameters
pars = dict(
    n_agents = 5_000,     # Number of agents to simulate
    networks = dict(      # Networks define how agents interact w/ each other
        type = 'random',  # Here, we use a 'random' network
        n_contacts = 10   # Each person has 10 contacts with other people  
    ),
    diseases = dict(      # *Diseases* add detail on what diseases to model
        type = 'sir',     # Here, we're creating an SIR disease
        init_prev = 0.01, # Proportion of the population initially infected
        beta = 0.05,      # Probability of transmission between contacts
    )
)

# Make the sim, run and plot
sim = ss.Sim(pars)
sim.run()
sim.plot() # Plot all the sim results
sim.diseases.sir.plot() # Plot the standard SIR curves

More usage examples are available in the tutorials, as well as the tests folder.

AI integration

Starsim includes a model context protocol (MCP) server that ensures your favorite AI-enabled editor/tool is Starsim-aware. For details, see the Starsim AI project.

Starsim structure

All core model code is located in the starsim subfolder; standard usage is import starsim as ss.

The model consists of core classes including Sim, People, Disease, Network, Intervention, and more. These classes contain methods for running, building simple or dynamic networks, generating random numbers, calculating results, plotting, etc.

The submodules of the Starsim folder are as follows:

  • analyzers.py: The Analyzers class (for performing analyses on the sim while it's running), and other classes and functions for analyzing simulations.
  • arrays.py: Classes to handle, store, and update states for people in networks in the simulation including living, mother, child, susceptible, infected, inoculated, recovered, etc.
  • calibration.py: Class to handle automated calibration of the model to data.
  • connectors.py: Classes for modulating interactions between modules (e.g. between two diseases).
  • debugtools.py: Helper functions and classes to aid with debugging model results and performance.
  • demographics.py: Classes to transform initial condition input parameters for use in building and utilizing networks.
  • diseases.py: Classes to manage infection rate of spread, prevalence, waning effects, and other parameters for specific diseases.
  • distributions.py: Classes that handle statistical distributions used throughout Starsim to produce random numbers.
  • interventions.py: The Intervention class, for adding interventions and dynamically modifying parameters, and classes for each of the specific interventions derived from it.
  • loop.py: The logic for the main simulation integration loop.
  • modules.py: Class to handle "module" logic, such as updates (diseases, networks, etc).
  • networks.py: Classes for creating simple and dynamic networks of people based on input parameters.
  • parameters.py: Classes for creating the simulation parameters.
  • people.py: The People class, for handling updates of state for each person.
  • products.py: Classes to manage the deployment of vaccines and treatments.
  • results.py: Classes to analyze and save results from simulations.
  • run.py: Classes for running simulations (e.g. parallel runs and the Scenarios and MultiSim classes).
  • samples.py: Class to store data from a large number of simulations.
  • settings.py: User-customizable options for Starsim (e.g. default font size).
  • sim.py: The Sim class, which performs most of the heavy lifting: initializing the model, running, and plotting.
  • time.py: Time classes, such as dates, durations, probabilities, and frequencies.
  • timeline.py: The Timeline class, which coordinates time between the Sim and different modules.
  • utils.py: Helper functions.
  • version.py: Version, date, and license information.

Starsim also includes a starsim_examples folder, which contains definitions of different examples of diseases, including STIs, Ebola, and cholera. Note: these are illustrative examples only for demonstrating Starsim usage and functionality; for actual scientific research, please see other Starsim models, e.g. STIsim.

Contributing

Questions or comments can be directed to info@starsim.org , or on this project's GitHub page. Full information about Starsim is provided in the documentation.

Disclaimer

The code in this repository was developed by IDM, the Burnet Institute, and other collaborators to support our joint research on flexible agent-based modeling. We've made it publicly available under the MIT 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 permitted under the MIT License.

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

starsim-3.1.0.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

starsim-3.1.0-py3-none-any.whl (942.9 kB view details)

Uploaded Python 3

File details

Details for the file starsim-3.1.0.tar.gz.

File metadata

  • Download URL: starsim-3.1.0.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for starsim-3.1.0.tar.gz
Algorithm Hash digest
SHA256 0c3d743e8a5812424e400193af116dae39f923a46d6cb46ca9ca90e1c089a785
MD5 2203ef62ee8d63f4fccc4e15163ceab0
BLAKE2b-256 3fb6ec43068397de0c49d0e6dfb4a26540aad69ff043347880d16333c141a7b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for starsim-3.1.0.tar.gz:

Publisher: pypi_release.yaml on starsimhub/starsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file starsim-3.1.0-py3-none-any.whl.

File metadata

  • Download URL: starsim-3.1.0-py3-none-any.whl
  • Upload date:
  • Size: 942.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for starsim-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 099a3dce3efce8322d5d83017703b6cb097cc024bfdbd8b20d13507505e850f1
MD5 45ee658f22c44413fbfb0a44b92fef45
BLAKE2b-256 5bfbca73d6eedd214279cc0fb9ffb317a2d4d3039cf2aac341c8cea4403f0782

See more details on using hashes here.

Provenance

The following attestation bundles were made for starsim-3.1.0-py3-none-any.whl:

Publisher: pypi_release.yaml on starsimhub/starsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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