Multi-Agent Systems Practicum 2

Translating a netlogo model to Python Mesa

Wim Pouw

Recap content so far

Practicum 1 + lectures 1-2

  • Getting setup: NetLogo and Python Mesa environment setup.
  • Coding Style: Briefly inspected some coding style differences in NetLogo and Python.
  • Lectures: Basics of agent-based modeling, Netlogo overview & inspection of model variety.

Practicum 2: Objectives

  • Crashcourse mesa functionality: Introduction mesa key functionalities.
    • Data collection
    • Model + data visualization
    • Multi-iteration runs
    • Data saving and post-hoc plotting
  • Translation: Making a start in translating a netlogo model into python mesa.

Agenda

  • Overview mesa functionality with Wim
  • Start of translation to netlogo model to python mesa
  • Challenge: Continue translation at home

Part 1: Fully functional basic grid model

  • Lets inspect the “full functionality grid model” in mesa
  • Open the notebook full_func_multiagent_grid.ipynb in visual studio code (and make sure your mesa environment is activated)
  • Wim will guide you through the basic components of this mesa model

Part 1: Crashcourse finished

You know have some familiarity with:

  • Basic mesa model structure

  • Data collection

  • Model + data visualization

  • Multi-iteration runs and parameter sweeping

  • Data saving and post-hoc plotting

    • We might forget of course, so we can always revisit the “fullfunc”1 model

Part 2: Translating a netlogo model to python mesa

Part 2: The dispersal netlogo model

  • The Africa Origin hypothesis
  • The model simulates the migration of early humans out of Africa
  • Original paper (Young & Bettinger, 1995)
  • Lets inspect it together first

Lets think it through

  • What are the agents, environment, and processes in the netlogo model?

  • How can we represent these in python mesa?

  • What data do we want to collect?

  • How can we visualize this data?

  • Wait, can we start simple? And break up the complexity?

Lets create a jupyter notebook for making a basic dispersal model from scratch

In the first Markdown chunk of the notebook:

  • Title it “Basic Dispersal Model”
  • Write a brief description of the model and its purpose

First python chunck:

import numpy as np
import pandas as pd
import mesa
from mesa.discrete_space import CellAgent, OrthogonalMooreGrid
from mesa.visualization import SolaraViz, make_plot_component, make_space_component

Then we know the drill

  • Create agent class and let it do things

  • Create model class, collect some data

  • Create simple visualization

  • Run the model, save some data

  • check back to the fullfunc grid model

  • Also here - work in managable steps! (first get agents initialized properly, then get them moving, then think about data collection, then think about further visualizations)

Challenge for the full model translation

  • How to implement the entire model that interfaces with the world map picture?
  • The spreading of humans can only be across the landscape
  • How to make the world only wrap horizontally?
  • can you see more things that we might want to translate from Netlogo
  • Again start with priorities (probably implementing the map)

Challenge for the full model translation