Examples

Starsim ships with a collection of example models — illustrative implementations of diseases, networks, and analyses that aren’t part of the core library but show how Starsim can be used and extended. They come in two forms:

Here’s a quick example running one of the library disease models:

import starsim as ss
import starsim.library as ssl
ss.options(jupyter=True)

# Run the measles model on a random network
sim = ss.Sim(diseases=ssl.diseases.Measles(), networks='random', n_agents=5000, verbose=0)
sim.run()
sim.plot('measles')
Figure(768x576)

Library disease models (ssl.diseases)

Worked examples of disease models, several of which add states and dynamics beyond the core SIR/SIS templates:

  • ssl.diseases.HIV — HIV natural history, including CD4 dynamics; pairs with the ssl.diseases.ART intervention and the ssl.diseases.CD4_analyzer
  • ssl.diseases.Cholera — an environmentally transmitted disease
  • ssl.diseases.Ebola — a model with multiple transmission routes
  • ssl.diseases.Measles — a childhood disease with an SEIR-like structure

These are used throughout the documentation, for example in the Diseases and Networks tutorials and the Connectors user guide.

Library networks (ssl.networks)

Example contact networks demonstrating different connection rules:

  • ssl.networks.DiskNet — connects agents by spatial proximity on a disk
  • ssl.networks.HouseholdNet — household-structured contacts
  • ssl.networks.ErdosRenyiNet, ssl.networks.NullNet — theoretical reference networks

Library maternal and child health (ssl.mnch)

Examples relevant to maternal and child health, including ssl.mnch.FetalHealth, ssl.mnch.NeonatalSepsis, and ssl.mnch.CongenitalDisease.

Standalone examples (docs/examples)

These live as scripts in the repository rather than in the importable library:

  • Embedding network (embedding.py) — pairs agents based on a continuous similarity embedding.
  • Cross-language translations (translations/) — the same simple SIS model implemented in pure Python, Numba, JAX, Julia, and Rust, alongside the idiomatic Starsim version. Useful for understanding performance trade-offs and how Starsim relates to lower-level implementations.
  • LASER interoperability (laser/) — shows how Starsim models relate to LASER, including minimal and full Starsim equivalents of a LASER example and profiling scripts.