An example of using the Python bindings for the CSDMS Basic Model Interface (BMI) to wrap a model written in NetLogo.
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
This example can be built and installed on Linux, macOS, and Windows.
Prerequisites:
- Java Runtime Environment (JRE). NetLogo is build on Java, and it needs a JRE to run.
- NetLogo. Instructions for downloading and installing NetLogo can be found here. NetLogo 6.1.1 was used to build, test, and run this example.
- Python BMI mappings. Follow the build and install directions given in that repository. You can choose to install them from source, or through
pip
orconda
. - 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 .
Jpype tries to guess where Java is installed.
If Java is installed in a non-standard location,
set the JAVA_HOME
environment variable.
As an example,
I installed Java through Homebrew on my Mac,
so I set JAVA_HOME
to its install location:
export JAVA_HOME=/opt/homebrew/opt/openjdk
Try the example notebooks and scripts in the examples directory.
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 U.S. National Science Foundation.