Agent-Based Models with Python: An Introduction to Mesa
Hi there,
I am getting this error when I run the code from step 7.
"""
self.grid.place_agent(trader, (x,y))
:83: UserWarning: Agent 4139 is being placed with
place_agent() despite already having the position (30, 30). In most
cases, you'd want to clear the current position with remove_agent()
before placing the agent again.
"""It seems to happen with the code from the github as well. Any ideas?
Hi Geoff,
place_agent method checks whether the agent already has a position before placing it. You could simply solve this issue by setting pos = None when creating a new agent. Here is the source code.
@warn_if_agent_has_position_already
def place_agent(self, agent: Agent, pos: Coordinate) -> None:
"""Place the agent at the specified location, and set its pos variable."""
x, y = pos
if agent.pos is None or agent not in self._grid[x][y]:
self._grid[x][y].append(agent)
agent.pos = pos
if self._empties_built:
self._empties.discard(pos)
self._empty_mask[agent.pos] = True
I'm running the code as shown in session 5 but getting the follow error - any ideas?
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
----> 1 model = SugarscapeG1mt()in __init__(self, width, height)
19
20 agent_id = 0
---> 21 for (x,y) in self.grid.coord_iter():
22 max_sugar = sugar_distribution[x,y]
23 if max_sugar > 0:ValueError: too many values to unpack (expected 2)
I've not figured out the error:
for _,(x,y) in self.grid.coord_iter():needs the brackets around (x,y) removed to become:
for _,x,y in self.grid.coord_iter():I have forked the session 5 on GitHub and suggested the change
- Eka Putri Difayanti
- 10 Nov 2024 10:37pm UTC
- in Agent-Based Models with Python: An Introduction to Mesa
I have the same problem. Did you find a solution?
I've had the same problem as well, did anyone come across a solution?
Did this fix not work?
for _,(x,y) in self.grid.coord_iter():needs the brackets around (x,y) removed to become:
for _,x,y in self.grid.coord_iter():Hi Tom, actually I am struggling with another issue when I try to run the last step in the fifth session I get this error about the number of arguments being incorrect with the __init__() function in the Sugar agent parameters, but the code I've used is a direct copy of the Session 5 code provided. Any thoughts on how to troubleshoot would be greatly appreciated. I am new to Python & ABM so the syntax is still new to me
Error message:
TypeError Traceback (most recent call last)
in ()
----> 1 model = SugarscapeG1mt()2 frames
/usr/local/lib/python3.10/dist-packages/mesa/agent.py in __init__(self, model, *args, **kwargs)
62
63 """
---> 64 super().__init__(*args, **kwargs)
65
66 self.model: Model = modelTypeError: object.__init__() takes exactly one argument (the instance to initialize)
Subforums
- Introduce Yourself
- Class Announcements
- Study Groups and Meetups
- Technical Issues
- General Discussion
- Course Feedback
- Course Materials to Share
- Fundamentals of NetLogo
- Functions and Iterations
- Introduction to Differential Equations
- Ordinary Differential Equations
- Maximum Entropy Methods
- Random Walks
- Introduction to Information Theory
- Vector and Matrix Algebra
- Introduction to Renormalization
- Game Theory I • Static Games
- Game Theory II • Dynamic Games
- Fundamentals of Machine Learning
- Introduction to Computation Theory
- Fundamentals of NetLogo
- Lecture: Pandemics
- Lecture: Artificial Intelligence
- Lecture: Crime and Punishment
- Complexity-GAINs Curriculum
- Introduction to Open Science
- Journal Club
- IN DEVELOPMENT: Multicellularity Modules
- UCR Application Tutorial
- Lecture: What is Complexity?
- Agent-Based Models with Python: An Introduction to Mesa
- Lecture: Epistemological emergence