From 495e4e248800c069478407084d2f07ff3b55dcbc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 23 Oct 2024 20:16:35 +0000 Subject: [PATCH] advanced examples: ruff format, pre-commit --- mesa/examples/__init__.py | 5 ++-- .../advanced/epstein_civil_violence/app.py | 23 +++++++++-------- .../advanced/epstein_civil_violence/model.py | 7 +++--- mesa/examples/advanced/pd_grid/app.py | 25 +++++-------------- mesa/examples/advanced/pd_grid/model.py | 3 +-- 5 files changed, 25 insertions(+), 38 deletions(-) diff --git a/mesa/examples/__init__.py b/mesa/examples/__init__.py index cfec8b4c9a1..0258243c9c3 100644 --- a/mesa/examples/__init__.py +++ b/mesa/examples/__init__.py @@ -1,12 +1,11 @@ +from mesa.examples.advanced.epstein_civil_violence.model import EpsteinCivilViolence +from mesa.examples.advanced.pd_grid.model import PdGrid from mesa.examples.basic.boid_flockers.model import BoidFlockers from mesa.examples.basic.boltzmann_wealth_model.model import BoltzmannWealthModel from mesa.examples.basic.conways_game_of_life.model import ConwaysGameOfLife from mesa.examples.basic.schelling.model import Schelling from mesa.examples.basic.virus_on_network.model import VirusOnNetwork -from mesa.examples.advanced.epstein_civil_violence.model import EpsteinCivilViolence -from mesa.examples.advanced.pd_grid.model import PdGrid - __all__ = [ "BoidFlockers", "BoltzmannWealthModel", diff --git a/mesa/examples/advanced/epstein_civil_violence/app.py b/mesa/examples/advanced/epstein_civil_violence/app.py index 749bd611f33..870e931c51d 100644 --- a/mesa/examples/advanced/epstein_civil_violence/app.py +++ b/mesa/examples/advanced/epstein_civil_violence/app.py @@ -1,7 +1,11 @@ -from mesa.visualization import SolaraViz, Slider, make_space_matplotlib, make_plot_measure - from mesa.examples.advanced.epstein_civil_violence.agents import Citizen, Cop from mesa.examples.advanced.epstein_civil_violence.model import EpsteinCivilViolence +from mesa.visualization import ( + Slider, + SolaraViz, + make_plot_measure, + make_space_matplotlib, +) COP_COLOR = "#000000" AGENT_QUIET_COLOR = "#648FFF" @@ -16,19 +20,18 @@ def citizen_cop_portrayal(agent): portrayal = { "size": 25, - # "shape": "circle", - "x": agent.cell.coordinate[0], - "y": agent.cell.coordinate[1], - # "filled": True, + "shape": "s", # square marker } if isinstance(agent, Citizen): - color = AGENT_QUIET_COLOR if agent.condition == "Quiescent" else AGENT_REBEL_COLOR + color = ( + AGENT_QUIET_COLOR if agent.condition == "Quiescent" else AGENT_REBEL_COLOR + ) color = JAIL_COLOR if agent.jail_sentence else color shape = JAIL_SHAPE if agent.jail_sentence else "circle" portrayal["color"] = color portrayal["shape"] = shape - if shape == "rect": + if shape == "s": portrayal["w"] = 0.9 portrayal["h"] = 0.9 else: @@ -62,9 +65,7 @@ def citizen_cop_portrayal(agent): page = SolaraViz( epstein_model, - components=[ - space_component, - chart_component], + components=[space_component, chart_component], model_params=model_params, name="Epstein Civil Violence", ) diff --git a/mesa/examples/advanced/epstein_civil_violence/model.py b/mesa/examples/advanced/epstein_civil_violence/model.py index 239681c5335..3d3708e1241 100644 --- a/mesa/examples/advanced/epstein_civil_violence/model.py +++ b/mesa/examples/advanced/epstein_civil_violence/model.py @@ -1,5 +1,4 @@ import mesa - from mesa.examples.advanced.epstein_civil_violence.agents import Citizen, Cop @@ -43,7 +42,7 @@ def __init__( arrest_prob_constant=2.3, movement=True, max_iters=1000, - seed=None + seed=None, ): super().__init__(seed=seed) self.width = width @@ -60,7 +59,9 @@ def __init__( self.max_iters = max_iters self.iteration = 0 - self.grid = mesa.experimental.cell_space.OrthogonalMooreGrid((width, height), capacity=1, torus=True, random=self.random) + self.grid = mesa.experimental.cell_space.OrthogonalMooreGrid( + (width, height), capacity=1, torus=True, random=self.random + ) model_reporters = { "Quiescent": lambda m: self.count_type_citizens(m, "Quiescent"), diff --git a/mesa/examples/advanced/pd_grid/app.py b/mesa/examples/advanced/pd_grid/app.py index 2364cee422d..4f97f9ff491 100644 --- a/mesa/examples/advanced/pd_grid/app.py +++ b/mesa/examples/advanced/pd_grid/app.py @@ -2,10 +2,9 @@ Solara-based visualization for the Spatial Prisoner's Dilemma Model. """ -import solara -from mesa.visualization import SolaraViz, make_space_matplotlib, make_plot_measure -from mesa.visualization.UserParam import Slider from mesa.examples.advanced.pd_grid.model import PdGrid +from mesa.visualization import SolaraViz, make_plot_measure, make_space_matplotlib +from mesa.visualization.UserParam import Slider def pd_agent_portrayal(agent): @@ -21,26 +20,14 @@ def pd_agent_portrayal(agent): # Model parameters model_params = { - "width": Slider( - "Grid Width", - value=50, - min=10, - max=100, - step=1 - ), - "height": Slider( - "Grid Height", - value=50, - min=10, - max=100, - step=1 - ), + "width": Slider("Grid Width", value=50, min=10, max=100, step=1), + "height": Slider("Grid Height", value=50, min=10, max=100, step=1), "activation_order": { "type": "Select", "value": "Random", "values": PdGrid.activation_regimes, - "label": "Activation Regime" - } + "label": "Activation Regime", + }, } diff --git a/mesa/examples/advanced/pd_grid/model.py b/mesa/examples/advanced/pd_grid/model.py index 78de0b5244a..35327a41ec5 100644 --- a/mesa/examples/advanced/pd_grid/model.py +++ b/mesa/examples/advanced/pd_grid/model.py @@ -1,7 +1,6 @@ import mesa -from mesa.experimental.cell_space import OrthogonalMooreGrid - from mesa.examples.advanced.pd_grid.agents import PDAgent +from mesa.experimental.cell_space import OrthogonalMooreGrid class PdGrid(mesa.Model):