Designing an agent-based model is never easy. Especially in the beginning when you have the rough ideas for the model in your head, maybe sketched some of the core behavioural rules, and gathered the references for them in an unordered list. You will advance through the regular steps of deciding on a model purpose, formulating precise research questions, properly formalising your model's inner workings, maybe putting its core functions in mathematical notation or possibly even pseudo-code, ...
At some point, however, you will find yourself starting up your IDE of choice (some do this step rather sooner than later) and stare at the blank file before you. You may smile out of anticipation of the grand things to come, the epiphanies that will strike you out of nowhere to make your code readable, easy to navigate, and performant at the same time. Or you may already release a deep sigh at the thought of endless iterations over your algorithms to get them to do what you intend them to do, or you might start to feel discouraged after a short while because of the lack of good documentation for things that feel like core features to you. You don't know where to start and what to do next, how to structure your code so that it stays maintainable in the long run, who to ask for help if you encounter a road block on your journey, and so on and so forth.
If you nodded at least once or twice while reading the paragraphs above, this little series might be for you. My name is Fred and I'm currently a PhD student at the Chair of Macroeconomics at Ruhr-University Bochum in Germany. In my free time I do volunteer work for the German Red Cross and I'm also a co-host of the Mikroökonomen podcast (in German). I neither have a background in computer science, nor am I outstandingly knowledgeable in the area of agent-based modelling (besides it being my day job). But over time I've picked up more and more how to code in Julia and how its community works. And due to how approachable both the language and its community are, I've ended up contributing to some Julia packages (most notably Agents.jl and InteractiveDynamics.jl and recently even started an own package (OSMMakie.jl) as a side project.
I've started my ventures into the field of ABMs a few years ago during a course of my master's programme. We learned about behavioural rules of economic agents, some algorithmic thinking, and how to code in NetLogo and I had a lot of fun working with it. Over the past years, I've even had the opportunity to assist in teaching the practical sides of agent-based modelling with NetLogo and how students can use it to tackle their own research questions. Ever since my first contact with ABMs, I've got hooked on the concepts of Computational Economics to explore and hopefully better understand the underlying complex relationships in the economic parts of societies.
Even though I've initially learned and later taught agent-based modelling via the great tool that is NetLogo, I've relatively quickly came to realise that its great prototyping abilities, easy to learn and use syntax, and built-in visualisations come with some trade-offs. Two of which still stand out the most to me:
For one, it's relatively slow compared to other ABM frameworks and, to be quite frank, there's not much that we as regular users can do about this. Have a look here for one attempt to quantify the differences between popular frameworks. As can be seen from this, Julia is well suited for executing highly computationally intensive ABMs. After all, agent-based models are at their core not really much more than repetitive number crunching under a set of given rules. And that, by chance, is a domain in which Julia really shines.
Users also need at least a second tool or programming language to analyse the data generated by their ABMs and plot it in a visually appealing way (preferably even in a publishable form). Julia solves this issue both by design and through its rich package ecosystem which allows agent-based modellers to code continuous pipelines from the model itself into data wrangling and finally visualisation. No need for intermediate data conversion and, maybe more importantly, no need to learn multiple syntaxes.
It's this kind of uniform approach utilising just a single programming language for all your needs, that can allow researchers to free up some precious mental capacities and gain speed in writing clear and concise code. All while allowing others to reproduce your findings and modify or extend your models. Taking these two points together, I firmly believe that Julia is indeed a great candidate for writing agent-based models.
A quick side note: Agent-based modelling has a broad community ranging from disciplines such as physics and biology to social sciences and economics. Due to my personal background, this series will naturally approach the topic of ABMs from this perspective as well. This means that in the examples I choose, the agents are more likely to represent humans, firms, or some other kind of institutions more often than for example cells, particles, or other animals. Let this not distract you from the fact, that ABMs can be used for a multitude of great applications and scenarios from various scientific backgrounds. At its core, the technicalities stay the same - it's just the story and the subjects that change.
For now, this is just a dummy post to test this new platform in the broader Julia community (yet, already having spent a non-negligible amount of time on this post). And while I'm planning to contribute a few more posts to this series, it's as of yet unclear how long this will last. Somehow it's an attempt to give something back to the Julia community besides answering questions on Discourse, Zulip, Slack and Github. Hopefully it will succeed in conveying my enthusiasm for doing agent-based modelling in Julia and convince others to try it out for themselves. It's not particularly harder to code good ABMs in Julia than it is in any other framework like NetLogo or Mesa. But it might take some time to get used to the "Julia way" when coming from another language. This is what I'm trying to help with. Maybe you'll like it, maybe you won't. In the end, I would be glad to hear about your experiences, no matter if they're positive or negative.
Designing an agent-based model is never easy.
So let's not make the coding part any harder than it has to be.
So long,
Fred
Top comments (10)
Hi Frederick - Many thanks for kicking this off.
I agree with all you have written here about the transition from NetLogo to Julia and the potential in Agents.jl. We have been working on an extension to the package (AgentsX.jl) that enables easier definitial of agent 'breeds' as they might be known in NetLogo as we found the Agents.jl framework to be too restrictive in this regard, especially when you have a very complex social system - i.e., we don't want to create agents who are people but have characteristics of 'buses', for instance, we just want to create people and then we want to create buses. We are also trying to create a simpler means for non-technical users to generate functional code.
We presented some of this work at ABMUS2022 last month (The abstract can be found here - modelling-urban-systems.com/) and one of our group's post-docs, Rajith will be presenting a little more at the Agents.jl stream at ESSA in September. He is the main developer.
In terms of speed in NetLogo (not that this is the focus of this post), we've also created some templates for anyone still in the transition to Julia as we are. osf.io/preprints/socarxiv/sqy8c/
Speed and data-visualisation is a non-trivial issue when we are working with policymakers - I am really looking forward to developments in Julia!
Hi Jason, first of all thanks for reading and commenting.
Your joint work on AgentsX.jl is very interesting. Although I have to admit that after reading the abstract, I'm not totally sure that I've understood your goals with the package. It seems to me as if most of the functionality you've described in the abstract is already present in Agents.jl or can be easily integrated by users without the need of another package. But as I could see from the git repo, the work is still ongoing, so I'll definitely keep an eye on its development. Thanks for bringing it up.
Also I didn't know about ABMUS2022 and am delighted to see that there is a dedicated and ongoing effort to increase visibility of urban simulations - a topic that I'm also very interested in. This conference definitely already went on my "to-attend list". :)
We'd love to have you along to ABMUS 2023, Frederick!
Our main goal with AgentsX.jl is to take the existing functionality of the base package but make a very specific and easy to use version specifically for social scientists that gives a head start focused on core social science problems common to socio-technical systems (assuming there are some...). We want to depart from ODD (a nightmare, imho) to make the 'code as the model' and also want to prompt people to think about the structure of problems in social science by easily incorporating multi-level modelling 'layers' - analogous to socio-ecological conceptualisations in some respects (e.g., moving from psychological and physiological through the behavioural, social, cultural, physical (e.g., maps and space ) and technical (e.g., policiies)). Layers will be set by default but could also be designed. We have come across restrictions with Agents.jl on defining multiple agent types (e.g., machine vs person) as opposed to agents with multiple characteristics (e.g., male or female person), so we've got a fix for that which makes coding things a bit cleaner.
So, yes, it will have all of the existing Agents.jl functionality but will add a few tweaks and 'ready-made' code blocks and functions especially targeted at social scientists.
Interesting, thanks for elaborating on it. I'll just watch how AgentsX.jl evolves. I will try to incorporate a model including "men and machines" in this series, to showcase how I would do it with the already existing tools. :)
On a sidenote, I agree about the unwieldiness of ODD. To me it feels too strict and seems to attempt to overly standardise very heterogeneous modelling processes.
I've subscribed, looking forward to seeing how these posts evolve!
Hey Edwin, thanks for your nice comment.
I am looking forward to the series!
Hey Logan, thanks for making this platform public. :)
Very excited to see another Econ PhD on the site. I've been interested in ABM and its applications in economics. What types of resources are there to investigate it?
Hey William, glad to see that I'm not the only economist on here. ;)
The resource base for ABMs in economics and other social sciences is very (!) broad, so it's definitely not an easy task to come up with just a few publications to read or videos to watch. In terms of journals, you could for example have a look at JASSS and ACS to get you started.