Skip to content

An example of wrapping a model written in NetLogo with a Python BMI

License

Notifications You must be signed in to change notification settings

csdms/bmi-example-pynetlogo

Repository files navigation

Basic Model Interface Test

bmi-example-pynetlogo

An example of using the Python bindings for the CSDMS Basic Model Interface (BMI) to wrap a model written in NetLogo.

Overview

This is an example of implementing a BMI for a simple model of temperature diffusion on a uniform rectangular plate with Dirichlet boundary conditions. The model, HeatDiffusion, is written in NetLogo, and is a part of the standard NetLogo distribution.

This repository is organized with the following directories:

heat
Source for the model and a BMI implementation for the model
examples
Python scripts and Jupyter Notebooks that demonstrate how to run the model standalone and through its BMI
tests
Tests that cover the BMI of the model

Build/Install

This example can be built and installed on Linux, macOS, and Windows.

Prerequisites:

  • NetLogo. Instructions for downloading and installing NetLogo can be found here. NetLogo 6.1.1 was used to build, test, and run this example.
  • The Python BMI bindings. Follow the build and install directions given in that repository. You can choose to install them from source, or through pip or conda.
  • PyNetLogo and Jpype. These are the key software packages that allow communication between NetLogo and Python.

We recommend setting up a virtual environment--e.g., through venv or conda--to install the packages required for this example. For conda, we've included an environment file.

conda env create --file environment.yml

This creates the logo environment, which you can activate to have access to all the dependent packages needed to build and use this example.

Install the example with pip.

pip install -e .

Use

Try the example notebooks and scripts in the examples directory.

Acknowledgments

The model of temperature diffusion used in this example.

Wilensky, U. (1998). NetLogo Heat Diffusion model. http://ccl.northwestern.edu/netlogo/models/HeatDiffusion. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

The NetLogo software.

Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

CSDMS is supported with funding from the National Science Foundation.