Issues with Interactive Visualization in Agents.jl

schellingagentsjl5.jl (6.3 KB)

The attached file contains my modified version of the code for the Schelling model, which I am running using the latest versions of VS Code, Julia, Agents.jl, and the other packages noted in the code. Everything runs and looks quite good, including all the examples. However, there are a few things that I have not been able to figure out related to the Interactive Visualization Example

  1. Issue with Inspecting Agents: When I hover over the agents in the Makie window, the values shown for the agent in the tooltip are for x, y, and z. These are clearly the elements of the position field, although I am not sure why there is a value for z. However, the values for the ID field and the fields I added, group and happy, do not appear. I have tried to use the agent2string function, but to no avail.

  2. Issue with setting up adata: Rather than plotting the number of agents that are happy, I wanted to show either the number of agents that are unhappy or the number of agents that are happy in each of the two groups. However, I was unable to figure out how to do this. I was particularly surprised that using [(:happy, count, group1)] , which worked fine in the Data Collection Example, caused problems here.

  3. Issue with stopping the model when a condition is reached: I included the terminate condition in the abmexploration() function just as I did in the Data Collection and Parameter Scanning Examples. While it worked as expected in those examples, it did not here. The model would only stop when I clicked on the “run model” button in the Makie window.

I have scoured the documentation and examples both at Agents.jl and the Agents.jl Example Zoo, as well as the Slack and Discourse channels. Any thoughts on these would be greatly appreciated.

Hi and welcome,

  1. This should be no problem with proper dispatch on the agent2string function. Did you follow the process laid out here in the docs?
  2. Our visualisations aren’t doing anything special when compared to regular Makie plotting. If you know how to work with Makie, then you can completely change the Agents.jl visualisations to your liking. If you want to add multiple plots to one axis (that’s what I understood from your example), you first need to collect the specific data for each step that you want to display (e.g. with a custom function like count_happy(model, group) = count(agent.happy for agent in filter(a -> a.group == group, allagents(model))) and then plot this into an axis of your liking. More on this can be found here in the docs. If that’s not what you wanted and you just struggled with how to collect the data based on a specific agent condition, have a look at the third code block on this page of the docs.
  3. That’s the expected behaviour for the run button, see here in the source code. Introducing functionality for stop conditions doesn’t make a lot of sense for interactive visualisations, imho. If you want to run the model until a certain point and then plot it, you can just call abmplot once before and once after and you will get the updated plot.

Hope this helps. :slight_smile:

On a sidenote: If you want to share your code (which is generally much appreciated), instead of uploading a file (which is a bit of an unnecessary hurdle to download and open) you can directly use code blocks fenced with triple backticks in your post.

1 Like

Hi @daler6 , I’m having the same issue with agent2string. Have you managed to solve it?