# Why does GridSpace zero/ negative coordinates yields an Error but still adds the agents to the model

**URL:** <https://discourse.julialang.org/t/why-does-gridspace-zero-negative-coordinates-yields-an-error-but-still-adds-the-agents-to-the-model/135020>\
**Category:** General Usage\
**Tags:** agents, agentsjl\
**Created:** [January 13, 2026, 10:26am UTC](https://discourse.julialang.org/t/why-does-gridspace-zero-negative-coordinates-yields-an-error-but-still-adds-the-agents-to-the-model/135020 "2026-01-13T10:26:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Farouk](https://avatars.discourse-cdn.com/v4/letter/f/f17d59/32.png) [@Farouk](https://discourse.julialang.org/u/Farouk)\
**Post date:** [January 13, 2026, 10:26am UTC](https://discourse.julialang.org/t/why-does-gridspace-zero-negative-coordinates-yields-an-error-but-still-adds-the-agents-to-the-model/135020/1 "2026-01-13T10:26:52Z")

</div>

Hello guys,  
I have a question regarding Agents.jl `GridSpace` does it allow coordinates that are negative or zero like `(0,0)` or `(-5,-1)`.  
In the test I’ve done (See code below) when I put a zero coordinates it returns an error but when checking the model I find the agent have been added to that position.

```julia-auto
using Agents

@agent struct Customer(GridAgent{2}) 
    age
end

space = GridSpace((100,100); periodic = false, metric = :euclidean)
model = StandardABM(Customer, space)
add_agent!((0,0), model,25)

```

When executing this it gives a `BoundsError`:

```julia-auto
BoundsError: attempt to access 100×100 Matrix{Vector{Int64}} at index [0, 0]

```

However when I check I find that the agent has been added:

```julia-auto
allagents(model)

```

It gives the output:

```julia-auto
ValueIterator for a Dict{Int64, Customer} with 1 entry. Values:
  Customer(1, (0, 0), 25)

```

The same behavior is observed for the negative position coordinates:

```julia-auto
add_agent!((-1,-1), model,25)

Output:
BoundsError: attempt to access 100×100 Matrix{Vector{Int64}} at index [-1, -1]

```

And when I check the agent is added:

```julia-auto
ValueIterator for a Dict{Int64, Customer} with 2 entries. Values:
  Customer(2, (-1, -1), 25)
  Customer(1, (0, 0), 25)

```

How does this happen is there any explanation of what going on ?  
Thanks in advance for your help 🙂

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [January 13, 2026, 10:34am UTC](https://discourse.julialang.org/t/why-does-gridspace-zero-negative-coordinates-yields-an-error-but-still-adds-the-agents-to-the-model/135020/2 "2026-01-13T10:34:11Z")

</div>

> [@Farouk](#):
>
> `GridSpace` does it allow coordinates that are negative or zero like `(0,0)` or `(-5,-1)`.

No It does not, because (on purpose and for simplicity) the positions of agents in a grid space are exactly the same as the indices of accessing the underlying storage array. and in julia the default array type has indices starting from 1 onwards.

You’ll need to approach your problem differently to avoid negative positions or use a continuous space.

---

<div class="post-metadata">

**Author:** ![Farouk](https://avatars.discourse-cdn.com/v4/letter/f/f17d59/32.png) [@Farouk](https://discourse.julialang.org/u/Farouk)\
**Post date:** [January 13, 2026, 10:48am UTC](https://discourse.julialang.org/t/why-does-gridspace-zero-negative-coordinates-yields-an-error-but-still-adds-the-agents-to-the-model/135020/4 "2026-01-13T10:48:05Z")

</div>

Yes but the problem is that it is adding agents to the model so when using `all_agents(model)` it returns all the agents even the ones outside the grid space. However, when using dedicated functions such as `nearby_ids(pos, model, radius)` it only return the valid agents with valid positions (which is understandable). Isn’t this considered somewhat of a bug ??

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [January 13, 2026, 11:25am UTC](https://discourse.julialang.org/t/why-does-gridspace-zero-negative-coordinates-yields-an-error-but-still-adds-the-agents-to-the-model/135020/5 "2026-01-13T11:25:18Z")

</div>

yes, the fact that agents with negative positions can be added to the grid is a bug; you can open an issue at the GitHub repo or open a PR to fix it directly. Do not rely on it and follow the rules outlined by the documentation (positive indices).
