Mesa 3.1.0__tar.gz → 3.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of Mesa might be problematic. Click here for more details.
- {mesa-3.1.0 → mesa-3.1.1}/HISTORY.md +29 -0
- {mesa-3.1.0 → mesa-3.1.1}/PKG-INFO +1 -1
- {mesa-3.1.0 → mesa-3.1.1}/docs/getting_started.md +10 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/migration_guide.md +11 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/tutorials/MoneyModel.py +6 -5
- {mesa-3.1.0 → mesa-3.1.1}/docs/tutorials/intro_tutorial.ipynb +38 -43
- {mesa-3.1.0 → mesa-3.1.1}/docs/tutorials/visualization_tutorial.ipynb +70 -64
- {mesa-3.1.0 → mesa-3.1.1}/mesa/__init__.py +1 -1
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/pd_grid/agents.py +2 -1
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/pd_grid/model.py +3 -5
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/sugarscape_g1mt/agents.py +12 -65
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/sugarscape_g1mt/app.py +17 -17
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/sugarscape_g1mt/model.py +45 -52
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/wolf_sheep/agents.py +3 -1
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/wolf_sheep/model.py +17 -16
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/schelling/agents.py +11 -5
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/schelling/app.py +1 -1
- {mesa-3.1.0 → mesa-3.1.1}/mesa/visualization/mpl_space_drawing.py +6 -3
- {mesa-3.1.0 → mesa-3.1.1}/mesa/visualization/solara_viz.py +26 -6
- {mesa-3.1.0 → mesa-3.1.1}/tests/test_solara_viz.py +17 -0
- {mesa-3.1.0 → mesa-3.1.1}/.codespellignore +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/.coveragerc +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/.github/ISSUE_TEMPLATE/bug-report.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/.github/ISSUE_TEMPLATE/config.yml +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/.github/ISSUE_TEMPLATE/feature-request.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/.github/PULL_REQUEST_TEMPLATE/bug.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/.github/PULL_REQUEST_TEMPLATE/feature.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/.github/dependabot.yml +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/.github/pull_request_template.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/.github/release.yml +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/.github/workflows/benchmarks.yml +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/.github/workflows/build_lint.yml +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/.github/workflows/release.yml +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/.gitignore +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/.pre-commit-config.yaml +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/.readthedocs.yml +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/CITATION.bib +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/CODE_OF_CONDUCT.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/CONTRIBUTING.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/Dockerfile +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/LICENSE +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/NOTICE +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/README.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/benchmarks/compare_timings.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/benchmarks/configurations.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/benchmarks/global_benchmark.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/binder/environment.yml +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/codecov.yaml +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docker-compose.yml +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/Makefile +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/README.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/_static/switcher.json +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/apis/agent.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/apis/api_main.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/apis/batchrunner.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/apis/datacollection.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/apis/experimental.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/apis/mesa_logging.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/apis/model.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/apis/space.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/apis/visualization.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/best-practices.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/conf.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/example_template.txt +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/examples_overview_template.txt +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/images/mesa_logo.ico +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/images/mesa_logo.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/images/tutorial/br_ginis.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/images/tutorial/dc_endwealth.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/images/tutorial/dc_gini.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/images/tutorial/dc_oneagent.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/images/tutorial/first_hist.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/images/tutorial/multirun_hist.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/images/tutorial/numpy_grid.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/images/tutorial/viz_chart.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/images/tutorial/viz_empty.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/images/tutorial/viz_greycircles.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/images/tutorial/viz_histogram.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/images/tutorial/viz_redcircles.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/images/wolf_sheep.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/index.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/make.bat +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/mesa.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/tutorials/files/viz_chart.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/tutorials/files/viz_empty.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/tutorials/files/viz_greycircles.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/tutorials/files/viz_histogram.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/tutorials/files/viz_redcircles.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/docs/tutorials/files/viz_slider.png +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/maintenance/fetch_unlabeled_prs.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/agent.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/batchrunner.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/datacollection.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/README.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/epstein_civil_violence/Epstein Civil Violence.ipynb +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/epstein_civil_violence/Readme.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/epstein_civil_violence/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/epstein_civil_violence/agents.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/epstein_civil_violence/app.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/epstein_civil_violence/model.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/pd_grid/Readme.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/pd_grid/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/pd_grid/analysis.ipynb +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/pd_grid/app.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/sugarscape_g1mt/Readme.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/sugarscape_g1mt/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/sugarscape_g1mt/sugar-map.txt +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/sugarscape_g1mt/tests.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/wolf_sheep/Readme.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/wolf_sheep/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/advanced/wolf_sheep/app.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/boid_flockers/Readme.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/boid_flockers/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/boid_flockers/agents.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/boid_flockers/app.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/boid_flockers/model.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/boltzmann_wealth_model/Readme.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/boltzmann_wealth_model/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/boltzmann_wealth_model/agents.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/boltzmann_wealth_model/app.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/boltzmann_wealth_model/model.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/boltzmann_wealth_model/st_app.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/conways_game_of_life/Readme.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/conways_game_of_life/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/conways_game_of_life/agents.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/conways_game_of_life/app.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/conways_game_of_life/model.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/conways_game_of_life/st_app.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/schelling/Readme.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/schelling/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/schelling/analysis.ipynb +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/schelling/model.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/virus_on_network/Readme.md +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/virus_on_network/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/virus_on_network/agents.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/virus_on_network/app.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/examples/basic/virus_on_network/model.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/experimental/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/experimental/cell_space/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/experimental/cell_space/cell.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/experimental/cell_space/cell_agent.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/experimental/cell_space/cell_collection.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/experimental/cell_space/discrete_space.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/experimental/cell_space/grid.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/experimental/cell_space/network.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/experimental/cell_space/property_layer.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/experimental/cell_space/voronoi.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/experimental/devs/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/experimental/devs/eventlist.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/experimental/devs/simulator.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/experimental/mesa_signals/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/experimental/mesa_signals/mesa_signal.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/experimental/mesa_signals/observable_collections.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/experimental/mesa_signals/signals_util.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/mesa_logging.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/model.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/space.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/visualization/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/visualization/components/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/visualization/components/altair_components.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/visualization/components/matplotlib_components.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/visualization/user_param.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mesa/visualization/utils.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/mypy.ini +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/pyproject.toml +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/tests/__init__.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/tests/read_requirements.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/tests/test_agent.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/tests/test_batch_run.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/tests/test_cell_space.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/tests/test_components_matplotlib.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/tests/test_datacollector.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/tests/test_devs.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/tests/test_end_to_end_viz.sh +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/tests/test_examples.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/tests/test_grid.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/tests/test_import_namespace.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/tests/test_lifespan.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/tests/test_mesa_logging.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/tests/test_mesa_signals.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/tests/test_model.py +0 -0
- {mesa-3.1.0 → mesa-3.1.1}/tests/test_space.py +0 -0
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Release History
|
|
3
3
|
---
|
|
4
|
+
# 3.1.1 (2024-12-14)
|
|
5
|
+
## Highlights
|
|
6
|
+
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.
|
|
7
|
+
|
|
8
|
+
Several example models were updated to use Mesa 3.1's recommended practices, particularly the `create_agents()` method for more efficient agent creation and NumPy's `rng.integers()` for random number generation. The Sugarscape example was modernized to use PropertyLayers.
|
|
9
|
+
|
|
10
|
+
Bug fixes include improvements to PropertyLayer visualization and a correction to the Schelling model's neighbor similarity calculation. The tutorials were also updated to reflect current best practices in Mesa 3.1.
|
|
11
|
+
|
|
12
|
+
## What's Changed
|
|
13
|
+
### 🎉 New features added
|
|
14
|
+
* Add Interactive Play Interval Control to Mesa Visualization by @AdamZh0u in https://github.com/projectmesa/mesa/pull/2540
|
|
15
|
+
### 🐛 Bugs fixed
|
|
16
|
+
* bug fixes for draw_property_layers by @quaquel in https://github.com/projectmesa/mesa/pull/2548
|
|
17
|
+
### 🔍 Examples updated
|
|
18
|
+
* Wolf-sheep to use `create_agent` by @quaquel in https://github.com/projectmesa/mesa/pull/2543
|
|
19
|
+
* Shift sugarscape example to using create_agent by @quaquel in https://github.com/projectmesa/mesa/pull/2544
|
|
20
|
+
* Fix: Schelling Model Neighbor Similarity Calculation by @Sahil-Chhoker in https://github.com/projectmesa/mesa/pull/2518
|
|
21
|
+
* Change pd_grid example to use create_agents by @quaquel in https://github.com/projectmesa/mesa/pull/2545
|
|
22
|
+
* Switch sugarscape to using property layers by @quaquel in https://github.com/projectmesa/mesa/pull/2546
|
|
23
|
+
### 📜 Documentation improvements
|
|
24
|
+
* Updated docs and check_model param by @nissu99 in https://github.com/projectmesa/mesa/pull/2510
|
|
25
|
+
* Update tutorials to use `create_agents` and `rng.integers` by @DarshPareek in https://github.com/projectmesa/mesa/pull/2541
|
|
26
|
+
|
|
27
|
+
## New Contributors
|
|
28
|
+
* @nissu99 made their first contribution in https://github.com/projectmesa/mesa/pull/2510
|
|
29
|
+
* @DarshPareek made their first contribution in https://github.com/projectmesa/mesa/pull/2541
|
|
30
|
+
|
|
31
|
+
**Full Changelog**: https://github.com/projectmesa/mesa/compare/v3.1.0...3.1.1
|
|
32
|
+
|
|
4
33
|
# 3.1.0 (2024-12-04)
|
|
5
34
|
## Highlights
|
|
6
35
|
With Mesa 3.1.0 we're back on our regular release schedule after the big Mesa 3.0 release, with some exciting new features.
|
|
@@ -180,6 +180,16 @@ Mesa now uses a new browser-based visualization system called SolaraViz. This al
|
|
|
180
180
|
|
|
181
181
|
> **Note:** SolaraViz is experimental and still in active development for Mesa 3.0. While we attempt to minimize them, there might be API breaking changes between Mesa 3.0 and 3.1. There won't be breaking changes between Mesa 3.0.x patch releases.
|
|
182
182
|
|
|
183
|
+
> **Note:** SolaraViz instantiates new models using `**model_parameters.value`, so all model inputs must be keyword arguments.
|
|
184
|
+
|
|
185
|
+
Ensure your model's `__init__` method accepts keyword arguments matching the `model_params` keys.
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
class MyModel(Model):
|
|
189
|
+
def __init__(self, n_agents=10, seed=None):
|
|
190
|
+
super().__init__(seed=seed)
|
|
191
|
+
# Initialize the model with N agents
|
|
192
|
+
|
|
183
193
|
The core functionality for building your own visualizations resides in the [`mesa.visualization`](apis/visualization) namespace
|
|
184
194
|
|
|
185
195
|
Here's a basic example of how to set up a visualization:
|
|
@@ -259,6 +259,17 @@ the import from mesa.experimental. Otherwise here is a list of things you need t
|
|
|
259
259
|
|
|
260
260
|
Previously SolaraViz was initialized by providing a `model_cls` and a `model_params`. This has changed to expect a model instance `model`. You can still provide (user-settable) `model_params`, but only if users should be able to change them. It is now also possible to pass in a "reactive model" by first calling `model = solara.reactive(model)`. This is useful for notebook environments. It allows you to pass the model to the SolaraViz Module, but continue to use the model. For example calling `model.value.step()` (notice the extra .value) will automatically update the plots. This currently only automatically works for the step method, you can force visualization updates by calling `model.value.force_update()`.
|
|
261
261
|
|
|
262
|
+
### Model Initialization with Keyword Arguments
|
|
263
|
+
|
|
264
|
+
With the introduction of SolaraViz in Mesa 3.0, models are now instantiated using `**model_parameters.value`. This means all inputs for initializing a new model must be keyword arguments. Ensure your model's `__init__` method accepts keyword arguments matching the keys in `model_params`.
|
|
265
|
+
|
|
266
|
+
```python
|
|
267
|
+
class MyModel(mesa.Model):
|
|
268
|
+
def __init__(self, n_agents=10, seed=None):
|
|
269
|
+
super().__init__(seed=seed)
|
|
270
|
+
# Initialize the model with N agents
|
|
271
|
+
```
|
|
272
|
+
|
|
262
273
|
#### Default space visualization
|
|
263
274
|
|
|
264
275
|
Previously we included a default space drawer that you could configure with an `agent_portrayal` function. You now have to explicitly create a space drawer with the `agent_portrayal` function
|
|
@@ -62,12 +62,13 @@ class MoneyModel(mesa.Model):
|
|
|
62
62
|
self.grid = mesa.space.MultiGrid(width, height, True)
|
|
63
63
|
|
|
64
64
|
# Create agents
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
agents = MoneyAgent.create_agents(model=self, n=n)
|
|
66
|
+
# Create x and y positions for agents
|
|
67
|
+
x = self.rng.integers(0, self.grid.width, size=(n,))
|
|
68
|
+
y = self.rng.integers(0, self.grid.height, size=(n,))
|
|
69
|
+
for a, i, j in zip(agents, x, y):
|
|
67
70
|
# Add the agent to a random grid cell
|
|
68
|
-
|
|
69
|
-
y = self.random.randrange(self.grid.height)
|
|
70
|
-
self.grid.place_agent(a, (x, y))
|
|
71
|
+
self.grid.place_agent(a, (i, j))
|
|
71
72
|
|
|
72
73
|
self.datacollector = mesa.DataCollector(
|
|
73
74
|
model_reporters={"Gini": compute_gini}, agent_reporters={"Wealth": "wealth"}
|
|
@@ -246,8 +246,7 @@
|
|
|
246
246
|
" super().__init__(seed=seed)\n",
|
|
247
247
|
" self.num_agents = n\n",
|
|
248
248
|
" # Create agents\n",
|
|
249
|
-
"
|
|
250
|
-
" a = MoneyAgent(self)"
|
|
249
|
+
" MoneyAgent.create_agents(model=self, n=n)"
|
|
251
250
|
]
|
|
252
251
|
},
|
|
253
252
|
{
|
|
@@ -295,11 +294,8 @@
|
|
|
295
294
|
" super().__init__(seed=seed)\n",
|
|
296
295
|
" self.num_agents = n\n",
|
|
297
296
|
"\n",
|
|
298
|
-
" # Create agents\n",
|
|
299
|
-
"
|
|
300
|
-
" a = MoneyAgent(\n",
|
|
301
|
-
" self\n",
|
|
302
|
-
" ) # This calls the agent class parameter n number of times\n",
|
|
297
|
+
" # Create n agents\n",
|
|
298
|
+
" MoneyAgent.create_agents(model=self, n=n)\n",
|
|
303
299
|
"\n",
|
|
304
300
|
" def step(self):\n",
|
|
305
301
|
" \"\"\"Advance the model by one step.\"\"\"\n",
|
|
@@ -478,10 +474,7 @@
|
|
|
478
474
|
" self.num_agents = n\n",
|
|
479
475
|
"\n",
|
|
480
476
|
" # Create agents\n",
|
|
481
|
-
"
|
|
482
|
-
" a = MoneyAgent(\n",
|
|
483
|
-
" self\n",
|
|
484
|
-
" ) # This calls the agent class parameter n number of times\n",
|
|
477
|
+
" MoneyAgent.create_agents(model=self, n=n)\n",
|
|
485
478
|
"\n",
|
|
486
479
|
" def step(self):\n",
|
|
487
480
|
" \"\"\"Advance the model by one step.\"\"\"\n",
|
|
@@ -620,13 +613,13 @@
|
|
|
620
613
|
" self.grid = mesa.space.MultiGrid(width, height, True)\n",
|
|
621
614
|
"\n",
|
|
622
615
|
" # Create agents\n",
|
|
623
|
-
"
|
|
624
|
-
"
|
|
625
|
-
"\n",
|
|
616
|
+
" agents = MoneyAgent.create_agents(model=self, n=n)\n",
|
|
617
|
+
" # Create x and y positions for agents\n",
|
|
618
|
+
" x = self.rng.randint(0, self.grid.width, size=(n,))\n",
|
|
619
|
+
" y = self.rng.randint(0, self.grid.height, size=(n,))\n",
|
|
620
|
+
" for a, i, j in zip(agents, x, y):\n",
|
|
626
621
|
" # Add the agent to a random grid cell\n",
|
|
627
|
-
"
|
|
628
|
-
" y = self.random.randrange(self.grid.height)\n",
|
|
629
|
-
" self.grid.place_agent(a, (x, y))"
|
|
622
|
+
" self.grid.place_agent(a, (i, j))"
|
|
630
623
|
]
|
|
631
624
|
},
|
|
632
625
|
{
|
|
@@ -724,12 +717,13 @@
|
|
|
724
717
|
" self.grid = mesa.space.MultiGrid(width, height, True)\n",
|
|
725
718
|
"\n",
|
|
726
719
|
" # Create agents\n",
|
|
727
|
-
"
|
|
728
|
-
"
|
|
720
|
+
" agents = MoneyAgent.create_agents(model=self, n=n)\n",
|
|
721
|
+
" # Create x and y coordinates for agents\n",
|
|
722
|
+
" x = self.rng.integers(0, self.grid.width, size=(n,))\n",
|
|
723
|
+
" y = self.rng.integers(0, self.grid.height, size=(n,))\n",
|
|
724
|
+
" for a, i, j in zip(agents, x, y):\n",
|
|
729
725
|
" # Add the agent to a random grid cell\n",
|
|
730
|
-
"
|
|
731
|
-
" y = self.random.randrange(self.grid.height)\n",
|
|
732
|
-
" self.grid.place_agent(a, (x, y))\n",
|
|
726
|
+
" self.grid.place_agent(a, (i, j))\n",
|
|
733
727
|
"\n",
|
|
734
728
|
" def step(self):\n",
|
|
735
729
|
" self.agents.shuffle_do(\"move\")\n",
|
|
@@ -852,7 +846,7 @@
|
|
|
852
846
|
" other = self.random.choice(cellmates)\n",
|
|
853
847
|
" other.wealth += 1\n",
|
|
854
848
|
" self.wealth -= 1\n",
|
|
855
|
-
"
|
|
849
|
+
"\n",
|
|
856
850
|
"\n",
|
|
857
851
|
"class MoneyModel(mesa.Model):\n",
|
|
858
852
|
" \"\"\"A model with some number of agents.\"\"\"\n",
|
|
@@ -868,12 +862,13 @@
|
|
|
868
862
|
" )\n",
|
|
869
863
|
"\n",
|
|
870
864
|
" # Create agents\n",
|
|
871
|
-
"
|
|
872
|
-
"
|
|
865
|
+
" agents = MoneyAgent.create_agents(model=self, n=n)\n",
|
|
866
|
+
" # Create x and y positions for agents\n",
|
|
867
|
+
" x = self.rng.integers(0, self.grid.width, size=(n,))\n",
|
|
868
|
+
" y = self.rng.integers(0, self.grid.height, size=(n,))\n",
|
|
869
|
+
" for a, i, j in zip(agents, x, y):\n",
|
|
873
870
|
" # Add the agent to a random grid cell\n",
|
|
874
|
-
"
|
|
875
|
-
" y = self.random.randrange(self.grid.height)\n",
|
|
876
|
-
" self.grid.place_agent(a, (x, y))\n",
|
|
871
|
+
" self.grid.place_agent(a, (i, j))\n",
|
|
877
872
|
"\n",
|
|
878
873
|
" def step(self):\n",
|
|
879
874
|
" self.datacollector.collect(self)\n",
|
|
@@ -1137,12 +1132,13 @@
|
|
|
1137
1132
|
" self.grid = mesa.space.MultiGrid(width, height, True)\n",
|
|
1138
1133
|
"\n",
|
|
1139
1134
|
" # Create agents\n",
|
|
1140
|
-
"
|
|
1141
|
-
"
|
|
1135
|
+
" agents = MoneyAgent.create_agents(model=self, n=n)\n",
|
|
1136
|
+
" # Create x and y positions for agents\n",
|
|
1137
|
+
" x = self.rng.integers(0, self.grid.width, size=(n,))\n",
|
|
1138
|
+
" y = self.rng.integers(0, self.grid.height, size=(n,))\n",
|
|
1139
|
+
" for a, i, j in zip(agents, x, y):\n",
|
|
1142
1140
|
" # Add the agent to a random grid cell\n",
|
|
1143
|
-
"
|
|
1144
|
-
" y = self.random.randrange(self.grid.height)\n",
|
|
1145
|
-
" self.grid.place_agent(a, (x, y))\n",
|
|
1141
|
+
" self.grid.place_agent(a, (i, j))\n",
|
|
1146
1142
|
"\n",
|
|
1147
1143
|
" self.datacollector = mesa.DataCollector(\n",
|
|
1148
1144
|
" model_reporters={\"Gini\": compute_gini}, agent_reporters={\"Wealth\": \"wealth\"}\n",
|
|
@@ -1234,8 +1230,7 @@
|
|
|
1234
1230
|
" self.num_agents = n\n",
|
|
1235
1231
|
"\n",
|
|
1236
1232
|
" # Create agents\n",
|
|
1237
|
-
"
|
|
1238
|
-
" a = MoneyAgent(self)\n",
|
|
1233
|
+
" MoneyAgent.create_agents(model=self, n=n)\n",
|
|
1239
1234
|
"\n",
|
|
1240
1235
|
" self.datacollector = mesa.DataCollector(\n",
|
|
1241
1236
|
" model_reporters={\"Gini\": compute_gini}, agent_reporters={\"Wealth\": \"wealth\"}\n",
|
|
@@ -1320,8 +1315,7 @@
|
|
|
1320
1315
|
" ethnicities = [\"Green\", \"Blue\", \"Mixed\"]\n",
|
|
1321
1316
|
"\n",
|
|
1322
1317
|
" # Create agents\n",
|
|
1323
|
-
"
|
|
1324
|
-
" a = MoneyAgent(self, self.random.choice(ethnicities))\n",
|
|
1318
|
+
" MoneyAgent.create_agents(model=self, n=n, ethnicity=self.random.choice(ethnicities))\n",
|
|
1325
1319
|
"\n",
|
|
1326
1320
|
" self.datacollector = mesa.DataCollector(\n",
|
|
1327
1321
|
" model_reporters={\"Gini\": compute_gini},\n",
|
|
@@ -1406,12 +1400,13 @@
|
|
|
1406
1400
|
" self.running = True\n",
|
|
1407
1401
|
"\n",
|
|
1408
1402
|
" # Create agents\n",
|
|
1409
|
-
"
|
|
1410
|
-
"
|
|
1403
|
+
" agents = MoneyAgent.create_agents(model=self, n=n)\n",
|
|
1404
|
+
" # Create x and y positions for agents\n",
|
|
1405
|
+
" x = self.rng.integers(0, self.grid.width, size=(n,))\n",
|
|
1406
|
+
" y = self.rng.integers(0, self.grid.height, size=(n,))\n",
|
|
1407
|
+
" for a, i, j in zip(agents, x, y):\n",
|
|
1411
1408
|
" # Add the agent to a random grid cell\n",
|
|
1412
|
-
"
|
|
1413
|
-
" y = self.random.randrange(self.grid.height)\n",
|
|
1414
|
-
" self.grid.place_agent(a, (x, y))\n",
|
|
1409
|
+
" self.grid.place_agent(a, (i, j))\n",
|
|
1415
1410
|
"\n",
|
|
1416
1411
|
" self.datacollector = mesa.DataCollector(\n",
|
|
1417
1412
|
" model_reporters={\"Gini\": compute_gini},\n",
|
|
@@ -1902,7 +1897,7 @@
|
|
|
1902
1897
|
"name": "python",
|
|
1903
1898
|
"nbconvert_exporter": "python",
|
|
1904
1899
|
"pygments_lexer": "ipython3",
|
|
1905
|
-
"version": "3.12.
|
|
1900
|
+
"version": "3.12.3"
|
|
1906
1901
|
},
|
|
1907
1902
|
"widgets": {
|
|
1908
1903
|
"state": {},
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
{
|
|
4
4
|
"cell_type": "markdown",
|
|
5
5
|
"metadata": {},
|
|
6
|
-
"source":
|
|
6
|
+
"source": [
|
|
7
|
+
"# Visualization Tutorial"
|
|
8
|
+
]
|
|
7
9
|
},
|
|
8
10
|
{
|
|
9
11
|
"cell_type": "markdown",
|
|
@@ -51,10 +53,10 @@
|
|
|
51
53
|
]
|
|
52
54
|
},
|
|
53
55
|
{
|
|
54
|
-
"metadata": {},
|
|
55
56
|
"cell_type": "code",
|
|
56
|
-
"outputs": [],
|
|
57
57
|
"execution_count": null,
|
|
58
|
+
"metadata": {},
|
|
59
|
+
"outputs": [],
|
|
58
60
|
"source": [
|
|
59
61
|
"import mesa\n",
|
|
60
62
|
"print(f\"Mesa version: {mesa.__version__}\")\n",
|
|
@@ -66,10 +68,10 @@
|
|
|
66
68
|
]
|
|
67
69
|
},
|
|
68
70
|
{
|
|
69
|
-
"metadata": {},
|
|
70
71
|
"cell_type": "code",
|
|
71
|
-
"outputs": [],
|
|
72
72
|
"execution_count": null,
|
|
73
|
+
"metadata": {},
|
|
74
|
+
"outputs": [],
|
|
73
75
|
"source": [
|
|
74
76
|
"def agent_portrayal(agent):\n",
|
|
75
77
|
" return {\n",
|
|
@@ -79,15 +81,17 @@
|
|
|
79
81
|
]
|
|
80
82
|
},
|
|
81
83
|
{
|
|
82
|
-
"metadata": {},
|
|
83
84
|
"cell_type": "markdown",
|
|
84
|
-
"
|
|
85
|
+
"metadata": {},
|
|
86
|
+
"source": [
|
|
87
|
+
"In addition to the portrayal method, we instantiate the model parameters, some of which are modifiable by user inputs. In this case, the number of agents, N, is specified as a slider of integers."
|
|
88
|
+
]
|
|
85
89
|
},
|
|
86
90
|
{
|
|
87
|
-
"metadata": {},
|
|
88
91
|
"cell_type": "code",
|
|
89
|
-
"outputs": [],
|
|
90
92
|
"execution_count": null,
|
|
93
|
+
"metadata": {},
|
|
94
|
+
"outputs": [],
|
|
91
95
|
"source": [
|
|
92
96
|
"model_params = {\n",
|
|
93
97
|
" \"n\": {\n",
|
|
@@ -104,8 +108,8 @@
|
|
|
104
108
|
]
|
|
105
109
|
},
|
|
106
110
|
{
|
|
107
|
-
"metadata": {},
|
|
108
111
|
"cell_type": "markdown",
|
|
112
|
+
"metadata": {},
|
|
109
113
|
"source": [
|
|
110
114
|
"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",
|
|
111
115
|
"\n",
|
|
@@ -118,13 +122,13 @@
|
|
|
118
122
|
]
|
|
119
123
|
},
|
|
120
124
|
{
|
|
121
|
-
"metadata": {},
|
|
122
125
|
"cell_type": "code",
|
|
123
|
-
"outputs": [],
|
|
124
126
|
"execution_count": null,
|
|
127
|
+
"metadata": {},
|
|
128
|
+
"outputs": [],
|
|
125
129
|
"source": [
|
|
126
130
|
"# Create initial model instance\n",
|
|
127
|
-
"model1 = MoneyModel(50, 10, 10)\n",
|
|
131
|
+
"model1 = MoneyModel(n=50, width=10, height=10) #keyword arguments\n",
|
|
128
132
|
"\n",
|
|
129
133
|
"SpaceGraph = make_space_component(agent_portrayal)\n",
|
|
130
134
|
"GiniPlot = make_plot_component(\"Gini\")\n",
|
|
@@ -140,8 +144,8 @@
|
|
|
140
144
|
]
|
|
141
145
|
},
|
|
142
146
|
{
|
|
143
|
-
"metadata": {},
|
|
144
147
|
"cell_type": "markdown",
|
|
148
|
+
"metadata": {},
|
|
145
149
|
"source": [
|
|
146
150
|
"## Part 2 - Dynamic Agent Representation \n",
|
|
147
151
|
"\n",
|
|
@@ -155,10 +159,10 @@
|
|
|
155
159
|
]
|
|
156
160
|
},
|
|
157
161
|
{
|
|
158
|
-
"metadata": {},
|
|
159
162
|
"cell_type": "code",
|
|
160
|
-
"outputs": [],
|
|
161
163
|
"execution_count": null,
|
|
164
|
+
"metadata": {},
|
|
165
|
+
"outputs": [],
|
|
162
166
|
"source": [
|
|
163
167
|
"import mesa\n",
|
|
164
168
|
"print(f\"Mesa version: {mesa.__version__}\")\n",
|
|
@@ -169,10 +173,10 @@
|
|
|
169
173
|
]
|
|
170
174
|
},
|
|
171
175
|
{
|
|
172
|
-
"metadata": {},
|
|
173
176
|
"cell_type": "code",
|
|
174
|
-
"outputs": [],
|
|
175
177
|
"execution_count": null,
|
|
178
|
+
"metadata": {},
|
|
179
|
+
"outputs": [],
|
|
176
180
|
"source": [
|
|
177
181
|
"def agent_portrayal(agent):\n",
|
|
178
182
|
" size = 10\n",
|
|
@@ -197,13 +201,13 @@
|
|
|
197
201
|
]
|
|
198
202
|
},
|
|
199
203
|
{
|
|
200
|
-
"metadata": {},
|
|
201
204
|
"cell_type": "code",
|
|
202
|
-
"outputs": [],
|
|
203
205
|
"execution_count": null,
|
|
206
|
+
"metadata": {},
|
|
207
|
+
"outputs": [],
|
|
204
208
|
"source": [
|
|
205
209
|
"# Create initial model instance\n",
|
|
206
|
-
"
|
|
210
|
+
"model = MoneyModel(n=50, width=10, height=10)\n",
|
|
207
211
|
"\n",
|
|
208
212
|
"SpaceGraph = make_space_component(agent_portrayal)\n",
|
|
209
213
|
"GiniPlot = make_plot_component(\"Gini\")\n",
|
|
@@ -219,8 +223,8 @@
|
|
|
219
223
|
]
|
|
220
224
|
},
|
|
221
225
|
{
|
|
222
|
-
"metadata": {},
|
|
223
226
|
"cell_type": "markdown",
|
|
227
|
+
"metadata": {},
|
|
224
228
|
"source": [
|
|
225
229
|
"## Part 3 - Custom Components \n",
|
|
226
230
|
"\n",
|
|
@@ -236,10 +240,10 @@
|
|
|
236
240
|
]
|
|
237
241
|
},
|
|
238
242
|
{
|
|
239
|
-
"metadata": {},
|
|
240
243
|
"cell_type": "code",
|
|
241
|
-
"outputs": [],
|
|
242
244
|
"execution_count": null,
|
|
245
|
+
"metadata": {},
|
|
246
|
+
"outputs": [],
|
|
243
247
|
"source": [
|
|
244
248
|
"import mesa\n",
|
|
245
249
|
"print(f\"Mesa version: {mesa.__version__}\")\n",
|
|
@@ -253,10 +257,10 @@
|
|
|
253
257
|
]
|
|
254
258
|
},
|
|
255
259
|
{
|
|
256
|
-
"metadata": {},
|
|
257
260
|
"cell_type": "code",
|
|
258
|
-
"outputs": [],
|
|
259
261
|
"execution_count": null,
|
|
262
|
+
"metadata": {},
|
|
263
|
+
"outputs": [],
|
|
260
264
|
"source": [
|
|
261
265
|
"def agent_portrayal(agent):\n",
|
|
262
266
|
" size = 10\n",
|
|
@@ -281,15 +285,17 @@
|
|
|
281
285
|
]
|
|
282
286
|
},
|
|
283
287
|
{
|
|
284
|
-
"metadata": {},
|
|
285
288
|
"cell_type": "markdown",
|
|
286
|
-
"
|
|
289
|
+
"metadata": {},
|
|
290
|
+
"source": [
|
|
291
|
+
"Next, we update our solara frontend to use this new component"
|
|
292
|
+
]
|
|
287
293
|
},
|
|
288
294
|
{
|
|
289
|
-
"metadata": {},
|
|
290
295
|
"cell_type": "code",
|
|
291
|
-
"outputs": [],
|
|
292
296
|
"execution_count": null,
|
|
297
|
+
"metadata": {},
|
|
298
|
+
"outputs": [],
|
|
293
299
|
"source": [
|
|
294
300
|
"@solara.component\n",
|
|
295
301
|
"def Histogram(model):\n",
|
|
@@ -306,13 +312,13 @@
|
|
|
306
312
|
]
|
|
307
313
|
},
|
|
308
314
|
{
|
|
309
|
-
"metadata": {},
|
|
310
315
|
"cell_type": "code",
|
|
311
|
-
"outputs": [],
|
|
312
316
|
"execution_count": null,
|
|
317
|
+
"metadata": {},
|
|
318
|
+
"outputs": [],
|
|
313
319
|
"source": [
|
|
314
320
|
"# Create initial model instance\n",
|
|
315
|
-
"
|
|
321
|
+
"model = MoneyModel(n=50, width=10, height=10)\n",
|
|
316
322
|
"\n",
|
|
317
323
|
"SpaceGraph = make_space_component(agent_portrayal)\n",
|
|
318
324
|
"GiniPlot = make_plot_component(\"Gini\")"
|
|
@@ -320,42 +326,42 @@
|
|
|
320
326
|
},
|
|
321
327
|
{
|
|
322
328
|
"cell_type": "code",
|
|
329
|
+
"execution_count": 12,
|
|
323
330
|
"metadata": {
|
|
324
331
|
"ExecuteTime": {
|
|
325
332
|
"end_time": "2024-10-29T19:38:49.471838Z",
|
|
326
333
|
"start_time": "2024-10-29T19:38:47.897295Z"
|
|
327
334
|
}
|
|
328
335
|
},
|
|
329
|
-
"source": [
|
|
330
|
-
"page = SolaraViz(\n",
|
|
331
|
-
" model1,\n",
|
|
332
|
-
" components=[SpaceGraph, GiniPlot, Histogram],\n",
|
|
333
|
-
" model_params=model_params,\n",
|
|
334
|
-
" name=\"Boltzmann Wealth Model\",\n",
|
|
335
|
-
")\n",
|
|
336
|
-
"# This is required to render the visualization in the Jupyter notebook\n",
|
|
337
|
-
"page"
|
|
338
|
-
],
|
|
339
336
|
"outputs": [
|
|
340
337
|
{
|
|
341
338
|
"data": {
|
|
342
|
-
"
|
|
343
|
-
"
|
|
344
|
-
|
|
339
|
+
"application/vnd.jupyter.widget-view+json": {
|
|
340
|
+
"model_id": "bc71b89ee5684038a194eee4c36f4a4c",
|
|
341
|
+
"version_major": 2,
|
|
342
|
+
"version_minor": 0
|
|
343
|
+
},
|
|
345
344
|
"text/html": [
|
|
346
345
|
"Cannot show widget. You probably want to rerun the code cell above (<i>Click in the code cell, and press Shift+Enter <kbd>⇧</kbd>+<kbd>↩</kbd></i>)."
|
|
347
346
|
],
|
|
348
|
-
"
|
|
349
|
-
"
|
|
350
|
-
|
|
351
|
-
"model_id": "bc71b89ee5684038a194eee4c36f4a4c"
|
|
352
|
-
}
|
|
347
|
+
"text/plain": [
|
|
348
|
+
"Cannot show ipywidgets in text"
|
|
349
|
+
]
|
|
353
350
|
},
|
|
354
351
|
"metadata": {},
|
|
355
352
|
"output_type": "display_data"
|
|
356
353
|
}
|
|
357
354
|
],
|
|
358
|
-
"
|
|
355
|
+
"source": [
|
|
356
|
+
"page = SolaraViz(\n",
|
|
357
|
+
" model,\n",
|
|
358
|
+
" components=[SpaceGraph, GiniPlot, Histogram],\n",
|
|
359
|
+
" model_params=model_params,\n",
|
|
360
|
+
" name=\"Boltzmann Wealth Model\",\n",
|
|
361
|
+
")\n",
|
|
362
|
+
"# This is required to render the visualization in the Jupyter notebook\n",
|
|
363
|
+
"page"
|
|
364
|
+
]
|
|
359
365
|
},
|
|
360
366
|
{
|
|
361
367
|
"cell_type": "markdown",
|
|
@@ -366,35 +372,35 @@
|
|
|
366
372
|
},
|
|
367
373
|
{
|
|
368
374
|
"cell_type": "code",
|
|
375
|
+
"execution_count": 13,
|
|
369
376
|
"metadata": {
|
|
370
377
|
"ExecuteTime": {
|
|
371
378
|
"end_time": "2024-10-29T19:38:49.505725Z",
|
|
372
379
|
"start_time": "2024-10-29T19:38:49.472599Z"
|
|
373
380
|
}
|
|
374
381
|
},
|
|
375
|
-
"source": [
|
|
376
|
-
"Histogram(model1)"
|
|
377
|
-
],
|
|
378
382
|
"outputs": [
|
|
379
383
|
{
|
|
380
384
|
"data": {
|
|
381
|
-
"
|
|
382
|
-
"
|
|
383
|
-
|
|
385
|
+
"application/vnd.jupyter.widget-view+json": {
|
|
386
|
+
"model_id": "0491f167a1434a92b78535078bd082a8",
|
|
387
|
+
"version_major": 2,
|
|
388
|
+
"version_minor": 0
|
|
389
|
+
},
|
|
384
390
|
"text/html": [
|
|
385
391
|
"Cannot show widget. You probably want to rerun the code cell above (<i>Click in the code cell, and press Shift+Enter <kbd>⇧</kbd>+<kbd>↩</kbd></i>)."
|
|
386
392
|
],
|
|
387
|
-
"
|
|
388
|
-
"
|
|
389
|
-
|
|
390
|
-
"model_id": "0491f167a1434a92b78535078bd082a8"
|
|
391
|
-
}
|
|
393
|
+
"text/plain": [
|
|
394
|
+
"Cannot show ipywidgets in text"
|
|
395
|
+
]
|
|
392
396
|
},
|
|
393
397
|
"metadata": {},
|
|
394
398
|
"output_type": "display_data"
|
|
395
399
|
}
|
|
396
400
|
],
|
|
397
|
-
"
|
|
401
|
+
"source": [
|
|
402
|
+
"Histogram(model)"
|
|
403
|
+
]
|
|
398
404
|
},
|
|
399
405
|
{
|
|
400
406
|
"cell_type": "markdown",
|
|
@@ -4,7 +4,7 @@ from mesa.experimental.cell_space import CellAgent
|
|
|
4
4
|
class PDAgent(CellAgent):
|
|
5
5
|
"""Agent member of the iterated, spatial prisoner's dilemma model."""
|
|
6
6
|
|
|
7
|
-
def __init__(self, model, starting_move=None):
|
|
7
|
+
def __init__(self, model, starting_move=None, cell=None):
|
|
8
8
|
"""
|
|
9
9
|
Create a new Prisoner's Dilemma agent.
|
|
10
10
|
|
|
@@ -15,6 +15,7 @@ class PDAgent(CellAgent):
|
|
|
15
15
|
"""
|
|
16
16
|
super().__init__(model)
|
|
17
17
|
self.score = 0
|
|
18
|
+
self.cell = cell
|
|
18
19
|
if starting_move:
|
|
19
20
|
self.move = starting_move
|
|
20
21
|
else:
|
|
@@ -32,11 +32,9 @@ class PdGrid(mesa.Model):
|
|
|
32
32
|
if payoffs is not None:
|
|
33
33
|
self.payoff = payoffs
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
agent = PDAgent(self)
|
|
39
|
-
agent.cell = self.grid[(x, y)]
|
|
35
|
+
PDAgent.create_agents(
|
|
36
|
+
self, len(self.grid.all_cells.cells), cell=self.grid.all_cells.cells
|
|
37
|
+
)
|
|
40
38
|
|
|
41
39
|
self.datacollector = mesa.DataCollector(
|
|
42
40
|
{
|