Installation and Quickstart

Prerequisites

It is strongly recommended that you install summer2 in a managed environment rather than your system Python installation.

You can install a minimal version of the Anaconda package and environment manager (“Miniconda”) here.

In any case, you will need to have Python 3.8+ and Pip (the Python package manager) available.

If you are using Miniconda, then you will need to create an “environment” where you can install Summer and other packages you need for your project. You can create a new environment as follows:

# Create a new Anaconda environment.
conda create -n myprojectname python=3.8
# Make the new Anaconda environment active in your shell session.
conda activate myprojectname

Installation

You can install summer2 from PyPI using the Pip package manager

pip install summerepi2

Important note for Windows users:

summer2 relies on the Jax framework for fast retargetable computing. This is automatically installed by pip under Linux, OSX, and WSL environments. If you are using Windows, you can either install via WSL, or run the following command after pip installing

pip install jax[cpu]==0.3.24 -f https://whls.blob.core.windows.net/unstable/index.html

For other install methods, see https://pygraphviz.github.io/documentation/stable/install.html

Then you can import the library as summer2 and get started building compartmental disease models. You can find a list of examples and detailed API documentation on this site.

Note the above method installs the latest ‘release’ version of summer, but that this documentation is based on the current Github master version of summer, which may contain new features or changes to the API. To install summer directly from Github, use the following command instead

pip install git+https://github.com/monash-emu/summer2.git

Optional (but recommended) extras

Summer has advanced interactive plotting tools built in - but they are greatly improved with the addition of the pygraphviz library.

If you are using conda, the simplest method of installation is as follows:

conda install --channel conda-forge pygraphviz

Quick Example Model

This is a short example on how summer can be used. See the list of examples for more.

[1]
from summer2 import CompartmentalModel
from summer2.functions.time import get_piecewise_scalar_function

import pandas as pd
pd.options.plotting.backend = "plotly"

# Create a model.
model = CompartmentalModel(
    times=[1990, 2025],
    compartments=["S", "I", "R"],
    infectious_compartments=["I"],
    timestep=0.1,
)

# Add people to the model.
model.set_initial_population(distribution={"S": 1000, "I": 10})

# Add intercompartmental flows.
model.add_infection_frequency_flow(name="infection", contact_rate=1.2, source="S", dest="I")
model.add_transition_flow(name="recovery", fractional_rate=1/6, source="I", dest="R")
model.add_death_flow(name="infection_death", death_rate=0.5, source="I")

# Spice up the model by importing 500 infected people over the course of 2005
get_infected_imports = get_piecewise_scalar_function([2005,2006], [0.0,500.0,0.0])

model.add_importation_flow('infected_imports', get_infected_imports, 'I', split_imports=True)

# Run the model
model.run()

# Plot the model results.
model.get_outputs_df().plot()

/tmp/ipykernel_2528/3125315769.py:24: DeprecationWarning: This method is deprecated and scheduled for removal, use get_piecewise_function instead
  get_infected_imports = get_piecewise_scalar_function([2005,2006], [0.0,500.0,0.0])
[ ]