Need some help/review on ants model

Hi there,

Last year i start to replicate the famous “Ants” model using Agents.jl with version 4.x

The result was not bad, see the video and original repo :

This year, to finish integration of Julia with Agents.jl into OpenMole distributed HPC marketplace examples, i try to update to Agents.jl 5.x

I have some difficulties with evolution of !step method :

In my previous code i use step like this to update my graphics : step!(abmstepper,model, ants_agent_step!, ants_model_step!, 1)


fig, abmstepper, abmobs = init_fig(model, observable)

and init_fig running abmplot :

function init_fig(model, observable)

    function ants_marker(b::Ants)
       φ = atan(b.vel[2], b.vel[1]) #+ π/2 + π
       scale(rotate2D(ants_polygon, φ), 2)

    function ants_color(b::Ants)
       return b.color

    fig, abmstepper, abmobs  = abmplot(model; ac=ants_color, am=ants_marker)

    ax, hm = heatmap(fig[1,2], observable[1]; colormap= :thermal, nan_color= :red)
    ax.aspect = AxisAspect(1)

    ax2, hm2 = heatmap(fig[2,1], observable[2]; colormap= :thermal, nan_color= :red)
    ax2.aspect = AxisAspect(1)

    ax3, hm3 = heatmap(fig[2,2], observable[3]; colormap= :thermal, nan_color= :red)
    ax3.aspect = AxisAspect(1)

    s = Observable(0) # counter of current step, also observable
    Colorbar(fig[1, 3], hm, width = 20,tellheight=false)
    rowsize!(fig.layout, 1 , ax.scene.px_area[].widths[2])

    return (fig, abmstepper, abmobs)


So the first update here was to understand if it’s possible to do the same thing with agents.jl v5, because !step signature change.

I also need some info of Agent.js dev to know if there is a more simple way to manage the double step for grid space : continuous (ants move) and discrete (food patches).

Actually i use a double step method to manage that :

     step!(abmstepper, model, ants_agent_step!, ants_model_step!, 1)
            step!(model.sugar_model, sugar_agent_step!, sugar_model_step!, 1)

I’m very interested to push a documented / updated version of this model, already implemented in python and netlogo) to use on HPC with OpenMOLE.

Yes it is very much possible to do animated composite plots, see here Plotting and Interactivity · Agents.jl

Obviously in your case you won’t have the full interactive GUI as the left window, but rather an animatable plot.

Now that i’m ready to use latest version of Cairo + Agents with julia 1.7 :slight_smile: i try to change the methods.

Into my init_fig() method i set abmplot like this, by passing the corresponding ants_xx_step! :

function init_fig(model, observable)

    fig, abmstepper, abmobs = abmplot(model; ants_agent_step!, ants_model_step!, am= ants_marker, ac=ants_color, figure=(;resolution=(800,800)))
    return (fig, abmstepper, abmobs)

Called like that :

fig, abmstepper, abmobs = init_fig(model, observable)

And i change the step! into main loop function :

  while Agents.until(s, rununtil, model)
            print("sugar remaining on world =  $(sum(model.sugar_model.sugar_landscape)) \n")
            recordframe!(io) # save current state
            if Agents.should_we_collect(s, model, true)
                Agents.collect_agent_data!(df_agent, model, adata, s)
            if Agents.should_we_collect(s, model.sugar_model, true)
                Agents.collect_model_data!(df_model, model.sugar_model, mdata, s)
            step!(abmobs, 1) # change here 
            step!(model.sugar_model, sugar_agent_step!, sugar_model_step!, 1)
            s += 1



function ants_model_step!(model)
    model.tick += 1

But my ant model doesn’t step and run indifinetly, so something missing …

Update 2

I test only with this and it’s work, so it’s a problem with model calling with Observables stepping ?

step!(model,ants_agent_step!,ants_model_step!,1) #ants stepping
step!(model.sugar_model, sugar_agent_step!, sugar_model_step!, 1) #sugar stepping

Update 3

I continue to debug to understand @Datseris, doing this works :

abmobs = ABMObservable(model; agent_step! = ants_agent_step!, model_step! = ants_model_step!)

while Agents.until(s, rununtil, model)
    step!(model.sugar_model, sugar_agent_step!, sugar_model_step!, 1)

That’s work, so is there a problem in ambplot ABMObservable returned and step! ?

Update 4

I found the problem i think, the abmplot doesn’t trigger an error, even if the syntax is not correct …


 fig, abmstepper, abmobs = abmplot(model; ants_agent_step!, ants_model_step!, am= ants_marker, ac=ants_color, figure=(;resolution=(800,800)))


 fig, abmstepper, abmobs = abmplot(model; agent_step! = ants_agent_step!, model_step! =  ants_model_step!, am= ants_marker, ac=ants_color, figure=(;resolution=(800,800)))

I push a first iteration of README doc and the updated model here : GitHub - reyman/julia-antworld-model

you should open a PR at AgentsExampleZoo.jl which adds this example. There it is much simpelr to give reviews to code.

1 Like