_images/logo_4.png

Agent-based model simulation for air quality and pandemic risk assessment in architectural spaces.

PyPI Status PyPI Version License Actions https://img.shields.io/pypi/dm/archABM?style=flat-square Top Language Github Issues

User Guide

archABM is a fast and open source agent-based modelling framework that simulates complex human-building-interaction patterns and estimates indoor air quality across an entire building, while taking into account potential airborne virus concentrations.

This documentation contains a quick-start guide (including installation procedure and basic usage of the simulator), a complete API Reference, as well as a detailed example. archABM is released under the MIT License.

Finally, if you use archABM in a scientific publication, we would appreciate citations.


Disclaimer

archABM is an evolving research tool designed to familiarize the interested user with factors influencing the potential indoor airborne transmission of viruses (such as SARS-CoV-2) and the generation of carbon-dioxide (CO2) indoors. Calculations of virus and CO2 levels within ArchABM are based on recently published aerosol models [1,2], which however have not been validated in the context of agent-based modeling (ABM) yet. We note that uncertainty in and intrinsic variability of model parameters as well as underlying assumptions concerning model parameters may lead to errors regarding the simulated results. Use of archABM is the sole responsibility of the user. It is being made available without guarantee or warranty of any kind. The authors do not accept any liability from its use.

[1] Peng, Zhe, and Jose L. Jimenez. “Exhaled CO2 as a COVID-19 infection risk proxy for different indoor environments and activities.” Environmental Science & Technology Letters 8.5 (2021): 392-397.

[2] Lelieveld, Jos, et al. “Model calculations of aerosol transmission and infection risk of COVID-19 in indoor environments.” International journal of environmental research and public health 17.21 (2020): 8114.


Getting Started

Use the following template to run a simulation with archABM:

# Import modules
import json
import pandas as pd
from archABM.engine import Engine

# Read configuration example
from archABM.config import config
# Alternatively, get configuration from "config.json" example

# Create ArchABM simulation engine
simulation = Engine(config)

# Run simulation
results = simulation.run()

# Create dataframes based on the results
df_people = pd.DataFrame(results["results"]["people"])
df_places = pd.DataFrame(results["results"]["places"])

This example uses the default configuration file built-in the library. Alternatively, you can download and modify the config.json file found at the data directory of archABM repository.


Developers can also use the command-line interface with the main.py file from the source code repository.

_images/command.png
$ python main.py config.json

To run an example, use the config.json found at the data directory of archABM repository.

Check the --help option to get more information about the optional parameters:

$ python main.py --help
Usage: main.py [OPTIONS] CONFIG_FILE

  ArchABM simulation helper

Arguments:
  CONFIG_FILE  The name of the configuration file  [required]

Options:
  -i, --interactive     Interactive CLI mode  [default: False]
  -l, --save-log        Save events logs  [default: False]
  -c, --save-config     Save configuration file  [default: True]
  -t, --save-csv        Export results to csv format  [default: True]
  -j, --save-json       Export results to json format  [default: False]
  -o, --return-output   Return results dictionary  [default: False]
  --install-completion  Install completion for the current shell.
  --show-completion     Show completion for the current shell, to copy it or
                        customize the installation.

  --help                Show this message and exit.

Inputs

In order to run a simulation, information about the event types, people, places, and the aerosol model must be provided to the ArchABM framework.

Attribute

Description

Type

name

Event name

string

schedule

When an event is permitted to happen, in minutes

list of tuples

duration

Event duration lower and upper bounds, in minutes

integer,integer

number of repetitions

Number of repetitions lower and upper bounds

integer,integer

mask efficiency

Mask efficiency during an event [0-1]

float

collective

Event is invoked by one person but involves many

boolean

allow

Whether such event is allowed in the simulation

boolean

