Skip to content

Commit a03fc2b

Browse files
committed
Merge remote-tracking branch 'upstream/main' into move_spaces
2 parents 7f6ee48 + eaf7457 commit a03fc2b

File tree

3 files changed

+95
-23
lines changed

3 files changed

+95
-23
lines changed

HISTORY.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,59 @@
11
---
22
title: Release History
33
---
4+
# 3.0.0a4 (2024-09-09)
5+
## Highlights
6+
Mesa 3.0.0a4 contains two major breaking changes:
7+
1. The Agent's `unique_id` is now automatically assigned, so doesn't need to be passed to the Agent class anymore. In a subclassed custom Agent, like normally used, this now looks like this:
8+
```diff
9+
class Wolf(Agent):
10+
- def __init__(self, unique_id, model, energy=None):
11+
+ def __init__(self, model, energy=None):
12+
# When initializing the super class (Agent), passing unique_id isn't needed anymore
13+
- super().__init__(unique_id, model)
14+
+ super().__init__(model)
15+
16+
- wolf = Wolf(unique_id, model)
17+
+ wolf = Wolf(model)
18+
```
19+
Example models were updated in [mesa-examples#194](https://github.com/projectmesa/mesa-examples/pull/194), which shows more examples on how to update existing models.
20+
21+
2. Our visualisation API is being overhauled, to be more flexible and powerful. For more details, see [#2278](https://github.com/projectmesa/mesa/pull/2278).
22+
- An initial update to the tutorial was made in [#2289](https://github.com/projectmesa/mesa/pull/2289) and is [available here](https://mesa.readthedocs.io/en/latest/tutorials/visualization_tutorial.html).
23+
- An initial example model was updated in [mesa-examples#195](https://github.com/projectmesa/mesa-examples/pull/195), and more examples will be updated in [mesa-examples#195](https://github.com/projectmesa/mesa-examples/pull/193).
24+
- The old SolaraViz API is still available at `mesa.experimental`, but might be removed in future releases.
25+
26+
Furthermore, the AgentSet has a new `agg` method to quickly get an aggerate value (for example `min_energy = model.agents.agg("energy", min)`) ([#2266](https://github.com/projectmesa/mesa/pull/2266)), The Model `get_agents_of_type` function is replaced by directly exposing the `agents_by_type` property (which can be accessed as a dict) ([#2267](https://github.com/projectmesa/mesa/pull/2267), [mesa-examples#190](https://github.com/projectmesa/mesa-examples/pull/190)) and the AgentSet get() methods can now handle missing values by replacing it with a default value ([#2279](https://github.com/projectmesa/mesa/pull/2279)).
27+
28+
Finally, it fixes a bug in which the Grid's `move_agent_to_one_of` method with `selection="closest"` selected a location deterministically, instead of randomly ([#2118](https://github.com/projectmesa/mesa/pull/2118)).
29+
30+
## What's Changed
31+
### ⚠️ Breaking changes
32+
* move solara_viz back to experimental by @Corvince in https://github.com/projectmesa/mesa/pull/2278
33+
* track unique_id automatically by @quaquel in https://github.com/projectmesa/mesa/pull/2260
34+
### 🎉 New features added
35+
* AgentSet: Add `agg` method by @EwoutH in https://github.com/projectmesa/mesa/pull/2266
36+
* Implement new SolaraViz API by @Corvince in https://github.com/projectmesa/mesa/pull/2263
37+
### 🛠 Enhancements made
38+
* Model: Replace `get_agents_of_type` method with `agents_by_type` property by @EwoutH in https://github.com/projectmesa/mesa/pull/2267
39+
* add default SolaraViz by @Corvince in https://github.com/projectmesa/mesa/pull/2280
40+
* Simplify ModelController by @Corvince in https://github.com/projectmesa/mesa/pull/2282
41+
* Add default values and missing value handling to `agentset.get` by @quaquel in https://github.com/projectmesa/mesa/pull/2279
42+
### 🐛 Bugs fixed
43+
* Fix deterministic behavior in `move_agent_to_one_of` with `selection="closest"` by @OrenBochman in https://github.com/projectmesa/mesa/pull/2118
44+
### 📜 Documentation improvements
45+
* docs: Fix Visualization Tutorial (main branch) by @EwoutH in https://github.com/projectmesa/mesa/pull/2271
46+
* Docs: Fix broken relative links by removing `.html` suffix by @EwoutH in https://github.com/projectmesa/mesa/pull/2274
47+
* Readthedocs: Don't let notebook failures pass silently by @EwoutH in https://github.com/projectmesa/mesa/pull/2276
48+
* Update viz tutorial to the new API by @Corvince in https://github.com/projectmesa/mesa/pull/2289
49+
### 🔧 Maintenance
50+
* Resolve multiprocessing warning, state Python 3.13 support by @rht in https://github.com/projectmesa/mesa/pull/2246
51+
52+
## New Contributors
53+
* @OrenBochman made their first contribution in https://github.com/projectmesa/mesa/pull/2118
54+
55+
**Full Changelog**: https://github.com/projectmesa/mesa/compare/v3.0.0a3...v3.0.0a4
56+
457
# 3.0.0a3 (2024-08-30)
558
## Highlights
659
Developments toward Mesa 3.0 are steaming ahead, and our fourth alpha release is packed with features and updates - only 8 days after our third.

docs/tutorials/visualization_tutorial.ipynb

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"cell_type": "markdown",
1212
"metadata": {},
1313
"source": [
14-
"*This version of the visualisation tutorial is updated for Mesa 3.0, and works with Mesa `3.0.0a1` and above. If you are using Mesa 2.3.x, check out the [stable version](https://mesa.readthedocs.io/en/stable/tutorials/visualization_tutorial.html) of this tutorial on Readthedocs.*\n",
14+
"*This version of the visualisation tutorial is updated for Mesa 3.0, and works with Mesa `3.0.0a4` and above. If you are using Mesa 2.3.x, check out the [stable version](https://mesa.readthedocs.io/en/stable/tutorials/visualization_tutorial.html) of this tutorial on Readthedocs.*\n",
1515
"\n",
1616
"**Important:** \n",
1717
"- If you are just exploring Mesa and want the fastest way to execute the code we recommend executing this tutorial online in a Colab notebook. [![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/projectmesa/mesa/blob/main/docs/tutorials/visualization_tutorial.ipynb)\n",
@@ -21,7 +21,7 @@
2121
"\n",
2222
"So far, we've built a model, run it, and analyzed some output afterwards. However, one of the advantages of agent-based models is that we can often watch them run step by step, potentially spotting unexpected patterns, behaviors or bugs, or developing new intuitions, hypotheses, or insights. Other times, watching a model run can explain it to an unfamiliar audience better than static explanations. Like many ABM frameworks, Mesa allows you to create an interactive visualization of the model. In this section we'll walk through creating a visualization using built-in components, and (for advanced users) how to create a new visualization element.\n",
2323
"\n",
24-
"First, a quick explanation of how Mesa's interactive visualization works. The visualization is done in a browser window, using the [Solara](https://solara.dev/) framework, a pure Python, React-style web framework. Running `solara run app.py` will launch a web server, which runs the model, and displays model detail at each step via the Matplotlib plotting library. Alternatively, you can execute everything inside a Jupyter environment."
24+
"First, a quick explanation of how Mesa's interactive visualization works. The visualization is done in a browser window, using the [Solara](https://solara.dev/) framework, a pure Python, React-style web framework. Running `solara run app.py` will launch a web server, which runs the model, and displays model detail at each step via the Matplotlib plotting library. Alternatively, you can execute everything inside a notebook environment and display it inline."
2525
]
2626
},
2727
{
@@ -105,7 +105,7 @@
105105
"cell_type": "markdown",
106106
"metadata": {},
107107
"source": [
108-
"Next, we instantiate the visualization object which (by default) displays the grid containing the agents, and timeseries of of values computed by the model's data collector. In this example, we specify the Gini coefficient.\n",
108+
"Next, we instantiate the visualization object which (by default) displays the grid containing the agents, and timeseries of values computed by the model's data collector. In this example, we specify the Gini coefficient.\n",
109109
"\n",
110110
"There are 3 buttons:\n",
111111
"- the step button, which advances the model by 1 step\n",
@@ -123,14 +123,19 @@
123123
},
124124
"outputs": [],
125125
"source": [
126-
"from mesa.visualization import SolaraViz\n",
126+
"from mesa.visualization import SolaraViz, make_plot_measure, make_space_matplotlib\n",
127+
"\n",
128+
"# Create initial model instance\n",
129+
"model1 = BoltzmannWealthModel(50, 10, 10)\n",
130+
"\n",
131+
"SpaceGraph = make_space_matplotlib(agent_portrayal)\n",
132+
"GiniPlot = make_plot_measure(\"Gini\")\n",
127133
"\n",
128134
"page = SolaraViz(\n",
129-
" BoltzmannWealthModel,\n",
130-
" model_params,\n",
131-
" measures=[\"Gini\"],\n",
132-
" name=\"Money Model\",\n",
133-
" agent_portrayal=agent_portrayal,\n",
135+
" model1,\n",
136+
" components=[SpaceGraph, GiniPlot],\n",
137+
" model_params=model_params,\n",
138+
" name=\"Boltzmann Wealth Model\",\n",
134139
")\n",
135140
"# This is required to render the visualization in the Jupyter notebook\n",
136141
"page"
@@ -170,11 +175,10 @@
170175
"outputs": [],
171176
"source": [
172177
"page = SolaraViz(\n",
173-
" BoltzmannWealthModel,\n",
174-
" model_params,\n",
175-
" measures=[\"Gini\"],\n",
176-
" name=\"Money Model\",\n",
177-
" agent_portrayal=agent_portrayal,\n",
178+
" model1,\n",
179+
" components=[SpaceGraph, GiniPlot],\n",
180+
" model_params=model_params,\n",
181+
" name=\"Boltzmann Wealth Model\",\n",
178182
")\n",
179183
"# This is required to render the visualization in the Jupyter notebook\n",
180184
"page"
@@ -202,8 +206,8 @@
202206
"import solara\n",
203207
"from matplotlib.figure import Figure\n",
204208
"\n",
205-
"\n",
206-
"def make_histogram(model):\n",
209+
"@solara.component\n",
210+
"def Histogram(model):\n",
207211
" # Note: you must initialize a figure using this method instead of\n",
208212
" # plt.figure(), for thread safety purpose\n",
209213
" fig = Figure()\n",
@@ -219,7 +223,23 @@
219223
"cell_type": "markdown",
220224
"metadata": {},
221225
"source": [
222-
"Next, we reinitialize the visualization object, but this time with the histogram (see the measures argument)."
226+
"In a notebook environment we can directly display the visualization by calling it with the model instance"
227+
]
228+
},
229+
{
230+
"cell_type": "code",
231+
"execution_count": null,
232+
"metadata": {},
233+
"outputs": [],
234+
"source": [
235+
"Histogram(model1)"
236+
]
237+
},
238+
{
239+
"cell_type": "markdown",
240+
"metadata": {},
241+
"source": [
242+
"Next, we update our solara frontend to use this new component"
223243
]
224244
},
225245
{
@@ -229,11 +249,10 @@
229249
"outputs": [],
230250
"source": [
231251
"page = SolaraViz(\n",
232-
" BoltzmannWealthModel,\n",
233-
" model_params,\n",
234-
" measures=[\"Gini\", make_histogram],\n",
235-
" name=\"Money Model\",\n",
236-
" agent_portrayal=agent_portrayal,\n",
252+
" model1,\n",
253+
" components=[SpaceGraph, GiniPlot, Histogram],\n",
254+
" model_params=model_params,\n",
255+
" name=\"Boltzmann Wealth Model\",\n",
237256
")\n",
238257
"# This is required to render the visualization in the Jupyter notebook\n",
239258
"page"

mesa/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
]
2828

2929
__title__ = "mesa"
30-
__version__ = "3.0.0a3"
30+
__version__ = "3.0.0a4"
3131
__license__ = "Apache 2.0"
3232
_this_year = datetime.datetime.now(tz=datetime.timezone.utc).date().year
3333
__copyright__ = f"Copyright {_this_year} Project Mesa Team"

0 commit comments

Comments
 (0)