From fe37aa3032dd7a93b7e43f88feebe2dde936a9d8 Mon Sep 17 00:00:00 2001 From: Vanya Kapoor Date: Sat, 21 Mar 2026 19:16:19 +0530 Subject: [PATCH 1/2] fix: add missing app.py entrypoints for el_farol, shape_example, caching_and_replay --- examples/caching_and_replay/app.py | 67 +++++++++++++++++++++ examples/el_farol/el_farol/app.py | 55 +++++++++++++++++ examples/el_farol/el_farol/model.py | 2 +- examples/shape_example/shape_example/app.py | 50 +++++++++++++++ 4 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 examples/caching_and_replay/app.py create mode 100644 examples/el_farol/el_farol/app.py create mode 100644 examples/shape_example/shape_example/app.py diff --git a/examples/caching_and_replay/app.py b/examples/caching_and_replay/app.py new file mode 100644 index 000000000..f7e054d60 --- /dev/null +++ b/examples/caching_and_replay/app.py @@ -0,0 +1,67 @@ +""" +Solara visualisation for the Schelling Caching and Replay example. + +Run with: + solara run app.py +""" + +import mesa.visualization +from model import Schelling + + +def agent_portrayal(agent): + return { + "color": "#185FA5" if agent.type == 0 else "#D85A30", + "marker": "s", + "size": 25, + } + + +model_params = { + "height": 20, + "width": 20, + "homophily": { + "type": "SliderInt", + "value": 3, + "label": "Homophily", + "min": 0, + "max": 8, + "step": 1, + }, + "density": { + "type": "SliderFloat", + "value": 0.8, + "label": "Density", + "min": 0.1, + "max": 1.0, + "step": 0.1, + }, + "minority_pc": { + "type": "SliderFloat", + "value": 0.3, + "label": "Minority fraction", + "min": 0.0, + "max": 1.0, + "step": 0.05, + }, + "radius": { + "type": "SliderInt", + "value": 1, + "label": "Radius", + "min": 1, + "max": 5, + "step": 1, + }, + "rng": 42, +} + +page = mesa.visualization.SolaraViz( + Schelling, + components=[ + mesa.visualization.make_space_component(agent_portrayal), + mesa.visualization.make_plot_component(["happy"]), + ], + model_params=model_params, + name="Schelling Segregation — with caching and replay", +) +page \ No newline at end of file diff --git a/examples/el_farol/el_farol/app.py b/examples/el_farol/el_farol/app.py new file mode 100644 index 000000000..84d6deeb8 --- /dev/null +++ b/examples/el_farol/el_farol/app.py @@ -0,0 +1,55 @@ +""" +Solara visualisation for the El Farol Bar model. + +Run with: + solara run app.py +""" + +import mesa.visualization +from model import ElFarolBar + + +model_params = { + "num_agents": { + "type": "SliderInt", + "value": 100, + "label": "Number of agents", + "min": 10, + "max": 300, + "step": 10, + }, + "crowd_threshold": { + "type": "SliderInt", + "value": 60, + "label": "Crowd threshold", + "min": 1, + "max": 100, + "step": 1, + }, + "num_strategies": { + "type": "SliderInt", + "value": 10, + "label": "Strategies per agent", + "min": 1, + "max": 20, + "step": 1, + }, + "memory_size": { + "type": "SliderInt", + "value": 10, + "label": "Memory size", + "min": 1, + "max": 20, + "step": 1, + }, +} + +page = mesa.visualization.SolaraViz( + ElFarolBar, + components=[ + mesa.visualization.make_plot_component(["Customers"]), + ], + model_params=model_params, + name="El Farol Bar Model", +) +page \ No newline at end of file diff --git a/examples/el_farol/el_farol/model.py b/examples/el_farol/el_farol/model.py index 4c927f00e..6019bb063 100644 --- a/examples/el_farol/el_farol/model.py +++ b/examples/el_farol/el_farol/model.py @@ -1,7 +1,7 @@ import mesa import numpy as np -from .agents import BarCustomer +from agents import BarCustomer class ElFarolBar(mesa.Model): diff --git a/examples/shape_example/shape_example/app.py b/examples/shape_example/shape_example/app.py new file mode 100644 index 000000000..c96b47187 --- /dev/null +++ b/examples/shape_example/shape_example/app.py @@ -0,0 +1,50 @@ +""" +Solara visualisation for the Shape Example. + +Run with: + solara run app.py +""" + +import mesa.visualization +from model import ShapeExample + + +def agent_portrayal(agent): + """Render each walker as an arrow pointing in its heading direction.""" + heading_to_angle = { + (1, 0): 0, # right + (0, 1): 90, # up + (-1, 0): 180, # left + (0, -1): 270, # down + } + return { + "color": "#1D9E75", + "shape": "arrowHead", + "scale": 0.8, + "heading_x": agent.heading[0], + "heading_y": agent.heading[1], + } + + +model_params = { + "num_agents": { + "type": "SliderInt", + "value": 2, + "label": "Number of agents", + "min": 1, + "max": 20, + "step": 1, + }, + "width": 20, + "height": 10, +} + +page = mesa.visualization.SolaraViz( + ShapeExample, + components=[ + mesa.visualization.make_space_component(agent_portrayal), + ], + model_params=model_params, + name="Shape Example — directional agents on a grid", +) +page \ No newline at end of file From d4b16a64395cd6a366c8a791a4ba2f22bda193d2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 21 Mar 2026 13:48:54 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- examples/caching_and_replay/app.py | 2 +- examples/el_farol/el_farol/app.py | 3 +-- examples/el_farol/el_farol/model.py | 1 - examples/shape_example/shape_example/app.py | 10 +++++----- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/examples/caching_and_replay/app.py b/examples/caching_and_replay/app.py index f7e054d60..52b7e1fbe 100644 --- a/examples/caching_and_replay/app.py +++ b/examples/caching_and_replay/app.py @@ -64,4 +64,4 @@ def agent_portrayal(agent): model_params=model_params, name="Schelling Segregation — with caching and replay", ) -page \ No newline at end of file +page diff --git a/examples/el_farol/el_farol/app.py b/examples/el_farol/el_farol/app.py index 84d6deeb8..1d807e0e7 100644 --- a/examples/el_farol/el_farol/app.py +++ b/examples/el_farol/el_farol/app.py @@ -8,7 +8,6 @@ import mesa.visualization from model import ElFarolBar - model_params = { "num_agents": { "type": "SliderInt", @@ -52,4 +51,4 @@ model_params=model_params, name="El Farol Bar Model", ) -page \ No newline at end of file +page diff --git a/examples/el_farol/el_farol/model.py b/examples/el_farol/el_farol/model.py index 6019bb063..41a3c8694 100644 --- a/examples/el_farol/el_farol/model.py +++ b/examples/el_farol/el_farol/model.py @@ -1,6 +1,5 @@ import mesa import numpy as np - from agents import BarCustomer diff --git a/examples/shape_example/shape_example/app.py b/examples/shape_example/shape_example/app.py index c96b47187..bcbfbe339 100644 --- a/examples/shape_example/shape_example/app.py +++ b/examples/shape_example/shape_example/app.py @@ -12,10 +12,10 @@ def agent_portrayal(agent): """Render each walker as an arrow pointing in its heading direction.""" heading_to_angle = { - (1, 0): 0, # right - (0, 1): 90, # up - (-1, 0): 180, # left - (0, -1): 270, # down + (1, 0): 0, # right + (0, 1): 90, # up + (-1, 0): 180, # left + (0, -1): 270, # down } return { "color": "#1D9E75", @@ -47,4 +47,4 @@ def agent_portrayal(agent): model_params=model_params, name="Shape Example — directional agents on a grid", ) -page \ No newline at end of file +page