Skip to main content

asdm

Agile System Dynamics Modelling

ASDM is a Python library for building and simulating System Dynamics (SD) models. It supports programmatic model creation, XMILE/.stmx import and export, and includes a built-in web simulator. ASDM is suitable for healthcare modelling, policy analysis, and any domain where stock-and-flow models are used.

Key Features

  • Programmatic model building — create stocks, flows, auxiliaries, and delayed auxiliaries from Python code.
  • XMILE round-trip — load .stmx/.xmile models, modify them, and save back to XMILE format.
  • Arrays and subscripts — multi-dimensional variables with element-level or parallel equations.
  • Conveyors — conveyor stocks with transit time and leak flows.
  • Graph functions — lookup tables with interpolation, modifiable at runtime.
  • Data import — feed time-varying or parameter data from CSV files into model variables.
  • Built-in SD functions — DELAY, DELAY1, DELAY3, SMTH1, SMTH3, PULSE, STEP, INIT, HISTORY, NORMAL, BINOMIAL, LOOKUP, and more.
  • Causal Loop Diagrams — generate CLDs from model structure using NetworkX.
  • Web simulator — browser-based interactive simulator with charts and CSV export.
  • Command-line interface — run simulations and export results from the terminal.

ASDM's Contribution & Impact

Check out this presentation: Project Care Home Demand, which highlights the role of ASDM in developing an online SD model-based simulator. The presentation is given by Sally Thompson, Senior Healthcare Analyst at The Strategy Unit (part of NHS Midlands and Lancashire CSU).


Installation

Install from PyPi

Requires Python 3.9 or later.

pip install asdm

ASDM and its required dependencies will be automatically installed.


Basic Usage

To create a new SD model using ASDM:

from asdm import sdmodel

model = sdmodel()

sdmodel is the core class for System Dynamics models.

Alternatively, you can load an SD model saved in XMILE format, including .stmx models:

model = sdmodel(from_xmile='example_model.stmx')

Run the simulation:

model.simulate()

Export simulation results:

  • As a pandas DataFrame:
    result = model.export_simulation_result(format='df')
    
  • As a Python dictionary:
    result = model.export_simulation_result(format='dict')
    

Save the model back to XMILE format:

model.save_xmile('output_model.stmx')

Running Simulations

Beyond the Python API, ASDM provides two ways to run simulations without writing code:

Web Interface

Perfect for exploring models, visualizing results, and quick iterations.

Launch the simulator:

asdm simulator

Opens in your browser at http://127.0.0.1:8080.

Run a specific model immediately:

asdm simulator model.stmx

Options:

  • --port 8081 — Use a different port
  • --host 0.0.0.0 — Allow access from other machines

Features:

  • Drag-and-drop model upload (.stmx, .xmile)
  • Interactive charts with variable selection
  • Download results as CSV
  • Auto-detects time units

ASDM Simulator


Command Line

Ideal for batch processing, automation, and integrating into pipelines.

Run a simulation:

asdm run model.stmx

Results saved as model.csv by default.

Custom output:

asdm run model.stmx --output results.csv

Use in scripts:

# Process multiple models
for model in models/*.stmx; do
  asdm run "$model" --output "results/$(basename $model .stmx).csv"
done

Check version:

asdm --version

Functionalities

Please refer to Documentation for detailed function descriptions.


Tutorial Jupyter Notebooks

Jupyter Notebooks demonstrate ASDM's functionalities:

SD Modelling

  • Creating an SD model from scratch:
    • Adding stocks, flows, auxiliaries.
    • Support for nonlinear and stochastic functions.
  • Running simulations.
  • Exporting and examining simulation results.
  • Visualising results.

Support for .stmx Models

  • Load and simulate .stmx models.
  • Support for arrays.
  • Modify equations and re-run simulations.

Abstract Syntax Tree (AST)

  • How ASDM parses model equations into AST structures.

More tutorial notebooks will be added.
Feel free to contribute your own via pull requests—please ensure they do not contain sensitive data.


Dependencies

ASDM relies on the following open-source packages. All use permissive licences compatible with the MIT licence.

Package Licence Purpose
NumPy BSD-3-Clause Numerical computation
pandas BSD-3-Clause Data export and CSV handling
Matplotlib PSF-based (BSD-compatible) Result visualisation
NetworkX BSD-3-Clause Dependency graphs and CLDs
lxml BSD-3-Clause XML processing
Beautiful Soup 4 MIT XMILE parsing
SciPy BSD-3-Clause Scientific functions
Flask BSD-3-Clause Web simulator

Licence

ASDM is open-source and released under the MIT licence.


Contributors

Wang Zhao (main author)

  • Scientific Collaborator at Swiss Tropical and Public Health Institute, Switzerland.
  • Contact: wang.zhao@swisstph.ch

Matt Stammers (contributor)

  • Consultant Gastroenterologist & open-source developer at University Hospital Southampton, UK.
  • Developed Streamlit-powered web apps using ASDM for healthcare modelling.
  • Part of the Really Useful Models initiative: Learn More.
  • GitHub: Matt's Homepage.

Metadata

Release files for asdm 0.7.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asdm 0.7.2
File Size Uploaded
asdm-0.7.2.tar.gz 66.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for asdm 0.7.2
File Interpreter ABI Platform
asdm-0.7.2-py3-none-any.whl Python 3 none any Details

Total release size: 125.6 kB

Release files / asdm-0.7.2.tar.gz

Download URL asdm-0.7.2.tar.gz
Size 66.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4577588da326c4520d9b6e2f1d2f6c3cbfd2242a87f17c730ebe882ecbc65d43
BLAKE2b-256 checksum
How to use checksums
a0c4d5aff6a0f58020afdb8154ff244a4ff1d5207a2c16b3fa8568174ea90820
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.9

Release files / asdm-0.7.2-py3-none-any.whl

Download URL asdm-0.7.2-py3-none-any.whl
Size 59.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a89a2d3817c20b67ad2f94ebd9776088ec43a51a822434b49b9e1950b102361
BLAKE2b-256 checksum
How to use checksums
912f84ab90692152ee23cad0f5966b0b699fd9499937c77ea5a6be65889a76c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.9

Release history Release notifications | RSS feed

This release

0.7.2 This release

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.5.0

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page