Makie - Makie crashes

I am trying to explore using Makie for some interactive applications and I have a hurdle that I am not sure how to get over. When following the tutorial for Schelling’s Segregation model on the Agents.jl page, Makie just creates a blank screen and then vanishes (picture attached). I am not sure how to debug the problem.

I am running Ubuntu 20.04 LTS with Julia 1.6.0.

Code

using Agents
using Random
using Statistics:mean
using InteractiveDynamics
using GLMakie

mutable struct SchellingAgent <: AbstractAgent
    id::Int
    pos::NTuple{2,Int}
    mood::Bool
    group::Int
end

function initialise(; numagents=320, griddims=(20, 20), min_to_be_happy=3, seed=125)
    space = GridSpace(griddims, periodic=false)
    properties = Dict(:min_to_be_happy => min_to_be_happy)
    rng = Random.MersenneTwister(seed)
    model = ABM(
        SchellingAgent, space;
        properties, rng, scheduler=Schedulers.randomly
    )

    for n in 1:numagents
        agent = SchellingAgent(n, (1, 1), false, n < numagents / 2 ? 1 : 2)
        add_agent_single!(agent, model)
    end
    return model

end

function agent_step!(agent, model)
    minhappy = model.min_to_be_happy
    count_neighbours_same_group = 0
    
    for neighbour in nearby_agents(agent, model)
        if agent.group == neighbour.group
            count_neighbours_same_group += 1
        end
    end
    
    if count_neighbours_same_group >= minhappy
        agent.mood = true
    else
        move_agent_single!(agent, model)
    end
    return

end

x(agent) = agent.pos[1]
groupcolor(a) = a.group == 1 ? :blue : :orange
groupmarker(a) = a.group == 1 ? :circle : :rect 

parange = Dict(:min_to_be_happy => 0:8)
adata = [(:mood, sum), (x, mean)]
alabels = ["happy", "avg. x"]

model = initialise(; numagents=300)

figure, adf, mdf = abm_data_exploration(
    model, agent_step!, dummystep, parange;
    ac=groupcolor, am=groupmarker, as=10, 
    adata, alabels
)

I can’t reproduce that… How did you run the code?
You could try display(figure), which may give you at least a stacktrace…

Hey sandisch,

I just run it with julia schelling.jl.

I added your suggestion, but it did not output anything. It had the same result.

Ahhh, I see :smiley:
The display loop isn’t blocking by default, since most people run code in the repl or vscode, to work on things interactively.
So if you run julia schelling.jl, it will just quit as soon as the script run through.
I recommend working with the REPL / VSCode (simplest form would be to start the julia repl and run include("schelling.jl")).
If you really must run this as a script, you can do wait(display(figure)).

2 Likes

Thank you kindly