Agents.jl problem with the step! function

Hi I am new to Agents.jl and Julia, I am following the official online tutorial on the Shelling’s model, however I am facing a hard time with the step! function, I tried to use the same source code as in the tutorial but I always get an Error from the stepping function and a warning(see image below). Note that the custom step function I created works fine I tested it in the REPL, and also when I use step!(model, n=5) I get MethodError.
I really appreciate your help and time.

using Agents


mutable struct Schelling <: AbstractAgent
    id::Int
    pos::Tuple{Int,Int}
    group::Int
    happy::Bool
end


function agent_step!(agent,model,)
    #println("checking agent: ",agent.id)
    #println("Happy: ",agent.happy)
    if agent.happy == true
        println("I am happy")
        return
    end
    nearby_same = 0
    for neighbor in nearby_agents(agent,model)
        println("nearby_same: ",nearby_same," neighbor: ",neighbor.id," neighbor group: ",neighbor.group)
        if neighbor.group == agent.group
            nearby_same += 1
        end
    end
    if nearby_same >= model.min_to_be_happy
        println("nearby_same:00 ",nearby_same)
        agent.happy = true
    else
        move_agent_single!(agent,model)
        println("jumped to: ",agent.pos)
    end
    return
end

function initilize(;N = 10, M = 4, min_to_be_happy = 2,steppingFunction = agent_step!)
    space = GridSpace((M,M))
    properties = Dict(:min_to_be_happy => min_to_be_happy)
    scheduler = Schedulers.Randomly
    model = AgentBasedModel(Schelling,space;properties = properties, scheduler = scheduler,agent_step! = steppingFunction)

    for n in 1:N
        agent = Schelling(n,(1,1),n < N/2 ? 1 : 2,false)
        add_agent_single!(agent,model) #This adds agents at a random and empty location in the space
    end
    return model
end



model = initilize()
step!(model,agent_step!,dummystep)

And here is the warning I face:

┌ Warning: Passing agent_step! and model_step! to step! is deprecated. Use 
     the new version
│              step!(model, n = 1, agents_first = true)

The Error:

ERROR: MethodError: Cannot `convert` an object of type StandardABM{GridSpace{2, true}, Schelling, Dict{Int64, Schelling}, Tuple{DataType}, typeof(agent_step!), typeof(dummystep), DataType, Dict{Symbol, Int64}, Random.TaskLocalRNG} to an object of type Vector{Int64}

Hi! Which version of the package are you using?

The current version (6) has a tutorial for this (Tutorial · Agents.jl) which differs in some key areas from your code.

1 Like

I am using 6.0.17. Thank you for the tutorial page.

Perhaps try the latest (current) version of the tutorial…?

1 Like

The current tutorial is really different from this tutorial.

That says v5.3.0 at the bottom left. So it should work if you download Agents v5.3 and run it in that environment…

1 Like

You know I figured what was triggering the problem, but still did not delve into why it is happening though. The error in my previous (old version) and current code is triggered by the scheduler I used. These two schedulers causes the problem: Schedulers.Randomly and Schedulers.ByID, however, in the latter we can achieve the same behavior by using Schedulers.ByProperty(:id). :confused: