Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
58386a5
Fix hex_ant: replace relative import with absolute import in model.py
Harshini2411 Mar 12, 2026
fa5e186
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 12, 2026
bd50c3b
Fix hex_snowflake: migrate from ModularServer to SolaraViz (Mesa 3.x)
Harshini2411 Mar 12, 2026
4d9c1c0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 12, 2026
14c294c
Fix shape_example: migrate from ModularServer to SolaraViz (Mesa 3.x)
Harshini2411 Mar 12, 2026
5b97968
Remove venv folders from tracking
Harshini2411 Mar 12, 2026
e27e298
Add .venv313 to gitignore
Harshini2411 Mar 12, 2026
9ddd87e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 12, 2026
2a28225
Fix charts: migrate from ModularServer to SolaraViz (Mesa 3.x)
Harshini2411 Mar 13, 2026
a3f4ba1
Fix ruff B018: remove useless expression in app.py
Harshini2411 Mar 13, 2026
6ac09ad
Fix .gitignore encoding: convert from UTF-16 to UTF-8
Harshini2411 Mar 16, 2026
83df1b4
Clean up duplicate entries in .gitignore
Harshini2411 Mar 16, 2026
0342b52
Fix shape_example: fix import path and move files to correct location
Harshini2411 Mar 16, 2026
532bc04
Fix hex_ant: use relative import for agent module
Harshini2411 Mar 16, 2026
11a1ce3
Fix hex_ant: restructure into package with nested folder and fix imports
Harshini2411 Mar 16, 2026
8bec5f6
Revert hex_ant restructure: keep flat structure matching upstream
Harshini2411 Mar 16, 2026
ff2f542
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 16, 2026
fc8b7a4
Fix hex_ant: use .data for PropertyLayer item assignment
Harshini2411 Mar 16, 2026
54c41dc
Fix hex_snowflake: restructure into package with nested folder and fi…
Harshini2411 Mar 16, 2026
dd367b6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 16, 2026
636ca85
Fix hex_snowflake: use relative import for cell module
Harshini2411 Mar 18, 2026
281b97a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 5 additions & 86 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,87 +1,6 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# ignore RL file - users download model on own
rl

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter and iPython notebook checkpoints
*.ipynb_checkpoints
*.virtual_documents

# Spyder app workspace config file
.spyderworkspace

# PyCharm environment files
.idea/

# VSCode environment files
.vscode/
*.code-workspace

# Apple OSX
*.DS_Store

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Virtual environment
.venv
.venv313
.venv313/
venv/

examples/caching_and_replay/my_cache_file_path.cache
__pycache__/
*.pyc
60 changes: 60 additions & 0 deletions examples/charts/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import solara
from charts.agents import Person
from charts.model import Charts
from mesa.visualization import SolaraViz, make_plot_component, make_space_component
from mesa.visualization.components import AgentPortrayalStyle
from mesa.visualization.user_param import Slider

# Colors - same palette as the original server.py (Matplotlib tab10)
RICH_COLOR = "#2ca02c" # green
POOR_COLOR = "#d62728" # red
MID_COLOR = "#1f77b4" # blue


def agent_portrayal(agent):
"""
Returns AgentPortrayalStyle (Mesa 3.x) instead of a dict.
Color encodes wealth class:
green -> savings > rich_threshold (rich)
red -> loans > 10 (poor)
blue -> everything else (middle class)
"""
if not isinstance(agent, Person):
return AgentPortrayalStyle()

color = MID_COLOR

if agent.savings > agent.model.rich_threshold:
color = RICH_COLOR
if agent.loans > 10:
color = POOR_COLOR

return AgentPortrayalStyle(color=color, size=20, marker="o")


model_params = {
"init_people": Slider(label="People", value=25, min=1, max=200, step=1),
"rich_threshold": Slider(label="Rich Threshold", value=10, min=1, max=20, step=1),
"reserve_percent": Slider(label="Reserves (%)", value=50, min=1, max=100, step=1),
}

SpaceGraph = make_space_component(agent_portrayal)

WealthClassChart = make_plot_component(
{"Rich": RICH_COLOR, "Poor": POOR_COLOR, "Middle Class": MID_COLOR}
)

MoneySupplyChart = make_plot_component(
{"Savings": "#9467bd", "Wallets": "#8c564b", "Money": "#17becf", "Loans": "#e377c2"}
)

# Wrap the instance in solara.Reactive to prevent render loops.
# SolaraViz expects Model | solara.Reactive[Model].
model = solara.Reactive(Charts())

page = SolaraViz(
model,
components=[SpaceGraph, WealthClassChart, MoneySupplyChart],
model_params=model_params,
name="Mesa Charts - Bank Reserves",
)
112 changes: 0 additions & 112 deletions examples/charts/charts/server.py

This file was deleted.

7 changes: 5 additions & 2 deletions examples/charts/run.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from charts.server import server
import subprocess
import sys
from pathlib import Path

server.launch(open_browser=True)
app_path = Path(__file__).parent / "app.py"
subprocess.run([sys.executable, "-m", "solara", "run", str(app_path)], check=False)
5 changes: 2 additions & 3 deletions examples/hex_ant/app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import matplotlib.pyplot as plt
from agent import AntState
from matplotlib.colors import LinearSegmentedColormap, ListedColormap
from mesa.visualization import SolaraViz, make_space_component
from mesa.visualization.components import PropertyLayerStyle

from .agent import AntState
from .model import AntForaging
from model import AntForaging

plt.rcParams["figure.figsize"] = (10, 10)

Expand Down
11 changes: 7 additions & 4 deletions examples/hex_ant/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import mesa
from mesa.discrete_space import HexGrid

from .agent import Ant
try:
from .agent import Ant
except ImportError:
from agent import Ant
from mesa.discrete_space import HexGrid


class AntForaging(mesa.Model):
Expand Down Expand Up @@ -57,9 +60,9 @@ def _init_environment(self):
# Create the Nest in the center
center = (self.grid.width // 2, self.grid.height // 2)
# Spike the 'home' pheromone at the nest so ants can find it initially
self.grid.pheromone_home[center] = 1.0
self.grid.pheromone_home.data[center] = 1.0
# Mark the home location
self.grid.home[center] = 1
self.grid.home.data[center] = 1

# Scatter some Food Sources
# Create 3 big clusters of food
Expand Down
21 changes: 21 additions & 0 deletions examples/hex_snowflake/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from cell import Cell
from mesa.visualization import SolaraViz, make_space_component
from model import HexSnowflake


def agent_portrayal(agent):
if agent is None:
return

if isinstance(agent, Cell):
color = "tab:green" if agent.state == Cell.ALIVE else "tab:grey"
return {"color": color, "size": 20}


model = HexSnowflake()

page = SolaraViz(
model,
components=[make_space_component(agent_portrayal=agent_portrayal)],
name="Hex Snowflake",
)
17 changes: 0 additions & 17 deletions examples/hex_snowflake/hex_snowflake/portrayal.py

This file was deleted.

12 changes: 0 additions & 12 deletions examples/hex_snowflake/hex_snowflake/server.py

This file was deleted.

3 changes: 0 additions & 3 deletions examples/hex_snowflake/run.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from hex_snowflake.server import server

server.launch(open_browser=True)
20 changes: 20 additions & 0 deletions examples/shape_example/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from mesa.visualization import SolaraViz, make_space_component
from model import ShapeExample, Walker


def agent_portrayal(agent):
if isinstance(agent, Walker):
return {
"color": "tab:green",
"size": 50,
"marker": "^",
}


model = ShapeExample()

page = SolaraViz(
model,
components=[make_space_component(agent_portrayal=agent_portrayal)],
name="Shape Model Example",
)
Loading
Loading