Skip to content

Commit

Permalink
Merge branch 'main' into meta-agents
Browse files Browse the repository at this point in the history
  • Loading branch information
tpike3 authored Jan 6, 2025
2 parents c7c8311 + 696923f commit 3b9fa59
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 157 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ To create a new release, follow these steps:
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/).
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"`).

A recorded video of this process is [available here](https://youtu.be/JE44jkegmns).

## Special Thanks

A special thanks to the following projects who offered inspiration for this contributing file.
Expand Down
20 changes: 20 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
---
title: Release History
---
# 3.1.2 (2025-01-04)
## Highlights
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.

## What's Changed
### 🔍 Examples updated
* examples/wolf_sheep: Don't allow dumb moves by @EwoutH in https://github.com/projectmesa/mesa/pull/2503
* Added homophily ratio in basic schelling example by @vbv-shm in https://github.com/projectmesa/mesa/pull/2520
* examples: Update pd_grid analysis.ipynb to use new spaces by @quaquel in https://github.com/projectmesa/mesa/pull/2553
### 📜 Documentation improvements
* Corrected a few errors in Intro tutorial by @sanika-n in https://github.com/projectmesa/mesa/pull/2583
* Small draw_space docstring fix by @quaquel in https://github.com/projectmesa/mesa/pull/2554
* fix: model name in visualization tutorial by @Sahil-Chhoker in https://github.com/projectmesa/mesa/pull/2591

## New Contributors
* @vbv-shm made their first contribution in https://github.com/projectmesa/mesa/pull/2520
* @sanika-n made their first contribution in https://github.com/projectmesa/mesa/pull/2583

**Full Changelog**: https://github.com/projectmesa/mesa/compare/v3.1.1...v3.1.2

# 3.1.1 (2024-12-14)
## Highlights
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.
Expand Down
44 changes: 22 additions & 22 deletions docs/tutorials/intro_tutorial.ipynb

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions docs/tutorials/visualization_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@
"outputs": [],
"source": [
"# Create initial model instance\n",
"model1 = MoneyModel(n=50, width=10, height=10) #keyword arguments\n",
"money_model = MoneyModel(n=50, width=10, height=10) #keyword arguments\n",
"\n",
"SpaceGraph = make_space_component(agent_portrayal)\n",
"GiniPlot = make_plot_component(\"Gini\")\n",
"\n",
"page = SolaraViz(\n",
" model1,\n",
" money_model,\n",
" components=[SpaceGraph, GiniPlot],\n",
" model_params=model_params,\n",
" name=\"Boltzmann Wealth Model\",\n",
Expand Down Expand Up @@ -207,13 +207,13 @@
"outputs": [],
"source": [
"# Create initial model instance\n",
"model = MoneyModel(n=50, width=10, height=10)\n",
"money_model = MoneyModel(n=50, width=10, height=10)\n",
"\n",
"SpaceGraph = make_space_component(agent_portrayal)\n",
"GiniPlot = make_plot_component(\"Gini\")\n",
"\n",
"page = SolaraViz(\n",
" model1,\n",
" money_model,\n",
" components=[SpaceGraph, GiniPlot],\n",
" model_params=model_params,\n",
" name=\"Boltzmann Wealth Model\",\n",
Expand Down Expand Up @@ -318,7 +318,7 @@
"outputs": [],
"source": [
"# Create initial model instance\n",
"model = MoneyModel(n=50, width=10, height=10)\n",
"money_model = MoneyModel(n=50, width=10, height=10)\n",
"\n",
"SpaceGraph = make_space_component(agent_portrayal)\n",
"GiniPlot = make_plot_component(\"Gini\")"
Expand Down Expand Up @@ -354,7 +354,7 @@
],
"source": [
"page = SolaraViz(\n",
" model,\n",
" money_model,\n",
" components=[SpaceGraph, GiniPlot, Histogram],\n",
" model_params=model_params,\n",
" name=\"Boltzmann Wealth Model\",\n",
Expand Down Expand Up @@ -399,7 +399,7 @@
}
],
"source": [
"Histogram(model)"
"Histogram(money_model)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion mesa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
]

__title__ = "mesa"
__version__ = "3.1.1"
__version__ = "3.1.2"
__license__ = "Apache 2.0"
_this_year = datetime.datetime.now(tz=datetime.UTC).date().year
__copyright__ = f"Copyright {_this_year} Project Mesa Team"
133 changes: 44 additions & 89 deletions mesa/examples/advanced/pd_grid/analysis.ipynb

Large diffs are not rendered by default.

78 changes: 42 additions & 36 deletions mesa/examples/basic/schelling/analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"\n",
"%matplotlib inline\n",
"\n",
"from model import Schelling"
],
"outputs": [],
"execution_count": null
]
},
{
"cell_type": "markdown",
Expand All @@ -38,10 +38,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": "model = Schelling(height=10, width=10, homophily=3, density=0.8, minority_pc=0.2)",
"outputs": [],
"execution_count": null
"source": [
"schelling_model = Schelling(\n",
" height=10, width=10, homophily=3, density=0.8, minority_pc=0.2\n",
")"
]
},
{
"cell_type": "markdown",
Expand All @@ -52,14 +56,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [
"while model.running and model.steps < 100:\n",
" model.step()\n",
"print(model.steps) # Show how many steps have actually run"
],
"outputs": [],
"execution_count": null
"source": [
"while schelling_model.running and schelling_model.steps < 100:\n",
" schelling_model.step()\n",
"print(schelling_model.steps) # Show how many steps have actually run"
]
},
{
"cell_type": "markdown",
Expand All @@ -70,21 +74,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [
"model_out = model.datacollector.get_model_vars_dataframe()"
],
"outputs": [],
"execution_count": null
"source": [
"model_out = schelling_model.datacollector.get_model_vars_dataframe()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model_out.head()"
],
"outputs": [],
"execution_count": null
]
},
{
"cell_type": "markdown",
Expand All @@ -95,12 +99,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model_out.happy.plot()"
],
"outputs": [],
"execution_count": null
]
},
{
"cell_type": "markdown",
Expand All @@ -115,10 +119,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": "from mesa.batchrunner import batch_run",
"outputs": [],
"execution_count": null
"source": [
"from mesa.batchrunner import batch_run"
]
},
{
"cell_type": "markdown",
Expand All @@ -129,52 +135,52 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fixed_params = {\"height\": 10, \"width\": 10, \"density\": 0.8, \"minority_pc\": 0.2}\n",
"variable_parms = {\"homophily\": range(1, 9)}\n",
"all_params = fixed_params | variable_parms"
],
"outputs": [],
"execution_count": null
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"results = batch_run(\n",
" Schelling,\n",
" parameters=all_params,\n",
" iterations=10,\n",
" max_steps=200,\n",
")"
],
"outputs": [],
"execution_count": null
]
},
{
"metadata": {},
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df = pd.DataFrame(results)\n",
"df"
],
"outputs": [],
"execution_count": null
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.scatter(df.homophily, df.happy)\n",
"plt.xlabel(\"Homophily\")\n",
"plt.ylabel(\"Happy Agents\")\n",
"plt.grid()\n",
"plt.title(\"Effect of Homophily on segregation\")\n",
"plt.show()"
],
"outputs": [],
"execution_count": null
]
}
],
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion mesa/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __init__(
self._seed = seed # this allows for reproducing stdlib.random

try:
self.rng: np.random.Generator = np.random.default_rng(rng)
self.rng: np.random.Generator = np.random.default_rng(seed)
except TypeError:
rng = self.random.randint(0, sys.maxsize)
self.rng: np.random.Generator = np.random.default_rng(rng)
Expand Down
1 change: 0 additions & 1 deletion mesa/visualization/mpl_space_drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def draw_space(
agent_portrayal: A callable that returns a dict specifying how to show the agent
propertylayer_portrayal: a dict specifying how to show propertylayer(s)
ax: the axes upon which to draw the plot
post_process: a callable called with the Axes instance
space_drawing_kwargs: any additional keyword arguments to be passed on to the underlying function for drawing the space.
Returns:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests for model.py."""

import numpy as np

from mesa.agent import Agent, AgentSet
from mesa.model import Model

Expand Down Expand Up @@ -37,6 +39,16 @@ def test_seed(seed=23):
assert model2._seed == seed + 1
assert model._seed == seed

assert Model(seed=42).random.random() == Model(seed=42).random.random()
assert np.all(
Model(seed=42).rng.random(
10,
)
== Model(seed=42).rng.random(
10,
)
)


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

0 comments on commit 3b9fa59

Please sign in to comment.