Agents.jl
Agents.jl copied to clipboard
Recommended way to use StaticVector types for agent vel field
I'm developing a model where the agent stepping function makes use of some linear algebra functions that are not out-of-the-box compatible with tuples (mainly rotations of agent.vel
, requiring matrix multiplications and adjoints).
One option would be to rewrite said functions to explicitly work with tuples but I'd rather just use StaticVector types.
I'm fairly new to the library (and love it!), and the first way I found to make this work is to extend the walk!
function which, for continuous agents, has the strict typing direction::Tuple{Vararg{Float64,D}}
Agents.walk!(agent::AbstractAgent, direction, model::ABM{<:ContinuousSpace}) = Agents.walk!(agent, Tuple(direction), model)
Everything seems to work fine with this "hack", but I get a warning everytime I run the model
┌ Warning: `vel` field in Agent struct should be of type `NTuple{<:AbstractFloat}` when using ContinuousSpace.
└ @ Agents ~/.julia/packages/Agents/207mT/src/core/model.jl:337
and I'm not sure whether something else might break under the hood by using a StaticVector vel
(I don't think so, but it's worth being sure).
- Can the usage of a StaticVector type for
agent.vel
in general be problematic? If yes, in what ways, and if not, why does Agents.jl enforce tuples? Are there performance reasons behind this choice? - Is there another, recommended way, to allow for StaticVector types?
- Minor: can the warning be suppressed?
Thanks for the great work!
Yeah this is a "problem" that we've encountered before that "formal vectors" are much more useful in continuous space. I'm thinking of making the agent fields for ContinuousSpace to be SVector
. But then again, I have problems because static vectors should be supported from the core Julia language. They aren't.
You can silence warnings when you make the model with a keyword.
There is no problem or issue in using static vectors instead. Use SVector(tuple)
and Tuple(svector)
to convert between the two.
I'm fairly new to the library (and love it!), and the first way I found to make this work is to extend the walk! function which, for continuous agents, has the strict typing direction::Tuple{Vararg{Float64,D}}
Thanks :) You can do a simple pull request that extends this restriction to a more generic type.