Example config.json
{
    "events": [{
            "activity": "home",
            "schedule": [
                [0, 480],
                [1020, 1440]
            ],
            "repeat_min": 0,
            "repeat_max": null,
            "duration_min": 300,
            "duration_max": 360,
            "mask_efficiency": null,
            "collective": false,
            "shared": false,
            "allow": true
        },
        {
            "activity": "work",
            "schedule": [
                [480, 1020]
            ],
            "repeat_min": 0,
            "repeat_max": null,
            "duration_min": 30,
            "duration_max": 60,
            "mask_efficiency": 0.8,
            "collective": false,
            "shared": true,
            "allow": true
        }
    ],
    "places": [{
            "name": "home",
            "activity": ["home"],
            "building": null,
            "department": null,
            "area": null,
            "height": null,
            "capacity": null,
            "ventilation": null,
            "recirculated_flow_rate": null,
            "allow": true
        },
        {
            "name": "office1",
            "activity": ["work"],
            "building": "building1",
            "department": ["department1"],
            "area": 200.0,
            "height": 3.0,
            "capacity": 50,
            "ventilation": 3,
            "recirculated_flow_rate": 0,
            "allow": true
        },
        {
            "name": "office2",
            "activity": ["work"],
            "building": "building1",
            "department": ["department2"],
            "area": 200.0,
            "height": 3.0,
            "capacity": 50,
            "ventilation": 3,
            "recirculated_flow_rate": 0,
            "allow": true
        }
    ],
    "people": [{
            "department": "department1",
            "building": "building1",
            "num_people": 20
        },
        {
            "department": "department2",
            "building": "building1",
            "num_people": 20
        }
    ],
    "options": {
        "movement_buildings": true,
        "movement_department": true,
        "number_runs": 1,
        "save_log": true,
        "save_config": true,
        "save_csv": false,
        "save_json": false,
        "return_output": false,
        "directory": null,
        "ratio_infected": 0.05,
        "model": "Colorado",
        "model_parameters": {
            "Colorado": {
                "pressure": 0.95,
                "temperature": 20,
                "CO2_background": 415,
                "decay_rate": 0.62,
                "deposition_rate": 0.3,
                "hepa_flow_rate": 0.0,
                "filter_efficiency": 0.20,
                "ducts_removal": 0.10,
                "other_removal": 0.00,
                "fraction_immune": 0,
                "breathing_rate": 0.52,
                "CO2_emission_person": 0.005,
                "quanta_exhalation": 25,
                "quanta_enhancement": 1,
                "people_with_masks": 1.00
            }
        }
    }
}

Outputs

Simulation outputs are stored by default in the results directory. The subfolder with the results of an specific simulation have the date and time of the moment when it was launched as a name in %Y-%m-%d_%H-%M-%S-%f format.

By default, three files are saved after a simulation:

  • config.json stores a copy of the input configuration.

  • people.csv stores every person’s state along time.

  • places.csv stores every places’s state along time.

Attribute

Description

Type

run

Simulation run

int

time

Simulation time (minutes)

int

person

Person ID

int

status

Person status (0: susceptible, 1: infective)

bool

place

Place ID

int

event

Event ID

int

CO2_level

Average CO2 level (ppm)

float

quanta_inhaled

Quanta inhaled (quanta)

float

archABM offers the possibility of exporting the results in JSON and CSV format. To export in JSON format, use the --save-json parameter when running archABM. By default, the --save-csv parameter is set to true.

Alternatively, archABM can also be configured to yield more detailed information. The app.log file saves the log of the actions and events occurred during the simulation. To export this file, use the --save-log parameter when running archABM.


Installation

As the compiled archABM package is hosted on the Python Package Index (PyPI) you can easily install it with pip. To install archABM, run this command in your terminal of choice:

$ pip install archABM

or, alternatively:

$ python -m pip install archABM

If you want to get archABM’s latest version, you can refer to the repository hosted at github:

python -m pip install https://github.com/Vicomtech/ArchABM/archive/main.zip

Environment Setup

Requirements

archABM builds on simpy, tqdm, jsonschema and typer libraries.

Python 3

To find out which version of python you have, open a terminal window and try the following command:

$ python3 --version
Python 3.6.9

If you have python3 on your machine, then this command should respond with a version number. If you do not have python3 installed, follow these instructions.

Pip

pip is the reference Python package manager. It’s used to install and update packages. In case pip is not installed in your OS, follow these instructions.

Virtual Environment

venv creates a “virtual” isolated Python installation and installs packages into that virtual installation. It is always recommended to use a virtual environment while developing Python applications. To create a virtual environment, go to your project’s directory and run venv.

$ python3 -m venv env

Before you can start installing or using packages in your virtual environment you’ll need to activate it.

$ source env/bin/activate

Source Code

archABM is developed on GitHub, where the code is always available.

You can either clone the public repository:

$ git clone git://github.com/Vicomtech/ArchABM.git

Or, download the tarball:

$ curl -OL https://github.com/Vicomtech/ArchABM/tarball/main
# optionally, zipball is also available (for Windows users).

Once you have a copy of the source, you can embed it in your own Python package, or install it into your site-packages easily:

$ cd ArchABM
$ python -m pip install .