From d90b0f72cd65d5875eb9e4012990699cfe886c5c Mon Sep 17 00:00:00 2001 From: Jan Kwakkel Date: Sun, 21 Jan 2024 18:57:57 +0100 Subject: [PATCH 01/12] further updates --- benchmarks/WolfSheep/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/benchmarks/WolfSheep/__init__.py b/benchmarks/WolfSheep/__init__.py index e69de29bb2d..18b86ab19ba 100644 --- a/benchmarks/WolfSheep/__init__.py +++ b/benchmarks/WolfSheep/__init__.py @@ -0,0 +1,14 @@ +from wolf_sheep import WolfSheep + +if __name__ == "__main__": + # for profiling this benchmark model + import time + + # model = WolfSheep(15, 25, 25, 60, 40, 0.2, 0.1, 20) + model = WolfSheep(15, 100, 100, 1000, 500, 0.4, 0.2, 20) + + start_time = time.perf_counter() + for _ in range(100): + model.step() + + print(time.perf_counter() - start_time) From 95864900d9e7981c8ea7240e34672f3fe792d681 Mon Sep 17 00:00:00 2001 From: Jan Kwakkel Date: Sun, 21 Jan 2024 19:13:00 +0100 Subject: [PATCH 02/12] Update benchmarks/WolfSheep/__init__.py --- benchmarks/WolfSheep/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/WolfSheep/__init__.py b/benchmarks/WolfSheep/__init__.py index 18b86ab19ba..98b1e9fdfed 100644 --- a/benchmarks/WolfSheep/__init__.py +++ b/benchmarks/WolfSheep/__init__.py @@ -1,4 +1,4 @@ -from wolf_sheep import WolfSheep +from .wolf_sheep import WolfSheep if __name__ == "__main__": # for profiling this benchmark model From 2759244eb350ce8e38b31b08cbea46e40998893a Mon Sep 17 00:00:00 2001 From: Jan Kwakkel Date: Tue, 27 Aug 2024 14:01:46 +0200 Subject: [PATCH 03/12] Update __init__.py --- benchmarks/WolfSheep/__init__.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/benchmarks/WolfSheep/__init__.py b/benchmarks/WolfSheep/__init__.py index 98b1e9fdfed..e69de29bb2d 100644 --- a/benchmarks/WolfSheep/__init__.py +++ b/benchmarks/WolfSheep/__init__.py @@ -1,14 +0,0 @@ -from .wolf_sheep import WolfSheep - -if __name__ == "__main__": - # for profiling this benchmark model - import time - - # model = WolfSheep(15, 25, 25, 60, 40, 0.2, 0.1, 20) - model = WolfSheep(15, 100, 100, 1000, 500, 0.4, 0.2, 20) - - start_time = time.perf_counter() - for _ in range(100): - model.step() - - print(time.perf_counter() - start_time) From e99811d6dbf649dad8e8df2d940d15ae57d614e4 Mon Sep 17 00:00:00 2001 From: Jan Kwakkel Date: Mon, 9 Sep 2024 08:32:50 +0200 Subject: [PATCH 04/12] move cell_space out of experimental to spaces folder move, rename, import changes --- mesa/__init__.py | 6 ++-- mesa/experimental/__init__.py | 5 +-- mesa/experimental/cell_space/__init__.py | 32 ------------------- mesa/experimental/components/matplotlib.py | 3 +- mesa/spaces/__init__.py | 20 ++++++++++++ .../cell_space => spaces}/cell.py | 4 +-- .../cell_space => spaces}/cell_agent.py | 2 +- .../cell_space => spaces}/cell_collection.py | 4 +-- .../cell_space => spaces}/discrete_space.py | 4 +-- .../cell_space => spaces}/grid.py | 2 +- .../cell_space => spaces}/network.py | 4 +-- .../cell_space => spaces}/voronoi.py | 4 +-- mesa/visualization/components/matplotlib.py | 2 +- tests/test_cell_space.py | 2 +- 14 files changed, 41 insertions(+), 53 deletions(-) delete mode 100644 mesa/experimental/cell_space/__init__.py create mode 100644 mesa/spaces/__init__.py rename mesa/{experimental/cell_space => spaces}/cell.py (97%) rename mesa/{experimental/cell_space => spaces}/cell_agent.py (95%) rename mesa/{experimental/cell_space => spaces}/cell_collection.py (95%) rename mesa/{experimental/cell_space => spaces}/discrete_space.py (94%) rename mesa/{experimental/cell_space => spaces}/grid.py (99%) rename mesa/{experimental/cell_space => spaces}/network.py (90%) rename mesa/{experimental/cell_space => spaces}/voronoi.py (98%) diff --git a/mesa/__init__.py b/mesa/__init__.py index 7e3b014b817..86b49d272b1 100644 --- a/mesa/__init__.py +++ b/mesa/__init__.py @@ -5,7 +5,8 @@ import datetime -import mesa.space as space +import mesa.space as old_space +# import mesa.spaces as spaces import mesa.time as time from mesa.agent import Agent from mesa.batchrunner import batch_run @@ -16,7 +17,8 @@ "Model", "Agent", "time", - "space", + "old_space", + "spaces", "DataCollector", "batch_run", "experimental", diff --git a/mesa/experimental/__init__.py b/mesa/experimental/__init__.py index a48c498f6f9..90fcdcfe2da 100644 --- a/mesa/experimental/__init__.py +++ b/mesa/experimental/__init__.py @@ -1,7 +1,4 @@ """Experimental init.""" - -from mesa.experimental import cell_space - from .solara_viz import JupyterViz, Slider, SolaraViz, make_text -__all__ = ["cell_space", "JupyterViz", "SolaraViz", "make_text", "Slider"] +__all__ = ["JupyterViz", "SolaraViz", "make_text", "Slider"] diff --git a/mesa/experimental/cell_space/__init__.py b/mesa/experimental/cell_space/__init__.py deleted file mode 100644 index 792dde611b9..00000000000 --- a/mesa/experimental/cell_space/__init__.py +++ /dev/null @@ -1,32 +0,0 @@ -"""Cell spaces. - -Cell spaces offer an alternative API for discrete spaces. It is experimental and under development. The API is more -expressive that the default grids available in `mesa.space`. - -""" - -from mesa.experimental.cell_space.cell import Cell -from mesa.experimental.cell_space.cell_agent import CellAgent -from mesa.experimental.cell_space.cell_collection import CellCollection -from mesa.experimental.cell_space.discrete_space import DiscreteSpace -from mesa.experimental.cell_space.grid import ( - Grid, - HexGrid, - OrthogonalMooreGrid, - OrthogonalVonNeumannGrid, -) -from mesa.experimental.cell_space.network import Network -from mesa.experimental.cell_space.voronoi import VoronoiGrid - -__all__ = [ - "CellCollection", - "Cell", - "CellAgent", - "DiscreteSpace", - "Grid", - "HexGrid", - "OrthogonalMooreGrid", - "OrthogonalVonNeumannGrid", - "Network", - "VoronoiGrid", -] diff --git a/mesa/experimental/components/matplotlib.py b/mesa/experimental/components/matplotlib.py index bb3b9854193..2ef52ea6e80 100644 --- a/mesa/experimental/components/matplotlib.py +++ b/mesa/experimental/components/matplotlib.py @@ -8,7 +8,7 @@ from matplotlib.ticker import MaxNLocator import mesa -from mesa.experimental.cell_space import VoronoiGrid + @solara.component @@ -164,6 +164,7 @@ def portray(space): def _draw_voronoi(space, space_ax, agent_portrayal): + from mesa.spaces.voronoi import VoronoiGrid def portray(g): x = [] y = [] diff --git a/mesa/spaces/__init__.py b/mesa/spaces/__init__.py new file mode 100644 index 00000000000..93c907e01bd --- /dev/null +++ b/mesa/spaces/__init__.py @@ -0,0 +1,20 @@ +from mesa.spaces.network import Network +from mesa.spaces.cell import Cell +from mesa.spaces.cell_agent import CellAgent +from mesa.spaces.cell_collection import CellCollection +from mesa.spaces.discrete_space import DiscreteSpace +from mesa.spaces.grid import Grid, HexGrid, OrthogonalMooreGrid, OrthogonalVonNeumannGrid +from mesa.spaces.voronoi import VoronoiGrid + +__all__ = [ + "CellCollection", + "Cell", + "CellAgent", + "DiscreteSpace", + "Grid", + "HexGrid", + "OrthogonalMooreGrid", + "OrthogonalVonNeumannGrid", + "Network", + "VoronoiGrid", +] diff --git a/mesa/experimental/cell_space/cell.py b/mesa/spaces/cell.py similarity index 97% rename from mesa/experimental/cell_space/cell.py rename to mesa/spaces/cell.py index 4e9a8f156cd..c68e1316445 100644 --- a/mesa/experimental/cell_space/cell.py +++ b/mesa/spaces/cell.py @@ -6,10 +6,10 @@ from random import Random from typing import TYPE_CHECKING -from mesa.experimental.cell_space.cell_collection import CellCollection +from mesa.spaces.cell_collection import CellCollection if TYPE_CHECKING: - from mesa.experimental.cell_space.cell_agent import CellAgent + from mesa.spaces.cell_agent import CellAgent class Cell: diff --git a/mesa/experimental/cell_space/cell_agent.py b/mesa/spaces/cell_agent.py similarity index 95% rename from mesa/experimental/cell_space/cell_agent.py rename to mesa/spaces/cell_agent.py index 76a7d16b866..3b81fb08dd0 100644 --- a/mesa/experimental/cell_space/cell_agent.py +++ b/mesa/spaces/cell_agent.py @@ -7,7 +7,7 @@ from mesa import Agent, Model if TYPE_CHECKING: - from mesa.experimental.cell_space.cell import Cell + from mesa.spaces.cell import Cell class CellAgent(Agent): diff --git a/mesa/experimental/cell_space/cell_collection.py b/mesa/spaces/cell_collection.py similarity index 95% rename from mesa/experimental/cell_space/cell_collection.py rename to mesa/spaces/cell_collection.py index 14832d511be..798d41eee59 100644 --- a/mesa/experimental/cell_space/cell_collection.py +++ b/mesa/spaces/cell_collection.py @@ -9,8 +9,8 @@ from typing import TYPE_CHECKING, Generic, TypeVar if TYPE_CHECKING: - from mesa.experimental.cell_space.cell import Cell - from mesa.experimental.cell_space.cell_agent import CellAgent + from mesa.spaces.cell import Cell + from mesa.spaces.cell_agent import CellAgent T = TypeVar("T", bound="Cell") diff --git a/mesa/experimental/cell_space/discrete_space.py b/mesa/spaces/discrete_space.py similarity index 94% rename from mesa/experimental/cell_space/discrete_space.py rename to mesa/spaces/discrete_space.py index f9a35de5160..09bb0c9281a 100644 --- a/mesa/experimental/cell_space/discrete_space.py +++ b/mesa/spaces/discrete_space.py @@ -6,8 +6,8 @@ from random import Random from typing import Generic, TypeVar -from mesa.experimental.cell_space.cell import Cell -from mesa.experimental.cell_space.cell_collection import CellCollection +from mesa.spaces.cell import Cell +from mesa.spaces.cell_collection import CellCollection T = TypeVar("T", bound=Cell) diff --git a/mesa/experimental/cell_space/grid.py b/mesa/spaces/grid.py similarity index 99% rename from mesa/experimental/cell_space/grid.py rename to mesa/spaces/grid.py index ae33fbe49f6..05c57991538 100644 --- a/mesa/experimental/cell_space/grid.py +++ b/mesa/spaces/grid.py @@ -7,7 +7,7 @@ from random import Random from typing import Generic, TypeVar -from mesa.experimental.cell_space import Cell, DiscreteSpace +from mesa.spaces import Cell, DiscreteSpace T = TypeVar("T", bound=Cell) diff --git a/mesa/experimental/cell_space/network.py b/mesa/spaces/network.py similarity index 90% rename from mesa/experimental/cell_space/network.py rename to mesa/spaces/network.py index 3920511c22e..dae3ddffdf6 100644 --- a/mesa/experimental/cell_space/network.py +++ b/mesa/spaces/network.py @@ -3,8 +3,8 @@ from random import Random from typing import Any -from mesa.experimental.cell_space.cell import Cell -from mesa.experimental.cell_space.discrete_space import DiscreteSpace +from mesa.spaces.cell import Cell +from mesa.spaces.discrete_space import DiscreteSpace class Network(DiscreteSpace): diff --git a/mesa/experimental/cell_space/voronoi.py b/mesa/spaces/voronoi.py similarity index 98% rename from mesa/experimental/cell_space/voronoi.py rename to mesa/spaces/voronoi.py index 0d712f3ea16..d77a40045c9 100644 --- a/mesa/experimental/cell_space/voronoi.py +++ b/mesa/spaces/voronoi.py @@ -6,8 +6,8 @@ import numpy as np -from mesa.experimental.cell_space.cell import Cell -from mesa.experimental.cell_space.discrete_space import DiscreteSpace +from mesa.spaces.cell import Cell +from mesa.spaces.discrete_space import DiscreteSpace class Delaunay: diff --git a/mesa/visualization/components/matplotlib.py b/mesa/visualization/components/matplotlib.py index 6061356af7b..9113f44320c 100644 --- a/mesa/visualization/components/matplotlib.py +++ b/mesa/visualization/components/matplotlib.py @@ -8,7 +8,7 @@ from matplotlib.ticker import MaxNLocator import mesa -from mesa.experimental.cell_space import VoronoiGrid +from mesa.spaces import VoronoiGrid from mesa.visualization.utils import update_counter diff --git a/tests/test_cell_space.py b/tests/test_cell_space.py index 6d88a90baf1..6cc5a030f41 100644 --- a/tests/test_cell_space.py +++ b/tests/test_cell_space.py @@ -5,7 +5,7 @@ import pytest from mesa import Model -from mesa.experimental.cell_space import ( +from mesa.spaces import ( Cell, CellAgent, CellCollection, From 06b099860fe161fbe841941ac5d4c4b207c989d8 Mon Sep 17 00:00:00 2001 From: Jan Kwakkel Date: Mon, 9 Sep 2024 08:49:19 +0200 Subject: [PATCH 05/12] move boltzman benchmark wealth model to new spaces --- .../BoltzmannWealth/boltzmann_wealth.py | 36 ++++++++----------- mesa/spaces/cell_agent.py | 5 ++- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/benchmarks/BoltzmannWealth/boltzmann_wealth.py b/benchmarks/BoltzmannWealth/boltzmann_wealth.py index 041445f1b8f..90cb5ef1fb0 100644 --- a/benchmarks/BoltzmannWealth/boltzmann_wealth.py +++ b/benchmarks/BoltzmannWealth/boltzmann_wealth.py @@ -4,7 +4,7 @@ """ import mesa - +import mesa.spaces as spaces def compute_gini(model): """Calculate gini for wealth in model. @@ -42,18 +42,18 @@ def __init__(self, seed=None, n=100, width=10, height=10): """ super().__init__(seed) self.num_agents = n - self.grid = mesa.space.MultiGrid(width, height, True) + self.grid = spaces.OrthogonalMooreGrid((width, height)) self.schedule = mesa.time.RandomActivation(self) self.datacollector = mesa.DataCollector( model_reporters={"Gini": compute_gini}, agent_reporters={"Wealth": "wealth"} ) # Create agents for _ in range(self.num_agents): - a = MoneyAgent(self) + agent = MoneyAgent(self) # Add the agent to a random grid cell - x = self.random.randrange(self.grid.width) - y = self.random.randrange(self.grid.height) - self.grid.place_agent(a, (x, y)) + x = self.random.randrange(width) + y = self.random.randrange(height) + agent.move_to(self.grid[(x, y)]) self.running = True self.datacollector.collect(self) @@ -75,7 +75,7 @@ def run_model(self, n): self.step() -class MoneyAgent(mesa.Agent): +class MoneyAgent(mesa.spaces.CellAgent): """An agent with fixed initial wealth.""" def __init__(self, model): @@ -87,20 +87,8 @@ def __init__(self, model): super().__init__(model) self.wealth = 1 - def move(self): - """Move the agent to a random neighboring cell.""" - possible_steps = self.model.grid.get_neighborhood( - self.pos, moore=True, include_center=False - ) - new_position = self.random.choice(possible_steps) - self.model.grid.move_agent(self, new_position) - def give_money(self): - """Give money to a random cell mate.""" - cellmates = self.model.grid.get_cell_list_contents([self.pos]) - cellmates.pop( - cellmates.index(self) - ) # Ensure agent is not giving money to itself + cellmates = [agent for agent in self.cell.agents if not agent is self] if len(cellmates) > 0: other = self.random.choice(cellmates) other.wealth += 1 @@ -108,6 +96,12 @@ def give_money(self): def step(self): """Run the agent for 1 step.""" - self.move() + self.move_to(self.cell.neighborhood().select_random_cell()) if self.wealth > 0: self.give_money() + + +if __name__ == '__main__': + model = BoltzmannWealth() + for _ in range(10): + model.step() \ No newline at end of file diff --git a/mesa/spaces/cell_agent.py b/mesa/spaces/cell_agent.py index 3b81fb08dd0..1e6c5612f7c 100644 --- a/mesa/spaces/cell_agent.py +++ b/mesa/spaces/cell_agent.py @@ -37,6 +37,9 @@ def move_to(self, cell) -> None: """ if self.cell is not None: - self.cell.remove_agent(self) + try: + self.cell.remove_agent(self) + except ValueError: + raise ValueError("Cannot remove agent from cell") self.cell = cell cell.add_agent(self) From 6e536121116d14a89d82c8440d31950d57736421 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 06:54:25 +0000 Subject: [PATCH 06/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- benchmarks/BoltzmannWealth/boltzmann_wealth.py | 7 ++++--- mesa/__init__.py | 1 + mesa/experimental/components/matplotlib.py | 2 -- mesa/spaces/__init__.py | 9 +++++++-- mesa/spaces/cell.py | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/benchmarks/BoltzmannWealth/boltzmann_wealth.py b/benchmarks/BoltzmannWealth/boltzmann_wealth.py index 90cb5ef1fb0..4d8eee90ff5 100644 --- a/benchmarks/BoltzmannWealth/boltzmann_wealth.py +++ b/benchmarks/BoltzmannWealth/boltzmann_wealth.py @@ -6,6 +6,7 @@ import mesa import mesa.spaces as spaces + def compute_gini(model): """Calculate gini for wealth in model. @@ -88,7 +89,7 @@ def __init__(self, model): self.wealth = 1 def give_money(self): - cellmates = [agent for agent in self.cell.agents if not agent is self] + cellmates = [agent for agent in self.cell.agents if agent is not self] if len(cellmates) > 0: other = self.random.choice(cellmates) other.wealth += 1 @@ -101,7 +102,7 @@ def step(self): self.give_money() -if __name__ == '__main__': +if __name__ == "__main__": model = BoltzmannWealth() for _ in range(10): - model.step() \ No newline at end of file + model.step() diff --git a/mesa/__init__.py b/mesa/__init__.py index 86b49d272b1..81eda89ee9f 100644 --- a/mesa/__init__.py +++ b/mesa/__init__.py @@ -6,6 +6,7 @@ import datetime import mesa.space as old_space + # import mesa.spaces as spaces import mesa.time as time from mesa.agent import Agent diff --git a/mesa/experimental/components/matplotlib.py b/mesa/experimental/components/matplotlib.py index 2ef52ea6e80..a4656cf11e7 100644 --- a/mesa/experimental/components/matplotlib.py +++ b/mesa/experimental/components/matplotlib.py @@ -10,7 +10,6 @@ import mesa - @solara.component def SpaceMatplotlib(model, agent_portrayal, dependencies: list[any] | None = None): """A component for rendering a space using Matplotlib. @@ -164,7 +163,6 @@ def portray(space): def _draw_voronoi(space, space_ax, agent_portrayal): - from mesa.spaces.voronoi import VoronoiGrid def portray(g): x = [] y = [] diff --git a/mesa/spaces/__init__.py b/mesa/spaces/__init__.py index 93c907e01bd..44ae0a5b6e7 100644 --- a/mesa/spaces/__init__.py +++ b/mesa/spaces/__init__.py @@ -1,9 +1,14 @@ -from mesa.spaces.network import Network from mesa.spaces.cell import Cell from mesa.spaces.cell_agent import CellAgent from mesa.spaces.cell_collection import CellCollection from mesa.spaces.discrete_space import DiscreteSpace -from mesa.spaces.grid import Grid, HexGrid, OrthogonalMooreGrid, OrthogonalVonNeumannGrid +from mesa.spaces.grid import ( + Grid, + HexGrid, + OrthogonalMooreGrid, + OrthogonalVonNeumannGrid, +) +from mesa.spaces.network import Network from mesa.spaces.voronoi import VoronoiGrid __all__ = [ diff --git a/mesa/spaces/cell.py b/mesa/spaces/cell.py index c68e1316445..2abb4e14ac1 100644 --- a/mesa/spaces/cell.py +++ b/mesa/spaces/cell.py @@ -123,7 +123,7 @@ def __repr__(self): # noqa # FIXME: Revisit caching strategy on methods @cache # noqa: B019 - def neighborhood(self, radius=1, include_center=False): + def neighborhood(self, radius=1, include_center=False): -> CellCollection: """Returns a list of all neighboring cells.""" return CellCollection( self._neighborhood(radius=radius, include_center=include_center), From 81f777984115b79005108099e02ccf85aaf29540 Mon Sep 17 00:00:00 2001 From: Jan Kwakkel Date: Mon, 9 Sep 2024 08:58:56 +0200 Subject: [PATCH 07/12] Update test_solara_viz.py --- tests/test_solara_viz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_solara_viz.py b/tests/test_solara_viz.py index 798777bb5eb..9647c770bee 100644 --- a/tests/test_solara_viz.py +++ b/tests/test_solara_viz.py @@ -116,7 +116,7 @@ def test_call_space_drawer(mocker): # noqa: D103 # check voronoi space drawer voronoi_model = mesa.Model() - voronoi_model.grid = mesa.experimental.cell_space.VoronoiGrid( + voronoi_model.grid = mesa.spaces.VoronoiGrid( centroids_coordinates=[(0, 1), (0, 0), (1, 0)], ) solara.render( From 72d32f472d47ab7572805925e459670b885870b7 Mon Sep 17 00:00:00 2001 From: Jan Kwakkel Date: Mon, 9 Sep 2024 09:00:22 +0200 Subject: [PATCH 08/12] fix benchmarks --- benchmarks/Schelling/schelling.py | 2 +- benchmarks/WolfSheep/wolf_sheep.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmarks/Schelling/schelling.py b/benchmarks/Schelling/schelling.py index 47bf521e057..669c1477dd0 100644 --- a/benchmarks/Schelling/schelling.py +++ b/benchmarks/Schelling/schelling.py @@ -1,7 +1,7 @@ """Schelling separation for performance benchmarking.""" from mesa import Model -from mesa.experimental.cell_space import CellAgent, OrthogonalMooreGrid +from mesa.spaces import CellAgent, OrthogonalMooreGrid from mesa.time import RandomActivation diff --git a/benchmarks/WolfSheep/wolf_sheep.py b/benchmarks/WolfSheep/wolf_sheep.py index 0999fc77842..14863e0db30 100644 --- a/benchmarks/WolfSheep/wolf_sheep.py +++ b/benchmarks/WolfSheep/wolf_sheep.py @@ -10,7 +10,7 @@ import math from mesa import Model -from mesa.experimental.cell_space import CellAgent, OrthogonalVonNeumannGrid +from mesa.spaces import CellAgent, OrthogonalVonNeumannGrid from mesa.experimental.devs import ABMSimulator From 80a56cc133e1e1f1f8b144b297e5c3caf3e9b747 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 07:00:30 +0000 Subject: [PATCH 09/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- benchmarks/WolfSheep/wolf_sheep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/WolfSheep/wolf_sheep.py b/benchmarks/WolfSheep/wolf_sheep.py index 14863e0db30..4a31e2f00ef 100644 --- a/benchmarks/WolfSheep/wolf_sheep.py +++ b/benchmarks/WolfSheep/wolf_sheep.py @@ -10,8 +10,8 @@ import math from mesa import Model -from mesa.spaces import CellAgent, OrthogonalVonNeumannGrid from mesa.experimental.devs import ABMSimulator +from mesa.spaces import CellAgent, OrthogonalVonNeumannGrid class Animal(CellAgent): From 6697e778d0207f617db1fb9183bcaff6740488db Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 18 Sep 2024 11:23:24 +0000 Subject: [PATCH 10/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mesa/experimental/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mesa/experimental/__init__.py b/mesa/experimental/__init__.py index 90fcdcfe2da..351500b16a6 100644 --- a/mesa/experimental/__init__.py +++ b/mesa/experimental/__init__.py @@ -1,4 +1,5 @@ """Experimental init.""" + from .solara_viz import JupyterViz, Slider, SolaraViz, make_text __all__ = ["JupyterViz", "SolaraViz", "make_text", "Slider"] From 259900e4a153090ef86ac69367a18674736cba31 Mon Sep 17 00:00:00 2001 From: Jan Kwakkel Date: Thu, 19 Sep 2024 16:24:26 +0200 Subject: [PATCH 11/12] Update cell.py --- mesa/spaces/cell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesa/spaces/cell.py b/mesa/spaces/cell.py index 2abb4e14ac1..333ef914f36 100644 --- a/mesa/spaces/cell.py +++ b/mesa/spaces/cell.py @@ -123,7 +123,7 @@ def __repr__(self): # noqa # FIXME: Revisit caching strategy on methods @cache # noqa: B019 - def neighborhood(self, radius=1, include_center=False): -> CellCollection: + def neighborhood(self, radius=1, include_center=False) -> CellCollection: """Returns a list of all neighboring cells.""" return CellCollection( self._neighborhood(radius=radius, include_center=include_center), From 2650ad73a090cc83d9ef914ff768a7d14233976b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 07:13:28 +0000 Subject: [PATCH 12/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- benchmarks/Schelling/schelling.py | 1 - mesa/spaces/discrete_space.py | 2 +- mesa/visualization/components/matplotlib.py | 2 +- tests/test_cell_space.py | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/benchmarks/Schelling/schelling.py b/benchmarks/Schelling/schelling.py index d0b09caa50b..4378bc061ba 100644 --- a/benchmarks/Schelling/schelling.py +++ b/benchmarks/Schelling/schelling.py @@ -4,7 +4,6 @@ from mesa import Model from mesa.spaces import CellAgent, OrthogonalMooreGrid -from mesa.time import RandomActivation class SchellingAgent(CellAgent): diff --git a/mesa/spaces/discrete_space.py b/mesa/spaces/discrete_space.py index 5262d24ccbb..07aabf701d5 100644 --- a/mesa/spaces/discrete_space.py +++ b/mesa/spaces/discrete_space.py @@ -7,9 +7,9 @@ from random import Random from typing import Any, Generic, TypeVar +from mesa.space import PropertyLayer from mesa.spaces.cell import Cell from mesa.spaces.cell_collection import CellCollection -from mesa.space import PropertyLayer T = TypeVar("T", bound=Cell) diff --git a/mesa/visualization/components/matplotlib.py b/mesa/visualization/components/matplotlib.py index 898d2900830..fd5f0e24761 100644 --- a/mesa/visualization/components/matplotlib.py +++ b/mesa/visualization/components/matplotlib.py @@ -11,8 +11,8 @@ from matplotlib.figure import Figure import mesa -from mesa.spaces import VoronoiGrid from mesa.space import PropertyLayer +from mesa.spaces import VoronoiGrid from mesa.visualization.utils import update_counter diff --git a/tests/test_cell_space.py b/tests/test_cell_space.py index 26af30fa79c..084b1f73386 100644 --- a/tests/test_cell_space.py +++ b/tests/test_cell_space.py @@ -6,6 +6,7 @@ import pytest from mesa import Model +from mesa.space import PropertyLayer from mesa.spaces import ( Cell, CellAgent, @@ -18,7 +19,6 @@ OrthogonalVonNeumannGrid, VoronoiGrid, ) -from mesa.space import PropertyLayer def test_orthogonal_grid_neumann():