Skip to content

Commit

Permalink
Removed superfluous type check and updated warning messages
Browse files Browse the repository at this point in the history
  • Loading branch information
veddox committed Dec 21, 2022
1 parent 856bb64 commit f6593e2
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/core/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ function agent_validator(
seeing this warning because you gave `Agent` instead of `Agent{Float64}`
(for example) to this function. You can also create an instance of your agent
and pass it to this function. If you want to use `Union` types for mixed agent
models, you can silence this warning.
models, you can silence this warning by passing `warn=false` to `AgentBasedModel()`.
"""
for type in union_types(A)
do_checks(type, space, warn)
Expand All @@ -325,18 +325,16 @@ function do_checks(::Type{A}, space::S, warn::Bool) where {A<:AbstractAgent,S<:S
if space !== nothing
space_type = typeof(space)
if warn && !(any(isequal(:pos), fieldnames(A)) && fieldnames(A)[2] == :pos)
@warn "Second field of Agent struct should be `pos` when using a space."
@warn "Second field of Agent struct must be `pos` when using a space, unless you are purposely working with a NoSpaceAgent."
elseif any(isequal(:pos), fieldnames(A))
# Check `pos` field in A has the correct type
pos_type = fieldtype(A, :pos)
if space_type <: GraphSpace && !(pos_type <: Integer)
throw(ArgumentError("`pos` field in Agent struct must be of type `Int` when using GraphSpace."))
elseif space_type <: GridSpace && !(pos_type <: NTuple{D,Integer} where {D})
throw(ArgumentError("`pos` field in Agent struct must be of type `NTuple{Int}` when using GridSpace."))
elseif space_type <: ContinuousSpace || space_type <: ContinuousSpace #FIXME this seems wrong?
if !(pos_type <: NTuple{D,<:AbstractFloat} where {D})
throw(ArgumentError("`pos` field in Agent struct must be of type `NTuple{<:AbstractFloat}` when using ContinuousSpace."))
end
elseif space_type <: ContinuousSpace && !(pos_type <: NTuple{D,<:AbstractFloat} where {D})
throw(ArgumentError("`pos` field in Agent struct must be of type `NTuple{<:AbstractFloat}` when using ContinuousSpace."))
end
end
if warn && space_type <: ContinuousSpace &&
Expand Down

0 comments on commit f6593e2

Please sign in to comment.