Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Von Neumann grid hits TypeError on agents in corners #1831

Closed
maskarb opened this issue Oct 7, 2023 · 2 comments
Closed

Von Neumann grid hits TypeError on agents in corners #1831

maskarb opened this issue Oct 7, 2023 · 2 comments

Comments

@maskarb
Copy link
Contributor

maskarb commented Oct 7, 2023

Describe the bug

I am recreating the Forest Fire example with Mesa 2, and sometimes I hit the following traceback when the model iterates on an agent in the corner of the grid, specifically with Von Neumann neighborhood (when using Moore neighborhood, I haven't seen this exception).

(99, 99) <<< coordinates of agent when exception is raised
Uncaught exception GET /ws (127.0.0.1)
HTTPServerRequest(protocol='http', host='127.0.0.1:8521', method='GET', uri='/ws', version='HTTP/1.1', remote_ip='127.0.0.1')
Traceback (most recent call last):
  File "/Users/mskarbek/projects/opinion-dynamics-leaderboard/.venv/lib/python3.11/site-packages/tornado/websocket.py", line 630, in _run_callback
    result = callback(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mskarbek/projects/opinion-dynamics-leaderboard/.venv/lib/python3.11/site-packages/mesa_viz_tornado/ModularVisualization.py", line 230, in on_message
    self.application.model.step()
  File "/Users/mskarbek/projects/opinion-dynamics-leaderboard/mesa_examples/forest_fire/forest_fire/model.py", line 50, in step
    self.schedule.step()
  File "/Users/mskarbek/projects/opinion-dynamics-leaderboard/.venv/lib/python3.11/site-packages/mesa/time.py", line 128, in step
    self.do_each("step", shuffle=True)
  File "/Users/mskarbek/projects/opinion-dynamics-leaderboard/.venv/lib/python3.11/site-packages/mesa/time.py", line 110, in do_each
    getattr(self._agents[agent_key], method)()
  File "/Users/mskarbek/projects/opinion-dynamics-leaderboard/mesa_examples/forest_fire/forest_fire/agent.py", line 32, in step
    for neighbor in self.model.grid.iter_neighbors(self.pos, False):
  File "/Users/mskarbek/projects/opinion-dynamics-leaderboard/.venv/lib/python3.11/site-packages/mesa/space.py", line 401, in <genexpr>
    if (cell := self._grid[x][y]) != self.default_val()
                ~~~~~~~~~~^^^
TypeError: list indices must be integers or slices, not tuple

Expected behavior

I do not expect a traceback when stepping on agents in the corners of the grid.

To Reproduce

I've pushed the code to this repo:
https://github.com/maskarb/opinion-dynamics-leaderboard/pull/33/files

Using this seed: 8002739158563429809, you hit the error at step 24. In this case, the agent which triggers the traceback is in position (0, 99).

I just run the server:

$ mesa runserver

And then just start the run (keeping the default density).

Additional context

$ python --version                                                                                                        
Python 3.11.5

$ mesa version
mesa 2.1.2
@rht
Copy link
Contributor

rht commented Oct 8, 2023

Thank you for the detailed report.

@rht
Copy link
Contributor

rht commented Oct 8, 2023

Closed via #1832.

@rht rht closed this as completed Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants