Skip to content

Commit

Permalink
ensure all tests are consistent with internal assignment of unique_id
Browse files Browse the repository at this point in the history
  • Loading branch information
quaquel committed Sep 4, 2024
1 parent 79f3b60 commit db16dac
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
3 changes: 2 additions & 1 deletion mesa/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ def __init__(self, *args, **kwargs) -> None:
Args:
model (Model): The model instance in which the agent exists.
"""
# FIXME, at some future point, turn *args back into model and remove this if else
if len(args) == 1:
model = args[0]
unique_id = next(self._ids[model])
# unique_id = next(self._ids[model])
else:
warnings.warn(
"unique ids are assigned automatically in MESA 3",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def remove_function(agent):

def test_agentset_agg():
model = Model()
agents = [TestAgent(i, model) for i in range(10)]
agents = [TestAgent(model) for i in range(10)]

# Assign some values to attributes
for i, agent in enumerate(agents):
Expand Down
35 changes: 17 additions & 18 deletions tests/test_batch_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ class MockAgent(Agent):
Minimalistic agent implementation for testing purposes
"""

def __init__(self, unique_id, model, val):
super().__init__(unique_id, model)
self.unique_id = unique_id
def __init__(self, model, val):
super().__init__(model)
self.val = val
self.local = 0

Expand Down Expand Up @@ -77,7 +76,7 @@ def init_agents(self):
else:
agent_val = self.variable_agent_param
for i in range(self.n_agents):
self.schedule.add(MockAgent(i, self, agent_val))
self.schedule.add(MockAgent(self, agent_val))

def get_local_model_param(self):
return 42
Expand All @@ -95,26 +94,26 @@ def test_batch_run():
"iteration": 0,
"Step": 1000,
"reported_model_param": 42,
"AgentID": 0,
"agent_id": 0,
"AgentID": 1,
"agent_id": 1,
"agent_local": 250.0,
},
{
"RunId": 0,
"iteration": 0,
"Step": 1000,
"reported_model_param": 42,
"AgentID": 1,
"agent_id": 1,
"AgentID": 2,
"agent_id": 2,
"agent_local": 250.0,
},
{
"RunId": 0,
"iteration": 0,
"Step": 1000,
"reported_model_param": 42,
"AgentID": 2,
"agent_id": 2,
"AgentID": 3,
"agent_id": 3,
"agent_local": 250.0,
},
]
Expand Down Expand Up @@ -172,29 +171,29 @@ def test_batch_run_unhashable_param():
{
"RunId": 0,
"iteration": 0,
"AgentID": 0,
"agent_id": 0,
"AgentID": 1,
"agent_id": 1,
**template,
},
{
"RunId": 0,
"iteration": 0,
"AgentID": 1,
"agent_id": 1,
"AgentID": 2,
"agent_id": 2,
**template,
},
{
"RunId": 1,
"iteration": 1,
"AgentID": 0,
"agent_id": 0,
"AgentID": 1,
"agent_id": 1,
**template,
},
{
"RunId": 1,
"iteration": 1,
"AgentID": 1,
"agent_id": 1,
"AgentID": 2,
"agent_id": 2,
**template,
},
]
4 changes: 2 additions & 2 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class Sheep(Agent):
pass

model = Model()
wolf = Wolf(1, model)
sheep = Sheep(2, model)
wolf = Wolf(model)
sheep = Sheep(model)

assert model.agents_by_type[Wolf] == AgentSet([wolf], model)
assert model.agents_by_type[Sheep] == AgentSet([sheep], model)
Expand Down

0 comments on commit db16dac

Please sign in to comment.