This repository was created to test the possibility to [bidirectionally] couple ABMs built witn Agents.jl or Mesa and an SD model built with PySD.
The models are inspired by Martin and Schlüter (2015). For practical reasons, the SD model was overly simplified, while the ABM is more similar to the original, but could not be fully reproduced based on the article and the supplementary materials.
The ABM simulates how social pressure and Municipality enforcement motivate households to upgrade their wastewater treatment system, to reduce pollution of a downstream lake.
The SD model simulates how lake pollution affects the population of a fish species.
When the fish population declines below a certain threshold, the Municipality informs polluting households about the need to upgrade their treatmen systems. Moreover, households that have already upgraded their systems, encourage their (close) neighbours to do the same. If after 3 years of breaching the threshold, households have not yet upgraded, the Municipality encourages them to do so (enforcement). When households upgrade the treatment system, they stop polluting the lake.
Both the SD and the ABM exchange information every year, but the SD model time step is 0.25 years.
The workflow is the following:
- ABM estimates anual pollution, which becomes an input to the SD model
- Based on the input pollution, the SD model updates the lake pollution and the fish population.
- The fish population is used as input to the ABM
The ABM model is written in julia and in Python, while the SD model is written in Python.
A julia script is used to couple the two models, using PyCall to run the SD model.
Users should have Julia installed, and a Python conda environment with PySD installed on it.
A config.toml
file needs to be created inside the project, whith the following contents:
python_path = "path_to_the_python_executable_in_your_conda_environment"
Users should have a Python conda environment with PySD and Mesa installed on it.
From a terminal, load the julia REPL with the required dependencies:
julia --project
include("social_model_plots.jl")
This will create an mp4
video, representing the Municipality (red dot) and the households. Blue means that households are polluting, orange means that they already upgraded their systems.
include("sd_model.jl")
sd_model.run()
This should return a DataFrame with the simulation results.
include("coupling.jl")
Activate the conda environment with:
conda activate my_environment
Then run:
python social_model.py
This should print a DataFrame on screen.
Activate the conda environment as in the previous step.
Open a Python interpreter:
python
Import pysd, load the model and run it.
import pysd
sd_model = pysd.load("sd_model.py")
sd_model.run()
Activate the conda environment.
python coupling.py
The dynamics simulated with the current versions of the models are not realistic.
For now only the variables from the ABM model are stored in a DataFrame.