Is there an alternative to the agents_first keyword?

I’m upgrading my code to Agents.jl 6.x and I get an error stating that there is an unsupported keyword “agents_first” for the run! function. I guess that the default is still the same (agents first) but I need the model_step! function to be called before the agent_step! function. Is there a new way to accomplish this?

This is the code I’m running:

function stepper!(model::ABM, step::Integer)
    model.step += 1

    return step >= model.run_steps
end

function run_econo_model!(model::ABM, steps::Integer, actors_first = false; kwargs...)
    abmproperties(model)[:run_steps] = steps

    run!(model, stepper!, agents_first = actors_first; kwargs...)
end

This is the complete error I’m getting:
SuMSy contribution - none: Error During Test at /Users/stef/Programming/Visual Studio/EconoSim.jl/test/models_test.jl:5
Got exception outside of a @test
MethodError: no method matching run!(::StandardABM{Nothing, MonetaryActor, Dict{Int64, MonetaryActor}, Tuple{DataType}, typeof(actor_step!), typeof(econo_model_step!), typeof(Agents.Schedulers.fastest), Dict{Symbol, Any}, Random.TaskLocalRNG}, ::typeof(EconoSim.stepper!); agents_first::Bool, adata::Vector{typeof(sumsy_assets)})

Closest candidates are:
run!(::Any, ::Any, ::Any, ::Any; when, when_model, mdata, adata, obtainer, agents_first, showprogress, warn_deprecation)
@ Agents ~/.julia/packages/Agents/ONd0c/src/deprecations.jl:118
run!(::AgentBasedModel, ::Any, ::Int64; warn_deprecation, kwargs…)
@ Agents ~/.julia/packages/Agents/ONd0c/src/deprecations.jl:115
run!(::AgentBasedModel, ::Union{Function, Real}; when, when_model, mdata, adata, obtainer, showprogress, init, dt) got unsupported keyword argument “agents_first”
@ Agents ~/.julia/packages/Agents/ONd0c/src/simulations/collect.jl:100

Stacktrace:
[1] kwerr(::@NamedTuple{agents_first::Bool, adata::Vector{typeof(sumsy_assets)}}, ::Function, ::StandardABM{Nothing, MonetaryActor, Dict{Int64, MonetaryActor}, Tuple{DataType}, typeof(actor_step!), typeof(econo_model_step!), typeof(Agents.Schedulers.fastest), Dict{Symbol, Any}, Random.TaskLocalRNG}, ::Function)
@ Base ./error.jl:165
[2] run_econo_model!(model::StandardABM{Nothing, MonetaryActor, Dict{Int64, MonetaryActor}, Tuple{DataType}, typeof(actor_step!), typeof(econo_model_step!), typeof(Agents.Schedulers.fastest), Dict{Symbol, Any}, Random.TaskLocalRNG}, steps::Int64, actors_first::Bool; kwargs::@Kwargs{adata::Vector{typeof(sumsy_assets)}})
@ EconoSim ~/Programming/Visual Studio/EconoSim.jl/src/models/econo_model.jl:88
[3] macro expansion
@ ~/Programming/Visual Studio/EconoSim.jl/test/models_test.jl:9 [inlined]
[4] macro expansion
@ ~/Library/Julia/Julia-1.10.app/Contents/Resources/julia/share/julia/stdlib/v1.10/Test/src/Test.jl:1577 [inlined]
[5] top-level scope
@ ~/Programming/Visual Studio/EconoSim.jl/test/models_test.jl:6
[6] eval
@ ./boot.jl:385 [inlined]
[7] include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String)
@ Base ./loading.jl:2076
[8] include_string(m::Module, txt::String, fname::String)
@ Base ./loading.jl:2086
[9] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
@ Base ./essentials.jl:892
[10] invokelatest(::Any, ::Any, ::Vararg{Any})
@ Base ./essentials.jl:889
[11] inlineeval(m::Module, code::String, code_line::Int64, code_column::Int64, file::String; softscope::Bool)
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.76.2/scripts/packages/VSCodeServer/src/eval.jl:263
[12] (::VSCodeServer.var"#69#74"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.76.2/scripts/packages/VSCodeServer/src/eval.jl:181
[13] withpath(f::VSCodeServer.var"#69#74"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String)
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.76.2/scripts/packages/VSCodeServer/src/repl.jl:274
[14] (::VSCodeServer.var"#68#73"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.76.2/scripts/packages/VSCodeServer/src/eval.jl:179
[15] hideprompt(f::VSCodeServer.var"#68#73"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.76.2/scripts/packages/VSCodeServer/src/repl.jl:38
[16] (::VSCodeServer.var"#67#72"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.76.2/scripts/packages/VSCodeServer/src/eval.jl:150
[17] with_logstate(f::Function, logstate::Any)
@ Base.CoreLogging ./logging.jl:515
[18] with_logger
@ ./logging.jl:627 [inlined]
[19] (::VSCodeServer.var"#66#71"{VSCodeServer.ReplRunCodeRequestParams})()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.76.2/scripts/packages/VSCodeServer/src/eval.jl:255
[20] #invokelatest#2
@ ./essentials.jl:892 [inlined]
[21] invokelatest(::Any)
@ Base ./essentials.jl:889
[22] (::VSCodeServer.var"#64#65")()
@ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.76.2/scripts/packages/VSCodeServer/src/eval.jl:34
Test Summary: | Error Total Time
SuMSy contribution - none | 1 1 1.0s
ERROR: Some tests did not pass: 0 passed, 0 failed, 1 errored, 0 broken.

Thanks in advance,
Stef

In v6 agents_first should be specified at model creation:

StandardABM(...; agents_first = true)

this seems a bit too restrictive though and it can be easily improved (just make it possible to change agents_first in the model), please open an issue on Github to track it if this is creating problems to you

1 Like

Thanks! In my case I can work with that. I guess the developers thought that there would be very few cases where you’d need to change the parameter from one run to another. There probably are some though.