diff --git a/examples/bank_reserves/requirements.txt b/examples/bank_reserves/requirements.txt index 198a1ab7..d398c6ed 100644 --- a/examples/bank_reserves/requirements.txt +++ b/examples/bank_reserves/requirements.txt @@ -1,4 +1,4 @@ itertools -mesa~=1.1 +mesa~=2.0 numpy pandas diff --git a/examples/boid_flockers/requirements.txt b/examples/boid_flockers/requirements.txt index 19b805ac..da2b9972 100644 --- a/examples/boid_flockers/requirements.txt +++ b/examples/boid_flockers/requirements.txt @@ -1,3 +1,3 @@ jupyter matplotlib -mesa~=1.1 +mesa~=2.0 diff --git a/examples/boltzmann_wealth_model/app.py b/examples/boltzmann_wealth_model/app.py index f2dd6da9..c4c92ea8 100644 --- a/examples/boltzmann_wealth_model/app.py +++ b/examples/boltzmann_wealth_model/app.py @@ -68,7 +68,7 @@ my_bar.progress((i / num_ticks), text="Simulation progress") placeholder.text("Step = %d" % i) for cell in model.grid.coord_iter(): - cell_content, x, y = cell + cell_content, (x, y) = cell agent_count = len(cell_content) selected_row = df_grid[(df_grid["x"] == x) & (df_grid["y"] == y)] df_grid.loc[ diff --git a/examples/boltzmann_wealth_model/requirements.txt b/examples/boltzmann_wealth_model/requirements.txt index 63b0d24e..25d263f4 100644 --- a/examples/boltzmann_wealth_model/requirements.txt +++ b/examples/boltzmann_wealth_model/requirements.txt @@ -1 +1 @@ -mesa~=1.1 +mesa~=2.0 diff --git a/examples/boltzmann_wealth_model_experimental/requirements.txt b/examples/boltzmann_wealth_model_experimental/requirements.txt index fd610831..479011dd 100644 --- a/examples/boltzmann_wealth_model_experimental/requirements.txt +++ b/examples/boltzmann_wealth_model_experimental/requirements.txt @@ -1,2 +1,3 @@ -mesa~=1.1 --e git+https://github.com/projectmesa/mesa-examples +mesa~=2.0 +solara +git+https://github.com/projectmesa/mesa-examples \ No newline at end of file diff --git a/examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/model.py b/examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/model.py index d13f70f6..42d58bd8 100644 --- a/examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/model.py +++ b/examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/model.py @@ -56,7 +56,7 @@ def __init__(self, unique_id, model): def move(self): possible_steps = [ node - for node in self.model.grid.get_neighbors(self.pos, include_center=False) + for node in self.model.grid.get_neighborhood(self.pos, include_center=False) if self.model.grid.is_cell_empty(node) ] if len(possible_steps) > 0: @@ -64,8 +64,7 @@ def move(self): self.model.grid.move_agent(self, new_position) def give_money(self): - neighbors_nodes = self.model.grid.get_neighbors(self.pos, include_center=False) - neighbors = self.model.grid.get_cell_list_contents(neighbors_nodes) + neighbors = self.model.grid.get_neighbors(self.pos, include_center=False) if len(neighbors) > 0: other = self.random.choice(neighbors) other.wealth += 1 diff --git a/examples/boltzmann_wealth_model_network/requirements.txt b/examples/boltzmann_wealth_model_network/requirements.txt index 1af7d8a1..e9403e6c 100644 --- a/examples/boltzmann_wealth_model_network/requirements.txt +++ b/examples/boltzmann_wealth_model_network/requirements.txt @@ -1,5 +1,5 @@ jupyter matplotlib -mesa~=1.1 +mesa~=2.0 numpy networkx diff --git a/examples/caching_and_replay/model.py b/examples/caching_and_replay/model.py index 47fa9891..95c26b6a 100644 --- a/examples/caching_and_replay/model.py +++ b/examples/caching_and_replay/model.py @@ -63,8 +63,7 @@ def __init__(self, width=20, height=20, density=0.8, minority_pc=0.2, homophily= # the coordinates of a cell as well as # its contents. (coord_iter) for cell in self.grid.coord_iter(): - x = cell[1] - y = cell[2] + x, y = cell[1] if self.random.random() < self.density: agent_type = 1 if self.random.random() < self.minority_pc else 0 diff --git a/examples/charts/requirements.txt b/examples/charts/requirements.txt index 198a1ab7..d398c6ed 100644 --- a/examples/charts/requirements.txt +++ b/examples/charts/requirements.txt @@ -1,4 +1,4 @@ itertools -mesa~=1.1 +mesa~=2.0 numpy pandas diff --git a/examples/color_patches/color_patches/model.py b/examples/color_patches/color_patches/model.py index a6619dab..973b91ad 100644 --- a/examples/color_patches/color_patches/model.py +++ b/examples/color_patches/color_patches/model.py @@ -80,7 +80,7 @@ def __init__(self, width=20, height=20): # -->but only col & row # for (contents, col, row) in self._grid.coord_iter(): # replaced content with _ to appease linter - for _, row, col in self._grid.coord_iter(): + for _, (row, col) in self._grid.coord_iter(): cell = ColorCell( (row, col), self, ColorCell.OPINIONS[self.random.randrange(0, 16)] ) diff --git a/examples/conways_game_of_life/app.py b/examples/conways_game_of_life/app.py index 0977b6f3..884ec523 100644 --- a/examples/conways_game_of_life/app.py +++ b/examples/conways_game_of_life/app.py @@ -49,7 +49,7 @@ model.step() my_bar.progress((i / num_ticks), text="Simulation progress") placeholder.text("Step = %d" % i) - for contents, x, y in model.grid.coord_iter(): + for contents, (x, y) in model.grid.coord_iter(): # print('x:',x,'y:',y, 'state:',contents) selected_row = df_grid[(df_grid["x"] == x) & (df_grid["y"] == y)] df_grid.loc[ diff --git a/examples/conways_game_of_life/conways_game_of_life/model.py b/examples/conways_game_of_life/conways_game_of_life/model.py index 581541c1..bf2204e0 100644 --- a/examples/conways_game_of_life/conways_game_of_life/model.py +++ b/examples/conways_game_of_life/conways_game_of_life/model.py @@ -27,7 +27,7 @@ def __init__(self, width=50, height=50): # Place a cell at each location, with some initialized to # ALIVE and some to DEAD. - for contents, x, y in self.grid.coord_iter(): + for contents, (x, y) in self.grid.coord_iter(): cell = Cell((x, y), self) if self.random.random() < 0.1: cell.state = cell.ALIVE diff --git a/examples/epstein_civil_violence/epstein_civil_violence/model.py b/examples/epstein_civil_violence/epstein_civil_violence/model.py index 1c7e45f4..f660ecfa 100644 --- a/examples/epstein_civil_violence/epstein_civil_violence/model.py +++ b/examples/epstein_civil_violence/epstein_civil_violence/model.py @@ -81,7 +81,7 @@ def __init__( unique_id = 0 if self.cop_density + self.citizen_density > 1: raise ValueError("Cop density + citizen density must be less than 1") - for contents, x, y in self.grid.coord_iter(): + for contents, (x, y) in self.grid.coord_iter(): if self.random.random() < self.cop_density: cop = Cop(unique_id, self, (x, y), vision=self.cop_vision) unique_id += 1 diff --git a/examples/forest_fire/forest_fire/model.py b/examples/forest_fire/forest_fire/model.py index 7f3a2f48..3d5f448a 100644 --- a/examples/forest_fire/forest_fire/model.py +++ b/examples/forest_fire/forest_fire/model.py @@ -29,7 +29,7 @@ def __init__(self, width=100, height=100, density=0.65): ) # Place a tree in each cell with Prob = density - for contents, x, y in self.grid.coord_iter(): + for contents, (x, y) in self.grid.coord_iter(): if self.random.random() < density: # Create a tree new_tree = TreeCell((x, y), self) diff --git a/examples/hex_snowflake/hex_snowflake/model.py b/examples/hex_snowflake/hex_snowflake/model.py index 28abab00..b064d767 100644 --- a/examples/hex_snowflake/hex_snowflake/model.py +++ b/examples/hex_snowflake/hex_snowflake/model.py @@ -25,9 +25,9 @@ def __init__(self, width=50, height=50): self.grid = mesa.space.HexGrid(width, height, torus=True) # Place a dead cell at each location. - for contents, x, y in self.grid.coord_iter(): - cell = Cell((x, y), self) - self.grid.place_agent(cell, (x, y)) + for contents, pos in self.grid.coord_iter(): + cell = Cell(pos, self) + self.grid.place_agent(cell, pos) self.schedule.add(cell) # activate the center(ish) cell. diff --git a/examples/hex_snowflake/requirements.txt b/examples/hex_snowflake/requirements.txt index 0d2d0bc6..ecd07eaf 100644 --- a/examples/hex_snowflake/requirements.txt +++ b/examples/hex_snowflake/requirements.txt @@ -1 +1 @@ -mesa~=1.1 \ No newline at end of file +mesa~=2.0 \ No newline at end of file diff --git a/examples/pd_grid/analysis.ipynb b/examples/pd_grid/analysis.ipynb index 53a63345..7f848318 100644 --- a/examples/pd_grid/analysis.ipynb +++ b/examples/pd_grid/analysis.ipynb @@ -68,7 +68,7 @@ " if not ax:\n", " fig, ax = plt.subplots(figsize=(6, 6))\n", " grid = np.zeros((model.grid.width, model.grid.height))\n", - " for agent, x, y in model.grid.coord_iter():\n", + " for agent, (x, y) in model.grid.coord_iter():\n", " if agent.move == \"D\":\n", " grid[y][x] = 1\n", " else:\n", diff --git a/examples/pd_grid/requirements.txt b/examples/pd_grid/requirements.txt index 19b805ac..da2b9972 100644 --- a/examples/pd_grid/requirements.txt +++ b/examples/pd_grid/requirements.txt @@ -1,3 +1,3 @@ jupyter matplotlib -mesa~=1.1 +mesa~=2.0 diff --git a/examples/schelling/model.py b/examples/schelling/model.py index ccc5699e..c7fe766a 100644 --- a/examples/schelling/model.py +++ b/examples/schelling/model.py @@ -61,8 +61,7 @@ def __init__(self, width=20, height=20, density=0.8, minority_pc=0.2, homophily= # the coordinates of a cell as well as # its contents. (coord_iter) for cell in self.grid.coord_iter(): - x = cell[1] - y = cell[2] + x, y = cell[1] if self.random.random() < self.density: agent_type = 1 if self.random.random() < self.minority_pc else 0 diff --git a/examples/schelling/requirements.txt b/examples/schelling/requirements.txt index 19b805ac..da2b9972 100644 --- a/examples/schelling/requirements.txt +++ b/examples/schelling/requirements.txt @@ -1,3 +1,3 @@ jupyter matplotlib -mesa~=1.1 +mesa~=2.0 diff --git a/examples/schelling_experimental/model.py b/examples/schelling_experimental/model.py index ccc5699e..c7fe766a 100644 --- a/examples/schelling_experimental/model.py +++ b/examples/schelling_experimental/model.py @@ -61,8 +61,7 @@ def __init__(self, width=20, height=20, density=0.8, minority_pc=0.2, homophily= # the coordinates of a cell as well as # its contents. (coord_iter) for cell in self.grid.coord_iter(): - x = cell[1] - y = cell[2] + x, y = cell[1] if self.random.random() < self.density: agent_type = 1 if self.random.random() < self.minority_pc else 0 diff --git a/examples/schelling_experimental/requirements.txt b/examples/schelling_experimental/requirements.txt index 287c86ff..02cb0c47 100644 --- a/examples/schelling_experimental/requirements.txt +++ b/examples/schelling_experimental/requirements.txt @@ -1,4 +1,5 @@ jupyter matplotlib -mesa~=1.1 --e git+https://github.com/projectmesa/mesa-examples +mesa~=2.0 +solara +git+https://github.com/projectmesa/mesa-examples \ No newline at end of file diff --git a/examples/shape_example/requirements.txt b/examples/shape_example/requirements.txt index 63b0d24e..25d263f4 100644 --- a/examples/shape_example/requirements.txt +++ b/examples/shape_example/requirements.txt @@ -1 +1 @@ -mesa~=1.1 +mesa~=2.0 diff --git a/examples/sugarscape_cg/requirements.txt b/examples/sugarscape_cg/requirements.txt index d1f92023..9531680f 100644 --- a/examples/sugarscape_cg/requirements.txt +++ b/examples/sugarscape_cg/requirements.txt @@ -1,2 +1,2 @@ jupyter -mesa~=1.1 +mesa~=2.0 diff --git a/examples/sugarscape_cg/sugarscape_cg/model.py b/examples/sugarscape_cg/sugarscape_cg/model.py index 61c6fc1a..ab1e6dfa 100644 --- a/examples/sugarscape_cg/sugarscape_cg/model.py +++ b/examples/sugarscape_cg/sugarscape_cg/model.py @@ -45,7 +45,7 @@ def __init__(self, width=50, height=50, initial_population=100): sugar_distribution = np.genfromtxt("sugarscape_cg/sugar-map.txt") agent_id = 0 - for _, x, y in self.grid.coord_iter(): + for _, (x, y) in self.grid.coord_iter(): max_sugar = sugar_distribution[x, y] sugar = Sugar(agent_id, (x, y), self, max_sugar) agent_id += 1 diff --git a/examples/sugarscape_g1mt/app.py b/examples/sugarscape_g1mt/app.py index 1866db22..ed54be19 100644 --- a/examples/sugarscape_g1mt/app.py +++ b/examples/sugarscape_g1mt/app.py @@ -15,8 +15,7 @@ def portray(g): "trader": {"x": [], "y": [], "c": "tab:red", "marker": "o", "s": 10}, } - # TODO update to Mesa 2.0 API - for content, i, j in g.coord_iter(): + for content, (i, j) in g.coord_iter(): for agent in content: if isinstance(agent, Trader): layers["trader"]["x"].append(i) diff --git a/examples/sugarscape_g1mt/sugarscape_g1mt/model.py b/examples/sugarscape_g1mt/sugarscape_g1mt/model.py index a7ed5200..83eaaafa 100644 --- a/examples/sugarscape_g1mt/sugarscape_g1mt/model.py +++ b/examples/sugarscape_g1mt/sugarscape_g1mt/model.py @@ -89,7 +89,7 @@ def __init__( spice_distribution = np.flip(sugar_distribution, 1) agent_id = 0 - for _, x, y in self.grid.coord_iter(): + for _, (x, y) in self.grid.coord_iter(): max_sugar = sugar_distribution[x, y] if max_sugar > 0: sugar = Sugar(agent_id, self, (x, y), max_sugar) diff --git a/examples/virus_on_network/requirements.txt b/examples/virus_on_network/requirements.txt index 9d01589a..03e3c237 100644 --- a/examples/virus_on_network/requirements.txt +++ b/examples/virus_on_network/requirements.txt @@ -1,2 +1,2 @@ networkx>=2.0 -mesa~=1.1 \ No newline at end of file +mesa~=2.0 \ No newline at end of file diff --git a/examples/virus_on_network/virus_on_network/model.py b/examples/virus_on_network/virus_on_network/model.py index 6f952490..961c56bc 100644 --- a/examples/virus_on_network/virus_on_network/model.py +++ b/examples/virus_on_network/virus_on_network/model.py @@ -123,7 +123,9 @@ def __init__( self.gain_resistance_chance = gain_resistance_chance def try_to_infect_neighbors(self): - neighbors_nodes = self.model.grid.get_neighbors(self.pos, include_center=False) + neighbors_nodes = self.model.grid.get_neighborhood( + self.pos, include_center=False + ) susceptible_neighbors = [ agent for agent in self.model.grid.get_cell_list_contents(neighbors_nodes) diff --git a/examples/wolf_sheep/requirements.txt b/examples/wolf_sheep/requirements.txt index 63b0d24e..25d263f4 100644 --- a/examples/wolf_sheep/requirements.txt +++ b/examples/wolf_sheep/requirements.txt @@ -1 +1 @@ -mesa~=1.1 +mesa~=2.0 diff --git a/examples/wolf_sheep/wolf_sheep/model.py b/examples/wolf_sheep/wolf_sheep/model.py index ac44beff..2626f958 100644 --- a/examples/wolf_sheep/wolf_sheep/model.py +++ b/examples/wolf_sheep/wolf_sheep/model.py @@ -113,7 +113,7 @@ def __init__( # Create grass patches if self.grass: - for agent, x, y in self.grid.coord_iter(): + for agent, (x, y) in self.grid.coord_iter(): fully_grown = self.random.choice([True, False]) if fully_grown: