Unable to use InteractiveDynamics and Agents as Part of my Package

I am trying to use the latest InteractiveDynamics v0.20 and Agents v5.0 as part of my project. Since yesterday, I am getting the following error, whenever I try to precompile my package.

ERROR: LoadError: UndefVarError: abmplot not defined  

So, I tried to recreate it minimally as follows. I generated a new project ‘DaisyWorldTest’ using Pkg generate. I activated the project and added the following packages: Agents, InteractiveDynamics, CairoMakie, StatsBase, Random. The last two because the sample code requires it.
The project contains only two files
File 1: DaisyWorldTest.jl

module DaisyWorldTest


end # module

File 2: DaisyWorld.jl Exact same Agent Based Models · InteractiveDynamics (juliadynamics.github.io) Pasting it below for convenience

using InteractiveDynamics, Agents
using CairoMakie
daisypath = joinpath(dirname(pathof(InteractiveDynamics)), "agents", "daisyworld_def.jl")
model, daisy_step!, daisyworld_step! = daisyworld(; solar_luminosity = 1.0, solar_change = 0.0, scenario = :change)

daisycolor(a::Daisy) = a.breed # color of agents
as = 14 # size of agents
am = '♠' # marker of agents
heatarray = :temperature
heatkwargs = (colorrange = (-20, 60), colormap = :thermal)
plotkwargs = (;
    ac = daisycolor, as, am,
    scatterkwargs = (strokewidth = 1.0,),
    heatarray, heatkwargs

fig, ax, abmobs = abmplot(model; plotkwargs...)

I use VSCode and when I do Alt+Enter (aka Execute active file in REPL) on DaisyWorld.jl, everything works as expected and I can see the Plot!
But when I precompile the DaisyWorldTest package. I get UndefVarError: abmplot not defined error. I am planning to build a traffic simulation package which uses Agents.jl and InteractiveDynamics.jl. It won’t work for me, if I can’t use Agents and InteractiveDynamics as part of a another project.

Please help!

What’s inside Daisyworld.jl ?

The same as in Agent Based Models · InteractiveDynamics (juliadynamics.github.io)

Just tried to run exactly your module and it worked just fine without any errors. I cannot reproduce your issue, sorry.

So I can access everything as expected when using modules.

julia> IDTest.

Daisy                       daisy_step!                  eval                         plotkwargs
DaisyWorld                  daisycolor                   fig                          propagate_daisy!
abmobs                      daisypath                    heatarray                    solar_activity!
am                          daisyworld                   heatkwargs                   update_surface_temperature!
as                          daisyworld_step!             include
ax                          diffuse_temperature!         model
julia> IDTest.abmplot
abmplot (generic function with 1 method)

help?> IDTest.abmplot
  abmplot(model::ABM; kwargs...) → fig, ax, abmobs
  abmplot!(ax::Axis/Axis3, model::ABM; kwargs...) → abmobs

  Plot an agent based model by plotting each individual agent as a marker and using the agent's position field as its
  location on the plot. The same function is used to make custom composite plots and interactive applications for the
  model evolution using the returned abmobs. abmplot is also used to launch interactive GUIs for evolving agent based
  models, see "Interactivity" below.


Uninstalled Julia, Deleted everything related to julia. Did a fresh installation and getting the exact same error. Executing the DaisyWorld.jl file in REPL creates the plot. Bit When I go to Pkg(’]) and precompile, I am getting the ‘undefVar error for abmplot’.

If its something weird only with my local system then the CI (github workflow) should have worked. It fails with the same. I have another fresh machine. I’ll try to recreate it on that machine and see how it goes. Thanks anyway.

I’ve created a file with your module in it. Loaded that module and executed everything in it, no problem. I really can’t tell where the difference is to what you did.

I have two files

  1. DaisyWorldTest.jl : This file is the primary file for the DaisyWorldTest module. This file ‘includes’ DaisyWorld’.jl
  2. DaisyWorld.jl file is not a module by itself. It ‘uses’ Agents and InteractiveDynamics and creates the plot.
    When I go to Pkg mode (’]’) and do precompile. It fails with abmplot undefvar error.
    If I open the DaisyWorld.jl file and execute it in repl. It works perfectly and generates the plot.

I found a fix, but I am still unsatisfied without being able to figure out what I did wrong.

Fix: I wrapped the code inside DaisyWorld.jl inside a module. Now, the DaisyWorld.jl starts with the line
`module MyModule’.

I modified the DaisyWorldTest.jl as follows


using .MyModule

Now precompile works fine. No more issues…

I am moving on. .But why? what did I do wrong?..whats the difference?
I am slightly worried that if I don’t address this debt, I might have to pay the cost later.

@fbanning Thank you very much for your help. I really appreciate it.

Edit: Replicated the same in a new machine (mac mini). Followed the steps as explained in the first post. Same error!

I’m still not able to replicate this in a new environment (add InteractiveDynamics, Agents, CairoMakie) with exactly your two files (DaisyWorldTest.jl as the module that includes Daisworld.jl). If I then just run DaisyWorldTest.jl in this environment, it compiles and works just fine. No errors, nothing. I can produce the plot just fine after including DaisyWorldTest.jl by running DaisyWorldTest.abmplot(DaisyWorldTest.model; DaisyWorldTest.plotkwargs...) just as we could expect it from how you laid out your code. Sorry, I don’t think this is an issue with Agents and/or InteractiveDynamics.

Kindly explain what you mean by “run DaisyWorldTest.jl”. Did you try “precompile”.
If you meant executing the file in REPL. It works for me as well. No issues there. But precompile fails.
Made a quick video. Unfortunately, can’t upload here. Sent to you in slack.

Edit: uploaded the video to youtube as an unlisted video

Yes, worked without any problems.

@codekomali did you manage to get a solution to this? I am having similar issues with the Flocking example in Agents.

Based on the publication connected with Agents.jl ( https://doi.org/10.1177/00375497211068820) abmplot should actually be abm_plot, which does work. So this is probably just a typo in the Tutorial docs. The same goes for abmvideo.

For the Flocking example I still have errors that stem from the Scheduler with:

ABM( SchellingAgent, space; properties, rng, scheduler = Schedulers.Randomly())
ERROR: UndefVarError: Randomly not defined

and with the marker definition:

const bird_polygon = Polygon(Point2f[(-0.5, -0.5), (1, 0), (-0.5, 0.5)])
ERROR: UndefVarError: Point2f not defined

but for now just removing and using the defaults suffices.

They have recently been reworked and renamed. If you’re using an up-to-date version of InteractiveDynamics.jl, you should switch to using abmplot/abmvideo.