Skip to content

Commit 3b9fa59

Browse files
authored
Merge branch 'main' into meta-agents
2 parents c7c8311 + 696923f commit 3b9fa59

File tree

10 files changed

+151
-157
lines changed

10 files changed

+151
-157
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ To create a new release, follow these steps:
137137
9. The [`release.yml`](https://github.com/projectmesa/mesa/blob/main/.github/workflows/release.yml) CI workflow should automatically create and upload the package to PyPI. Verify this on [PyPI.org](https://pypi.org/project/mesa/).
138138
10. Finally, after release, open a new PR to update the version number in [`mesa/__init__.py`](https://github.com/projectmesa/mesa/blob/main/mesa/__init__.py) for the next release (e.g., `"3.1.0.dev"`).
139139

140+
A recorded video of this process is [available here](https://youtu.be/JE44jkegmns).
141+
140142
## Special Thanks
141143

142144
A special thanks to the following projects who offered inspiration for this contributing file.

HISTORY.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
---
22
title: Release History
33
---
4+
# 3.1.2 (2025-01-04)
5+
## Highlights
6+
Mesa v3.1.2 is a patch release containing updates to our wolf-sheep, shelling and prisoner's dilemma example models and improving documentation in the tutorials and visualisation docstring. No functional changes to the core library were made.
7+
8+
## What's Changed
9+
### 🔍 Examples updated
10+
* examples/wolf_sheep: Don't allow dumb moves by @EwoutH in https://github.com/projectmesa/mesa/pull/2503
11+
* Added homophily ratio in basic schelling example by @vbv-shm in https://github.com/projectmesa/mesa/pull/2520
12+
* examples: Update pd_grid analysis.ipynb to use new spaces by @quaquel in https://github.com/projectmesa/mesa/pull/2553
13+
### 📜 Documentation improvements
14+
* Corrected a few errors in Intro tutorial by @sanika-n in https://github.com/projectmesa/mesa/pull/2583
15+
* Small draw_space docstring fix by @quaquel in https://github.com/projectmesa/mesa/pull/2554
16+
* fix: model name in visualization tutorial by @Sahil-Chhoker in https://github.com/projectmesa/mesa/pull/2591
17+
18+
## New Contributors
19+
* @vbv-shm made their first contribution in https://github.com/projectmesa/mesa/pull/2520
20+
* @sanika-n made their first contribution in https://github.com/projectmesa/mesa/pull/2583
21+
22+
**Full Changelog**: https://github.com/projectmesa/mesa/compare/v3.1.1...v3.1.2
23+
424
# 3.1.1 (2024-12-14)
525
## Highlights
626
Mesa 3.1.1 is a maintenance release that includes visualization improvements and documentation updates. The key enhancement is the addition of an interactive play interval control to the visualization interface, allowing users to dynamically adjust simulation speed between 1ms and 500ms through a slider in the Controls panel.

docs/tutorials/intro_tutorial.ipynb

Lines changed: 22 additions & 22 deletions
Large diffs are not rendered by default.

docs/tutorials/visualization_tutorial.ipynb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@
128128
"outputs": [],
129129
"source": [
130130
"# Create initial model instance\n",
131-
"model1 = MoneyModel(n=50, width=10, height=10) #keyword arguments\n",
131+
"money_model = MoneyModel(n=50, width=10, height=10) #keyword arguments\n",
132132
"\n",
133133
"SpaceGraph = make_space_component(agent_portrayal)\n",
134134
"GiniPlot = make_plot_component(\"Gini\")\n",
135135
"\n",
136136
"page = SolaraViz(\n",
137-
" model1,\n",
137+
" money_model,\n",
138138
" components=[SpaceGraph, GiniPlot],\n",
139139
" model_params=model_params,\n",
140140
" name=\"Boltzmann Wealth Model\",\n",
@@ -207,13 +207,13 @@
207207
"outputs": [],
208208
"source": [
209209
"# Create initial model instance\n",
210-
"model = MoneyModel(n=50, width=10, height=10)\n",
210+
"money_model = MoneyModel(n=50, width=10, height=10)\n",
211211
"\n",
212212
"SpaceGraph = make_space_component(agent_portrayal)\n",
213213
"GiniPlot = make_plot_component(\"Gini\")\n",
214214
"\n",
215215
"page = SolaraViz(\n",
216-
" model1,\n",
216+
" money_model,\n",
217217
" components=[SpaceGraph, GiniPlot],\n",
218218
" model_params=model_params,\n",
219219
" name=\"Boltzmann Wealth Model\",\n",
@@ -318,7 +318,7 @@
318318
"outputs": [],
319319
"source": [
320320
"# Create initial model instance\n",
321-
"model = MoneyModel(n=50, width=10, height=10)\n",
321+
"money_model = MoneyModel(n=50, width=10, height=10)\n",
322322
"\n",
323323
"SpaceGraph = make_space_component(agent_portrayal)\n",
324324
"GiniPlot = make_plot_component(\"Gini\")"
@@ -354,7 +354,7 @@
354354
],
355355
"source": [
356356
"page = SolaraViz(\n",
357-
" model,\n",
357+
" money_model,\n",
358358
" components=[SpaceGraph, GiniPlot, Histogram],\n",
359359
" model_params=model_params,\n",
360360
" name=\"Boltzmann Wealth Model\",\n",
@@ -399,7 +399,7 @@
399399
}
400400
],
401401
"source": [
402-
"Histogram(model)"
402+
"Histogram(money_model)"
403403
]
404404
},
405405
{

mesa/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
]
2323

2424
__title__ = "mesa"
25-
__version__ = "3.1.1"
25+
__version__ = "3.1.2"
2626
__license__ = "Apache 2.0"
2727
_this_year = datetime.datetime.now(tz=datetime.UTC).date().year
2828
__copyright__ = f"Copyright {_this_year} Project Mesa Team"

mesa/examples/advanced/pd_grid/analysis.ipynb

Lines changed: 44 additions & 89 deletions
Large diffs are not rendered by default.

mesa/examples/basic/schelling/analysis.ipynb

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
},
1818
{
1919
"cell_type": "code",
20+
"execution_count": null,
2021
"metadata": {},
22+
"outputs": [],
2123
"source": [
2224
"import matplotlib.pyplot as plt\n",
2325
"import pandas as pd\n",
2426
"\n",
2527
"%matplotlib inline\n",
2628
"\n",
2729
"from model import Schelling"
28-
],
29-
"outputs": [],
30-
"execution_count": null
30+
]
3131
},
3232
{
3333
"cell_type": "markdown",
@@ -38,10 +38,14 @@
3838
},
3939
{
4040
"cell_type": "code",
41+
"execution_count": null,
4142
"metadata": {},
42-
"source": "model = Schelling(height=10, width=10, homophily=3, density=0.8, minority_pc=0.2)",
4343
"outputs": [],
44-
"execution_count": null
44+
"source": [
45+
"schelling_model = Schelling(\n",
46+
" height=10, width=10, homophily=3, density=0.8, minority_pc=0.2\n",
47+
")"
48+
]
4549
},
4650
{
4751
"cell_type": "markdown",
@@ -52,14 +56,14 @@
5256
},
5357
{
5458
"cell_type": "code",
59+
"execution_count": null,
5560
"metadata": {},
56-
"source": [
57-
"while model.running and model.steps < 100:\n",
58-
" model.step()\n",
59-
"print(model.steps) # Show how many steps have actually run"
60-
],
6161
"outputs": [],
62-
"execution_count": null
62+
"source": [
63+
"while schelling_model.running and schelling_model.steps < 100:\n",
64+
" schelling_model.step()\n",
65+
"print(schelling_model.steps) # Show how many steps have actually run"
66+
]
6367
},
6468
{
6569
"cell_type": "markdown",
@@ -70,21 +74,21 @@
7074
},
7175
{
7276
"cell_type": "code",
77+
"execution_count": null,
7378
"metadata": {},
74-
"source": [
75-
"model_out = model.datacollector.get_model_vars_dataframe()"
76-
],
7779
"outputs": [],
78-
"execution_count": null
80+
"source": [
81+
"model_out = schelling_model.datacollector.get_model_vars_dataframe()"
82+
]
7983
},
8084
{
8185
"cell_type": "code",
86+
"execution_count": null,
8287
"metadata": {},
88+
"outputs": [],
8389
"source": [
8490
"model_out.head()"
85-
],
86-
"outputs": [],
87-
"execution_count": null
91+
]
8892
},
8993
{
9094
"cell_type": "markdown",
@@ -95,12 +99,12 @@
9599
},
96100
{
97101
"cell_type": "code",
102+
"execution_count": null,
98103
"metadata": {},
104+
"outputs": [],
99105
"source": [
100106
"model_out.happy.plot()"
101-
],
102-
"outputs": [],
103-
"execution_count": null
107+
]
104108
},
105109
{
106110
"cell_type": "markdown",
@@ -115,10 +119,12 @@
115119
},
116120
{
117121
"cell_type": "code",
122+
"execution_count": null,
118123
"metadata": {},
119-
"source": "from mesa.batchrunner import batch_run",
120124
"outputs": [],
121-
"execution_count": null
125+
"source": [
126+
"from mesa.batchrunner import batch_run"
127+
]
122128
},
123129
{
124130
"cell_type": "markdown",
@@ -129,52 +135,52 @@
129135
},
130136
{
131137
"cell_type": "code",
138+
"execution_count": null,
132139
"metadata": {},
140+
"outputs": [],
133141
"source": [
134142
"fixed_params = {\"height\": 10, \"width\": 10, \"density\": 0.8, \"minority_pc\": 0.2}\n",
135143
"variable_parms = {\"homophily\": range(1, 9)}\n",
136144
"all_params = fixed_params | variable_parms"
137-
],
138-
"outputs": [],
139-
"execution_count": null
145+
]
140146
},
141147
{
142148
"cell_type": "code",
149+
"execution_count": null,
143150
"metadata": {},
151+
"outputs": [],
144152
"source": [
145153
"results = batch_run(\n",
146154
" Schelling,\n",
147155
" parameters=all_params,\n",
148156
" iterations=10,\n",
149157
" max_steps=200,\n",
150158
")"
151-
],
152-
"outputs": [],
153-
"execution_count": null
159+
]
154160
},
155161
{
156-
"metadata": {},
157162
"cell_type": "code",
163+
"execution_count": null,
164+
"metadata": {},
165+
"outputs": [],
158166
"source": [
159167
"df = pd.DataFrame(results)\n",
160168
"df"
161-
],
162-
"outputs": [],
163-
"execution_count": null
169+
]
164170
},
165171
{
166172
"cell_type": "code",
173+
"execution_count": null,
167174
"metadata": {},
175+
"outputs": [],
168176
"source": [
169177
"plt.scatter(df.homophily, df.happy)\n",
170178
"plt.xlabel(\"Homophily\")\n",
171179
"plt.ylabel(\"Happy Agents\")\n",
172180
"plt.grid()\n",
173181
"plt.title(\"Effect of Homophily on segregation\")\n",
174182
"plt.show()"
175-
],
176-
"outputs": [],
177-
"execution_count": null
183+
]
178184
}
179185
],
180186
"metadata": {

mesa/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def __init__(
9494
self._seed = seed # this allows for reproducing stdlib.random
9595

9696
try:
97-
self.rng: np.random.Generator = np.random.default_rng(rng)
97+
self.rng: np.random.Generator = np.random.default_rng(seed)
9898
except TypeError:
9999
rng = self.random.randint(0, sys.maxsize)
100100
self.rng: np.random.Generator = np.random.default_rng(rng)

mesa/visualization/mpl_space_drawing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ def draw_space(
117117
agent_portrayal: A callable that returns a dict specifying how to show the agent
118118
propertylayer_portrayal: a dict specifying how to show propertylayer(s)
119119
ax: the axes upon which to draw the plot
120-
post_process: a callable called with the Axes instance
121120
space_drawing_kwargs: any additional keyword arguments to be passed on to the underlying function for drawing the space.
122121
123122
Returns:

tests/test_model.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Tests for model.py."""
22

3+
import numpy as np
4+
35
from mesa.agent import Agent, AgentSet
46
from mesa.model import Model
57

@@ -37,6 +39,16 @@ def test_seed(seed=23):
3739
assert model2._seed == seed + 1
3840
assert model._seed == seed
3941

42+
assert Model(seed=42).random.random() == Model(seed=42).random.random()
43+
assert np.all(
44+
Model(seed=42).rng.random(
45+
10,
46+
)
47+
== Model(seed=42).rng.random(
48+
10,
49+
)
50+
)
51+
4052

4153
def test_reset_randomizer(newseed=42):
4254
"""Test resetting the random seed on the model."""

0 commit comments

Comments
 (0)