CoMSES Net Discourse Forums

Agentpy - Agent-based modeling in Python

Hi everyone,

I am new to this forum and happy to share my package for agent-based modeling in Python! The project is still in an early stage of development. If you want to contribute or have feedback, let me know :slight_smile:

Documentation: https://agentpy.readthedocs.io
Source: https://github.com/joelforamitti/

Here are some main features:

  • Design of agent-based models with complex procedures.
  • Creation of custom agent types, environments, and networks.
  • Container classes for operations on groups of agents and environments.
  • Experiments with repeated iterations, large parameter samples, and distinct scenarios.
  • Output data that can be saved, loaded, and transformed for further analysis.
  • Tools for sensitivity analysis, interactive output, animations, and plots.

In the model library of the documentation, you can find examples of wealth transfers, disease spreading, random networks, and forest fires. You can use these as tutorials, or also to compare the syntax and tools to other existing frameworks like Mesa or Netlogo.

Here is an example from an animation in one of the demonstration models:

ElW8ZlLXYAAWN-2

Best,
Joël

Thanks for sharing, @joelforamitti ! Would you be willing to explain more about why you decided to build this framework instead of using or contributing to Mesa? I didn’t see anything in the docs besides Mesa being more similar to NetLogo. (as a side note, you might want to consider following the Python PEP8 Style Guidelines more closely in your examples and codebase while you’re still in the early stages).

Regardless, congratulations on your first release! Competition is always a good thing and helps spur innovation :sweat_smile:!

Dear @alee,

thank you for your kind response!

i think Mesa is a great package, so I don’t want to play it down here in order to promote my own, but I will try to explain what motivated me to work on a seperate package:

  • The original motivation was that I wanted to create a multi-environment structure, i.e. a model that can hold multiple custom environments with different typologies (networks,grids,etc.), which can act like agents themselves, but also contain agents within them. Imagine, for example, interacting social groups, economic markets, or ecosystems. Other key structural elements are the parameter dictionary, the agent list class, and how output is recorded.

  • So I wanted a very particular base structure which differed from that of Mesa, and could not really be commited as an additional feature as it would fundamentally change the base classes. Other agentpy features, like the networkx and SALib integration, could be added to Mesa more easily, so maybe Mesa can benefit from some ideas in agentpy, in the same way that it helped me sometimes to see how they solved a particular issue

  • Another reason was that Mesa’s stated goal is to be the Python counterpart to Netlogo, Repast, & MASON. These frameworks, in my view, have a strong focus on live interfaces where you can observe the model dynamics as it runs, usually on a spacial grid. if that is the goal, Mesa and it’s browser-based visualization tool is probably more useful

  • For agentpy, in contrast, the main focus is on multi-run experiments with parameter sampling and scenario comparison. The framework is designed to combine dynamic and static variables from multiple runs into large datasets, as well as on analysis functions that can be applied to these datasets afterwards (e.g. sensitivity analysis with the SALib library).

i hope that answered your question! if you want to compare the two frameworks in terms of syntax, you can look at these two demonstrations of the same model in each framework:

kind regards,
joël

ps: thank you also for your tip regarding style, this will certainly be the focus of my next update, together with better testing.

1 Like