From 402631671aa612ae9fca4d0870a1fdc4ff59d008 Mon Sep 17 00:00:00 2001 From: Ewout ter Hoeven Date: Sat, 21 Sep 2024 22:36:48 +0200 Subject: [PATCH] intro_tutorial: Don't initialize agents with an unique_id (#2315) This resolves about half of the warnings in the intro_tutorial. * intro_tutorial: Don't initialize agents with an unique_id * tutorial: Also update MoneyModel * tutorial: Don't pass/require unique_id on MoneyAgent init --- docs/tutorials/MoneyModel.py | 4 +- docs/tutorials/intro_tutorial.ipynb | 62 ++++++++++++++--------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/docs/tutorials/MoneyModel.py b/docs/tutorials/MoneyModel.py index d723a52b654..08b89726fdb 100644 --- a/docs/tutorials/MoneyModel.py +++ b/docs/tutorials/MoneyModel.py @@ -63,8 +63,8 @@ def __init__(self, N, width, height): self.schedule = mesa.time.RandomActivation(self) # Create agents - for i in range(self.num_agents): - a = MoneyAgent(i, self) + for _ in range(self.num_agents): + a = MoneyAgent(self) self.schedule.add(a) # Add the agent to a random grid cell x = self.random.randrange(self.grid.width) diff --git a/docs/tutorials/intro_tutorial.ipynb b/docs/tutorials/intro_tutorial.ipynb index 28b855b3f68..d791f7d1d1e 100644 --- a/docs/tutorials/intro_tutorial.ipynb +++ b/docs/tutorials/intro_tutorial.ipynb @@ -194,9 +194,9 @@ "class MoneyAgent(mesa.Agent):\n", " \"\"\"An agent with fixed initial wealth.\"\"\"\n", "\n", - " def __init__(self, unique_id, model):\n", + " def __init__(self, model):\n", " # Pass the parameters to the parent class.\n", - " super().__init__(unique_id, model)\n", + " super().__init__(model)\n", "\n", " # Create the agent's variable and set the initial values.\n", " self.wealth = 1" @@ -232,8 +232,8 @@ " super().__init__()\n", " self.num_agents = N\n", " # Create agents\n", - " for i in range(self.num_agents):\n", - " a = MoneyAgent(i, self)" + " for _ in range(self.num_agents):\n", + " a = MoneyAgent(self)" ] }, { @@ -261,9 +261,9 @@ "class MoneyAgent(mesa.Agent):\n", " \"\"\"An agent with fixed initial wealth.\"\"\"\n", "\n", - " def __init__(self, unique_id, model):\n", + " def __init__(self, model):\n", " # Pass the parameters to the parent class.\n", - " super().__init__(unique_id, model)\n", + " super().__init__(model)\n", "\n", " # Create the agent's attribute and set the initial values.\n", " self.wealth = 1\n", @@ -284,8 +284,8 @@ " self.schedule = mesa.time.RandomActivation(self)\n", "\n", " # Create agents\n", - " for i in range(self.num_agents):\n", - " a = MoneyAgent(i, self)\n", + " for _ in range(self.num_agents):\n", + " a = MoneyAgent(self)\n", " # Add the agent to the scheduler\n", " self.schedule.add(a)\n", "\n", @@ -357,9 +357,9 @@ "class MoneyAgent(mesa.Agent):\n", " \"\"\"An agent with fixed initial wealth.\"\"\"\n", "\n", - " def __init__(self, unique_id, model):\n", + " def __init__(self, model):\n", " # Pass the parameters to the parent class.\n", - " super().__init__(unique_id, model)\n", + " super().__init__(model)\n", "\n", " # Create the agent's variable and set the initial values.\n", " self.wealth = 1\n", @@ -424,9 +424,9 @@ "class MoneyAgent(mesa.Agent):\n", " \"\"\"An agent with fixed initial wealth.\"\"\"\n", "\n", - " def __init__(self, unique_id, model):\n", + " def __init__(self, model):\n", " # Pass the parameters to the parent class.\n", - " super().__init__(unique_id, model)\n", + " super().__init__(model)\n", "\n", " # Create the agent's variable and set the initial values.\n", " self.wealth = 1\n", @@ -464,7 +464,7 @@ "outputs": [], "source": [ "model = MoneyModel(10)\n", - "for i in range(10):\n", + "for _ in range(10):\n", " model.step()" ] }, @@ -511,10 +511,10 @@ "source": [ "all_wealth = []\n", "# This runs the model 100 times, each model executing 10 steps.\n", - "for j in range(100):\n", + "for _ in range(100):\n", " # Run the model\n", " model = MoneyModel(10)\n", - " for i in range(10):\n", + " for _ in range(10):\n", " model.step()\n", "\n", " # Store the results\n", @@ -573,8 +573,8 @@ " self.schedule = mesa.time.RandomActivation(self)\n", "\n", " # Create agents\n", - " for i in range(self.num_agents):\n", - " a = MoneyAgent(i, self)\n", + " for _ in range(self.num_agents):\n", + " a = MoneyAgent(self)\n", " self.schedule.add(a)\n", "\n", " # Add the agent to a random grid cell\n", @@ -653,8 +653,8 @@ "class MoneyAgent(mesa.Agent):\n", " \"\"\"An agent with fixed initial wealth.\"\"\"\n", "\n", - " def __init__(self, unique_id, model):\n", - " super().__init__(unique_id, model)\n", + " def __init__(self, model):\n", + " super().__init__(model)\n", " self.wealth = 1\n", "\n", " def move(self):\n", @@ -686,8 +686,8 @@ " self.grid = mesa.space.MultiGrid(width, height, True)\n", " self.schedule = mesa.time.RandomActivation(self)\n", " # Create agents\n", - " for i in range(self.num_agents):\n", - " a = MoneyAgent(i, self)\n", + " for _ in range(self.num_agents):\n", + " a = MoneyAgent(self)\n", " self.schedule.add(a)\n", " # Add the agent to a random grid cell\n", " x = self.random.randrange(self.grid.width)\n", @@ -712,7 +712,7 @@ "outputs": [], "source": [ "model = MoneyModel(100, 10, 10)\n", - "for i in range(20):\n", + "for _ in range(20):\n", " model.step()" ] }, @@ -771,8 +771,8 @@ "class MoneyAgent(mesa.Agent):\n", " \"\"\"An agent with fixed initial wealth.\"\"\"\n", "\n", - " def __init__(self, unique_id, model):\n", - " super().__init__(unique_id, model)\n", + " def __init__(self, model):\n", + " super().__init__(model)\n", " self.wealth = 1\n", "\n", " def move(self):\n", @@ -810,8 +810,8 @@ " self.schedule = mesa.time.RandomActivation(self)\n", "\n", " # Create agents\n", - " for i in range(self.num_agents):\n", - " a = MoneyAgent(i, self)\n", + " for _ in range(self.num_agents):\n", + " a = MoneyAgent(self)\n", " self.schedule.add(a)\n", " # Add the agent to a random grid cell\n", " x = self.random.randrange(self.grid.width)\n", @@ -845,7 +845,7 @@ "outputs": [], "source": [ "model = MoneyModel(100, 10, 10)\n", - "for i in range(100):\n", + "for _ in range(100):\n", " model.step()" ] }, @@ -1052,8 +1052,8 @@ " self.running = True\n", "\n", " # Create agents\n", - " for i in range(self.num_agents):\n", - " a = MoneyAgent(i, self)\n", + " for _ in range(self.num_agents):\n", + " a = MoneyAgent(self)\n", " self.schedule.add(a)\n", " # Add the agent to a random grid cell\n", " x = self.random.randrange(self.grid.width)\n", @@ -1073,8 +1073,8 @@ "class MoneyAgent(mesa.Agent):\n", " \"\"\"An agent with fixed initial wealth.\"\"\"\n", "\n", - " def __init__(self, unique_id, model):\n", - " super().__init__(unique_id, model)\n", + " def __init__(self, model):\n", + " super().__init__(model)\n", " self.wealth = 1\n", " self.steps_not_given = 0\n", "\n",