Search code examples
juliaagent

how to collect simulation data every n ticks from julia agents


I have an agent-based model in Julia for which I need to collect data, I am running it like:

ensemblerun!(models, agent_step!, dummystep, 1000; adata, parallel = true);

It actually reports values at every step, but I would like to collect data only every 50 steps.

Where should I introduce a condition like:

steps mod 50 == 0 # then proceed collecting data

I really have no idea where to insert any kind of condition... it seems an hardwired behaviour of the framework... but maybe I am missing the point, being new at this Julia Agents


Solution

  • Try running the simulation with:

    ensemblerun!(models, agent_step!, dummystep, 1000; 
      adata, parallel = true, when=((m,s)->s % 50 == 1))
    

    More explicitly, the when parameter can be a function that returns a boolean indicating when to trace. The function's parameters being (model, step_number) and are self-explanatory.