Mesa 3.1.3__tar.gz → 3.1.4__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.

Files changed (190) hide show
  1. {mesa-3.1.3 → mesa-3.1.4}/.github/workflows/benchmarks.yml +3 -1
  2. {mesa-3.1.3 → mesa-3.1.4}/.pre-commit-config.yaml +2 -2
  3. {mesa-3.1.3 → mesa-3.1.4}/HISTORY.md +38 -0
  4. {mesa-3.1.3 → mesa-3.1.4}/PKG-INFO +13 -10
  5. {mesa-3.1.3 → mesa-3.1.4}/README.md +4 -9
  6. {mesa-3.1.3 → mesa-3.1.4}/binder/environment.yml +2 -2
  7. {mesa-3.1.3 → mesa-3.1.4}/docs/README.md +2 -1
  8. {mesa-3.1.3 → mesa-3.1.4}/docs/apis/visualization.md +8 -0
  9. {mesa-3.1.3 → mesa-3.1.4}/docs/conf.py +1 -0
  10. {mesa-3.1.3 → mesa-3.1.4}/docs/getting_started.md +3 -5
  11. {mesa-3.1.3 → mesa-3.1.4}/docs/index.md +4 -9
  12. mesa-3.1.4/docs/mesa_extension.md +97 -0
  13. {mesa-3.1.3 → mesa-3.1.4}/docs/tutorials/intro_tutorial.ipynb +5 -11
  14. {mesa-3.1.3 → mesa-3.1.4}/docs/tutorials/visualization_tutorial.ipynb +1 -3
  15. {mesa-3.1.3 → mesa-3.1.4}/mesa/__init__.py +1 -1
  16. {mesa-3.1.3 → mesa-3.1.4}/mesa/datacollection.py +62 -2
  17. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/sugarscape_g1mt/app.py +15 -37
  18. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/cell_space/grid.py +8 -8
  19. {mesa-3.1.3 → mesa-3.1.4}/mesa/visualization/__init__.py +1 -2
  20. {mesa-3.1.3 → mesa-3.1.4}/mesa/visualization/components/altair_components.py +10 -8
  21. {mesa-3.1.3 → mesa-3.1.4}/mesa/visualization/mpl_space_drawing.py +139 -90
  22. {mesa-3.1.3 → mesa-3.1.4}/mesa/visualization/solara_viz.py +5 -1
  23. {mesa-3.1.3 → mesa-3.1.4}/pyproject.toml +2 -3
  24. {mesa-3.1.3 → mesa-3.1.4}/tests/test_agent.py +3 -3
  25. {mesa-3.1.3 → mesa-3.1.4}/tests/test_cell_space.py +17 -17
  26. {mesa-3.1.3 → mesa-3.1.4}/tests/test_datacollector.py +62 -0
  27. {mesa-3.1.3 → mesa-3.1.4}/tests/test_solara_viz.py +39 -6
  28. {mesa-3.1.3 → mesa-3.1.4}/.codespellignore +0 -0
  29. {mesa-3.1.3 → mesa-3.1.4}/.coveragerc +0 -0
  30. {mesa-3.1.3 → mesa-3.1.4}/.github/ISSUE_TEMPLATE/bug-report.md +0 -0
  31. {mesa-3.1.3 → mesa-3.1.4}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  32. {mesa-3.1.3 → mesa-3.1.4}/.github/ISSUE_TEMPLATE/feature-request.md +0 -0
  33. {mesa-3.1.3 → mesa-3.1.4}/.github/PULL_REQUEST_TEMPLATE/bug.md +0 -0
  34. {mesa-3.1.3 → mesa-3.1.4}/.github/PULL_REQUEST_TEMPLATE/feature.md +0 -0
  35. {mesa-3.1.3 → mesa-3.1.4}/.github/dependabot.yml +0 -0
  36. {mesa-3.1.3 → mesa-3.1.4}/.github/pull_request_template.md +0 -0
  37. {mesa-3.1.3 → mesa-3.1.4}/.github/release.yml +0 -0
  38. {mesa-3.1.3 → mesa-3.1.4}/.github/workflows/build_lint.yml +0 -0
  39. {mesa-3.1.3 → mesa-3.1.4}/.github/workflows/release.yml +0 -0
  40. {mesa-3.1.3 → mesa-3.1.4}/.gitignore +0 -0
  41. {mesa-3.1.3 → mesa-3.1.4}/.readthedocs.yml +0 -0
  42. {mesa-3.1.3 → mesa-3.1.4}/CITATION.bib +0 -0
  43. {mesa-3.1.3 → mesa-3.1.4}/CODE_OF_CONDUCT.md +0 -0
  44. {mesa-3.1.3 → mesa-3.1.4}/CONTRIBUTING.md +0 -0
  45. {mesa-3.1.3 → mesa-3.1.4}/Dockerfile +0 -0
  46. {mesa-3.1.3 → mesa-3.1.4}/LICENSE +0 -0
  47. {mesa-3.1.3 → mesa-3.1.4}/NOTICE +0 -0
  48. {mesa-3.1.3 → mesa-3.1.4}/benchmarks/compare_timings.py +0 -0
  49. {mesa-3.1.3 → mesa-3.1.4}/benchmarks/configurations.py +0 -0
  50. {mesa-3.1.3 → mesa-3.1.4}/benchmarks/global_benchmark.py +0 -0
  51. {mesa-3.1.3 → mesa-3.1.4}/codecov.yaml +0 -0
  52. {mesa-3.1.3 → mesa-3.1.4}/docker-compose.yml +0 -0
  53. {mesa-3.1.3 → mesa-3.1.4}/docs/Makefile +0 -0
  54. {mesa-3.1.3 → mesa-3.1.4}/docs/_static/switcher.json +0 -0
  55. {mesa-3.1.3 → mesa-3.1.4}/docs/apis/agent.md +0 -0
  56. {mesa-3.1.3 → mesa-3.1.4}/docs/apis/api_main.md +0 -0
  57. {mesa-3.1.3 → mesa-3.1.4}/docs/apis/batchrunner.md +0 -0
  58. {mesa-3.1.3 → mesa-3.1.4}/docs/apis/datacollection.md +0 -0
  59. {mesa-3.1.3 → mesa-3.1.4}/docs/apis/experimental.md +0 -0
  60. {mesa-3.1.3 → mesa-3.1.4}/docs/apis/mesa_logging.md +0 -0
  61. {mesa-3.1.3 → mesa-3.1.4}/docs/apis/model.md +0 -0
  62. {mesa-3.1.3 → mesa-3.1.4}/docs/apis/space.md +0 -0
  63. {mesa-3.1.3 → mesa-3.1.4}/docs/best-practices.md +0 -0
  64. {mesa-3.1.3 → mesa-3.1.4}/docs/example_template.txt +0 -0
  65. {mesa-3.1.3 → mesa-3.1.4}/docs/examples_overview_template.txt +0 -0
  66. {mesa-3.1.3 → mesa-3.1.4}/docs/images/mesa_logo.ico +0 -0
  67. {mesa-3.1.3 → mesa-3.1.4}/docs/images/mesa_logo.png +0 -0
  68. {mesa-3.1.3 → mesa-3.1.4}/docs/images/tutorial/br_ginis.png +0 -0
  69. {mesa-3.1.3 → mesa-3.1.4}/docs/images/tutorial/dc_endwealth.png +0 -0
  70. {mesa-3.1.3 → mesa-3.1.4}/docs/images/tutorial/dc_gini.png +0 -0
  71. {mesa-3.1.3 → mesa-3.1.4}/docs/images/tutorial/dc_oneagent.png +0 -0
  72. {mesa-3.1.3 → mesa-3.1.4}/docs/images/tutorial/first_hist.png +0 -0
  73. {mesa-3.1.3 → mesa-3.1.4}/docs/images/tutorial/multirun_hist.png +0 -0
  74. {mesa-3.1.3 → mesa-3.1.4}/docs/images/tutorial/numpy_grid.png +0 -0
  75. {mesa-3.1.3 → mesa-3.1.4}/docs/images/tutorial/viz_chart.png +0 -0
  76. {mesa-3.1.3 → mesa-3.1.4}/docs/images/tutorial/viz_empty.png +0 -0
  77. {mesa-3.1.3 → mesa-3.1.4}/docs/images/tutorial/viz_greycircles.png +0 -0
  78. {mesa-3.1.3 → mesa-3.1.4}/docs/images/tutorial/viz_histogram.png +0 -0
  79. {mesa-3.1.3 → mesa-3.1.4}/docs/images/tutorial/viz_redcircles.png +0 -0
  80. {mesa-3.1.3 → mesa-3.1.4}/docs/images/wolf_sheep.png +0 -0
  81. {mesa-3.1.3 → mesa-3.1.4}/docs/make.bat +0 -0
  82. {mesa-3.1.3 → mesa-3.1.4}/docs/mesa.md +0 -0
  83. {mesa-3.1.3 → mesa-3.1.4}/docs/migration_guide.md +0 -0
  84. {mesa-3.1.3 → mesa-3.1.4}/docs/tutorials/MoneyModel.py +0 -0
  85. {mesa-3.1.3 → mesa-3.1.4}/docs/tutorials/files/viz_chart.png +0 -0
  86. {mesa-3.1.3 → mesa-3.1.4}/docs/tutorials/files/viz_empty.png +0 -0
  87. {mesa-3.1.3 → mesa-3.1.4}/docs/tutorials/files/viz_greycircles.png +0 -0
  88. {mesa-3.1.3 → mesa-3.1.4}/docs/tutorials/files/viz_histogram.png +0 -0
  89. {mesa-3.1.3 → mesa-3.1.4}/docs/tutorials/files/viz_redcircles.png +0 -0
  90. {mesa-3.1.3 → mesa-3.1.4}/docs/tutorials/files/viz_slider.png +0 -0
  91. {mesa-3.1.3 → mesa-3.1.4}/maintenance/fetch_unlabeled_prs.py +0 -0
  92. {mesa-3.1.3 → mesa-3.1.4}/mesa/agent.py +0 -0
  93. {mesa-3.1.3 → mesa-3.1.4}/mesa/batchrunner.py +0 -0
  94. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/README.md +0 -0
  95. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/__init__.py +0 -0
  96. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/__init__.py +0 -0
  97. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/epstein_civil_violence/Epstein Civil Violence.ipynb +0 -0
  98. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/epstein_civil_violence/Readme.md +0 -0
  99. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/epstein_civil_violence/__init__.py +0 -0
  100. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/epstein_civil_violence/agents.py +0 -0
  101. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/epstein_civil_violence/app.py +0 -0
  102. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/epstein_civil_violence/model.py +0 -0
  103. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/pd_grid/Readme.md +0 -0
  104. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/pd_grid/__init__.py +0 -0
  105. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/pd_grid/agents.py +0 -0
  106. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/pd_grid/analysis.ipynb +0 -0
  107. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/pd_grid/app.py +0 -0
  108. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/pd_grid/model.py +0 -0
  109. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/sugarscape_g1mt/Readme.md +0 -0
  110. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/sugarscape_g1mt/__init__.py +0 -0
  111. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/sugarscape_g1mt/agents.py +0 -0
  112. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/sugarscape_g1mt/model.py +0 -0
  113. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/sugarscape_g1mt/sugar-map.txt +0 -0
  114. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/sugarscape_g1mt/tests.py +0 -0
  115. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/wolf_sheep/Readme.md +0 -0
  116. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/wolf_sheep/__init__.py +0 -0
  117. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/wolf_sheep/agents.py +0 -0
  118. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/wolf_sheep/app.py +0 -0
  119. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/advanced/wolf_sheep/model.py +0 -0
  120. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/__init__.py +0 -0
  121. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/boid_flockers/Readme.md +0 -0
  122. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/boid_flockers/__init__.py +0 -0
  123. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/boid_flockers/agents.py +0 -0
  124. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/boid_flockers/app.py +0 -0
  125. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/boid_flockers/model.py +0 -0
  126. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/boltzmann_wealth_model/Readme.md +0 -0
  127. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/boltzmann_wealth_model/__init__.py +0 -0
  128. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/boltzmann_wealth_model/agents.py +0 -0
  129. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/boltzmann_wealth_model/app.py +0 -0
  130. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/boltzmann_wealth_model/model.py +0 -0
  131. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/boltzmann_wealth_model/st_app.py +0 -0
  132. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/conways_game_of_life/Readme.md +0 -0
  133. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/conways_game_of_life/__init__.py +0 -0
  134. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/conways_game_of_life/agents.py +0 -0
  135. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/conways_game_of_life/app.py +0 -0
  136. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/conways_game_of_life/model.py +0 -0
  137. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/conways_game_of_life/st_app.py +0 -0
  138. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/schelling/Readme.md +0 -0
  139. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/schelling/__init__.py +0 -0
  140. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/schelling/agents.py +0 -0
  141. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/schelling/analysis.ipynb +0 -0
  142. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/schelling/app.py +0 -0
  143. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/schelling/model.py +0 -0
  144. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/virus_on_network/Readme.md +0 -0
  145. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/virus_on_network/__init__.py +0 -0
  146. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/virus_on_network/agents.py +0 -0
  147. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/virus_on_network/app.py +0 -0
  148. {mesa-3.1.3 → mesa-3.1.4}/mesa/examples/basic/virus_on_network/model.py +0 -0
  149. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/__init__.py +0 -0
  150. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/cell_space/__init__.py +0 -0
  151. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/cell_space/cell.py +0 -0
  152. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/cell_space/cell_agent.py +0 -0
  153. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/cell_space/cell_collection.py +0 -0
  154. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/cell_space/discrete_space.py +0 -0
  155. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/cell_space/network.py +0 -0
  156. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/cell_space/property_layer.py +0 -0
  157. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/cell_space/voronoi.py +0 -0
  158. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/continuous_space/__init__.py +0 -0
  159. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/continuous_space/continuous_space.py +0 -0
  160. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/continuous_space/continuous_space_agents.py +0 -0
  161. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/devs/__init__.py +0 -0
  162. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/devs/eventlist.py +0 -0
  163. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/devs/simulator.py +0 -0
  164. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/mesa_signals/__init__.py +0 -0
  165. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/mesa_signals/mesa_signal.py +0 -0
  166. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/mesa_signals/observable_collections.py +0 -0
  167. {mesa-3.1.3 → mesa-3.1.4}/mesa/experimental/mesa_signals/signals_util.py +0 -0
  168. {mesa-3.1.3 → mesa-3.1.4}/mesa/mesa_logging.py +0 -0
  169. {mesa-3.1.3 → mesa-3.1.4}/mesa/model.py +0 -0
  170. {mesa-3.1.3 → mesa-3.1.4}/mesa/space.py +0 -0
  171. {mesa-3.1.3 → mesa-3.1.4}/mesa/visualization/components/__init__.py +0 -0
  172. {mesa-3.1.3 → mesa-3.1.4}/mesa/visualization/components/matplotlib_components.py +0 -0
  173. {mesa-3.1.3 → mesa-3.1.4}/mesa/visualization/user_param.py +0 -0
  174. {mesa-3.1.3 → mesa-3.1.4}/mesa/visualization/utils.py +0 -0
  175. {mesa-3.1.3 → mesa-3.1.4}/mypy.ini +0 -0
  176. {mesa-3.1.3 → mesa-3.1.4}/tests/__init__.py +0 -0
  177. {mesa-3.1.3 → mesa-3.1.4}/tests/read_requirements.py +0 -0
  178. {mesa-3.1.3 → mesa-3.1.4}/tests/test_batch_run.py +0 -0
  179. {mesa-3.1.3 → mesa-3.1.4}/tests/test_components_matplotlib.py +0 -0
  180. {mesa-3.1.3 → mesa-3.1.4}/tests/test_continuous_space.py +0 -0
  181. {mesa-3.1.3 → mesa-3.1.4}/tests/test_devs.py +0 -0
  182. {mesa-3.1.3 → mesa-3.1.4}/tests/test_end_to_end_viz.sh +0 -0
  183. {mesa-3.1.3 → mesa-3.1.4}/tests/test_examples.py +0 -0
  184. {mesa-3.1.3 → mesa-3.1.4}/tests/test_grid.py +0 -0
  185. {mesa-3.1.3 → mesa-3.1.4}/tests/test_import_namespace.py +0 -0
  186. {mesa-3.1.3 → mesa-3.1.4}/tests/test_lifespan.py +0 -0
  187. {mesa-3.1.3 → mesa-3.1.4}/tests/test_mesa_logging.py +0 -0
  188. {mesa-3.1.3 → mesa-3.1.4}/tests/test_mesa_signals.py +0 -0
  189. {mesa-3.1.3 → mesa-3.1.4}/tests/test_model.py +0 -0
  190. {mesa-3.1.3 → mesa-3.1.4}/tests/test_space.py +0 -0
@@ -28,8 +28,10 @@ jobs:
28
28
  python-version: '3.13'
29
29
  - name: Add project directory to PYTHONPATH
30
30
  run: echo "PYTHONPATH=$PYTHONPATH:$(pwd)" >> $GITHUB_ENV
31
+ - name: Install uv
32
+ run: pip install uv
31
33
  - name: Install dependencies
32
- run: pip install numpy pandas tqdm tabulate matplotlib solara networkx
34
+ run: uv pip install --system numpy pandas tqdm tabulate matplotlib solara networkx scipy
33
35
  # Benchmarks on the projectmesa main branch
34
36
  - name: Checkout main branch
35
37
  uses: actions/checkout@v4
@@ -4,7 +4,7 @@ ci:
4
4
  repos:
5
5
  - repo: https://github.com/astral-sh/ruff-pre-commit
6
6
  # Ruff version.
7
- rev: v0.8.6
7
+ rev: v0.9.4
8
8
  hooks:
9
9
  # Run the linter.
10
10
  - id: ruff
@@ -25,7 +25,7 @@ repos:
25
25
  - id: check-toml
26
26
  - id: check-yaml
27
27
  - repo: https://github.com/codespell-project/codespell
28
- rev: v2.3.0
28
+ rev: v2.4.1
29
29
  hooks:
30
30
  - id: codespell
31
31
  args: [
@@ -1,6 +1,44 @@
1
1
  ---
2
2
  title: Release History
3
3
  ---
4
+ # 3.1.4 (2025-02-09)
5
+ ## Highlights
6
+ This release contains various improvements and bugfixes to the matplotlib-based visualization of spaces. Hexgrids are now fully supported, including property layers. In making this possible, various minor bugs were encountered and also fixed. In addition to the visualization improvements, there are various minor convenience improvements to the docs.
7
+
8
+
9
+ ## What's Changed
10
+ ### 🛠 Enhancements made
11
+ * Fixed hex-space draw function to avoid overlaps by @Sahil-Chhoker in https://github.com/projectmesa/mesa/pull/2609
12
+ * Fix: Property layer visualization for HexGrid by @Sahil-Chhoker in https://github.com/projectmesa/mesa/pull/2646
13
+ * Enhance DataCollector to validate model_reporters functions by @peter-kinger in https://github.com/projectmesa/mesa/pull/2605
14
+ * Implemented post_process in Altair based components by @sanika-n in https://github.com/projectmesa/mesa/pull/2641
15
+ ### 🐛 Bugs fixed
16
+ * bugfix for draw_property_layer by @quaquel in https://github.com/projectmesa/mesa/pull/2639
17
+ * Uses array for hex grid property layer fix by @Sahil-Chhoker in https://github.com/projectmesa/mesa/pull/2651
18
+ * Update Binder environment to use latest Mesa version (#2652) by @aarav-shukla07 in https://github.com/projectmesa/mesa/pull/2655
19
+ * Change Hexgrid._connect_cells_2d to use x,y coordinates by @quaquel in https://github.com/projectmesa/mesa/pull/2632
20
+ ### 🔍 Examples updated
21
+ * Added property layer viz to sugarscape by @sanika-n in https://github.com/projectmesa/mesa/pull/2653
22
+ * added color-bar for spice by @sanika-n in https://github.com/projectmesa/mesa/pull/2622
23
+ ### 📜 Documentation improvements
24
+ * remove any reference to using --pre by @quaquel in https://github.com/projectmesa/mesa/pull/2618
25
+ * Updated Docs by @sanika-n in https://github.com/projectmesa/mesa/pull/2624
26
+ * Fixed 404 error for Examples Tab in Introductory Tutorial (#2662) by @aarav-shukla07 in https://github.com/projectmesa/mesa/pull/2664
27
+ * Documentation by @Spartan-71 in https://github.com/projectmesa/mesa/pull/2630
28
+ * Adding a copy option at the top of the code written in the docs by @PrashantChoudhary13579 in https://github.com/projectmesa/mesa/pull/2628
29
+ * Adding Mesa Extension page by @PrashantChoudhary13579 in https://github.com/projectmesa/mesa/pull/2627
30
+ ### 🔧 Maintenance
31
+ * remove remnants of mesa cli by @quaquel in https://github.com/projectmesa/mesa/pull/2617
32
+ * benchmarks.yml: Install SciPy and use uv for pip install by @EwoutH in https://github.com/projectmesa/mesa/pull/2633
33
+ * [pre-commit.ci] pre-commit autoupdate by @pre-commit-ci in https://github.com/projectmesa/mesa/pull/2659
34
+
35
+ ## New Contributors
36
+ * @PrashantChoudhary13579 made their first contribution in https://github.com/projectmesa/mesa/pull/2628
37
+ * @aarav-shukla07 made their first contribution in https://github.com/projectmesa/mesa/pull/2655
38
+ * @peter-kinger made their first contribution in https://github.com/projectmesa/mesa/pull/2605
39
+
40
+ **Full Changelog**: https://github.com/projectmesa/mesa/compare/v3.1.3...v3.1.4
41
+
4
42
  # 3.1.3 (2025-01-11)
5
43
  ## Highlights
6
44
  Mesa 3.1.3 introduces a major experimental reimplementation of Mesa's continuous space, providing an intuitive agent-centric API and significant performance improvements. The new implementation supports n-dimensional spaces and offers streamlined methods for agent movement and neighbor calculations.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Mesa
3
- Version: 3.1.3
3
+ Version: 3.1.4
4
4
  Summary: Agent-based modeling (ABM) in Python
5
5
  Project-URL: homepage, https://github.com/projectmesa/mesa
6
6
  Project-URL: repository, https://github.com/projectmesa/mesa
@@ -27,6 +27,7 @@ Requires-Dist: pandas
27
27
  Requires-Dist: scipy
28
28
  Requires-Dist: tqdm
29
29
  Provides-Extra: all
30
+ Requires-Dist: altair; extra == 'all'
30
31
  Requires-Dist: ipython; extra == 'all'
31
32
  Requires-Dist: matplotlib; extra == 'all'
32
33
  Requires-Dist: myst-nb; extra == 'all'
@@ -41,7 +42,9 @@ Requires-Dist: scipy; extra == 'all'
41
42
  Requires-Dist: seaborn; extra == 'all'
42
43
  Requires-Dist: solara; extra == 'all'
43
44
  Requires-Dist: sphinx; extra == 'all'
45
+ Requires-Dist: sphinx-copybutton; extra == 'all'
44
46
  Provides-Extra: dev
47
+ Requires-Dist: altair; extra == 'dev'
45
48
  Requires-Dist: matplotlib; extra == 'dev'
46
49
  Requires-Dist: networkx; extra == 'dev'
47
50
  Requires-Dist: pytest; extra == 'dev'
@@ -51,6 +54,7 @@ Requires-Dist: ruff; extra == 'dev'
51
54
  Requires-Dist: solara; extra == 'dev'
52
55
  Requires-Dist: sphinx; extra == 'dev'
53
56
  Provides-Extra: docs
57
+ Requires-Dist: altair; extra == 'docs'
54
58
  Requires-Dist: ipython; extra == 'docs'
55
59
  Requires-Dist: matplotlib; extra == 'docs'
56
60
  Requires-Dist: myst-nb; extra == 'docs'
@@ -60,7 +64,9 @@ Requires-Dist: pydata-sphinx-theme; extra == 'docs'
60
64
  Requires-Dist: seaborn; extra == 'docs'
61
65
  Requires-Dist: solara; extra == 'docs'
62
66
  Requires-Dist: sphinx; extra == 'docs'
67
+ Requires-Dist: sphinx-copybutton; extra == 'docs'
63
68
  Provides-Extra: examples
69
+ Requires-Dist: altair; extra == 'examples'
64
70
  Requires-Dist: matplotlib; extra == 'examples'
65
71
  Requires-Dist: networkx; extra == 'examples'
66
72
  Requires-Dist: pytest; extra == 'examples'
@@ -69,10 +75,12 @@ Requires-Dist: solara; extra == 'examples'
69
75
  Provides-Extra: network
70
76
  Requires-Dist: networkx; extra == 'network'
71
77
  Provides-Extra: rec
78
+ Requires-Dist: altair; extra == 'rec'
72
79
  Requires-Dist: matplotlib; extra == 'rec'
73
80
  Requires-Dist: networkx; extra == 'rec'
74
81
  Requires-Dist: solara; extra == 'rec'
75
82
  Provides-Extra: viz
83
+ Requires-Dist: altair; extra == 'viz'
76
84
  Requires-Dist: matplotlib; extra == 'viz'
77
85
  Requires-Dist: solara; extra == 'viz'
78
86
  Description-Content-Type: text/markdown
@@ -107,27 +115,22 @@ can be displayed in browser windows or Jupyter.*
107
115
 
108
116
  ## Using Mesa
109
117
 
110
- To install our latest stable release (3.0.x), run:
118
+ To install our latest stable release, run:
111
119
 
112
120
  ``` bash
113
121
  pip install -U mesa
114
122
  ```
115
123
 
116
- To install our latest pre-release, run:
117
-
118
- ``` bash
119
- pip install -U --pre mesa
120
- ```
121
124
  Starting with Mesa 3.0, we don't install all our dependencies anymore by default.
122
125
  ```bash
123
126
  # You can customize the additional dependencies you need, if you want. Available are:
124
- pip install -U --pre mesa[network,viz]
127
+ pip install -U mesa[network,viz]
125
128
 
126
129
  # This is equivalent to our recommended dependencies:
127
- pip install -U --pre mesa[rec]
130
+ pip install -U mesa[rec]
128
131
 
129
132
  # To install all, including developer, dependencies:
130
- pip install -U --pre mesa[all]
133
+ pip install -U mesa[all]
131
134
  ```
132
135
 
133
136
  You can also use `pip` to install the latest GitHub version:
@@ -28,27 +28,22 @@ can be displayed in browser windows or Jupyter.*
28
28
 
29
29
  ## Using Mesa
30
30
 
31
- To install our latest stable release (3.0.x), run:
31
+ To install our latest stable release, run:
32
32
 
33
33
  ``` bash
34
34
  pip install -U mesa
35
35
  ```
36
36
 
37
- To install our latest pre-release, run:
38
-
39
- ``` bash
40
- pip install -U --pre mesa
41
- ```
42
37
  Starting with Mesa 3.0, we don't install all our dependencies anymore by default.
43
38
  ```bash
44
39
  # You can customize the additional dependencies you need, if you want. Available are:
45
- pip install -U --pre mesa[network,viz]
40
+ pip install -U mesa[network,viz]
46
41
 
47
42
  # This is equivalent to our recommended dependencies:
48
- pip install -U --pre mesa[rec]
43
+ pip install -U mesa[rec]
49
44
 
50
45
  # To install all, including developer, dependencies:
51
- pip install -U --pre mesa[all]
46
+ pip install -U mesa[all]
52
47
  ```
53
48
 
54
49
  You can also use `pip` to install the latest GitHub version:
@@ -1,4 +1,4 @@
1
- name: example-environment
1
+ name: mesa-tutorials
2
2
  channels:
3
3
  - conda-forge
4
4
  dependencies:
@@ -11,4 +11,4 @@ dependencies:
11
11
  - matplotlib
12
12
  - seaborn
13
13
  - solara
14
- - mesa[rec]==3.0.0b1
14
+ - mesa[rec]
@@ -15,6 +15,7 @@ Updating docs can be confusing. Here are the basic setups.
15
15
  1. Build the docs, from the inside of the docs folder.
16
16
  * **Requires** sphinx: `pip install sphinx`
17
17
  * **Requires** nbsphinx: `pip install nbsphinx` (this will render the images from jupyter in the docs)
18
+ * **Requires** sphinx-copybutton: `pip install sphinx-copybutton` (this will enable a copy option at the top of the code written in the docs)
18
19
  * `make html`
19
20
  1. Commit the changes. If there are new files, you will have to explicit add them.
20
21
  * `git commit -am "Updating docs."`
@@ -32,5 +33,5 @@ From this point, you will need to find someone that has access to readthedocs. C
32
33
  ### Helpful Sphnix tips
33
34
  * Build html from docs:
34
35
  * `make html`
35
- * Autogenerate / update sphninx from docstrings (replace your name as the author:
36
+ * Autogenerate / update sphninx from docstrings (replace your name as the author):
36
37
  * `sphinx-apidoc -A "Jackie Kazil" -F -o docs mesa/`
@@ -11,6 +11,13 @@ For a detailed tutorial, please refer to our [Visualization Tutorial](../tutoria
11
11
  :show-inheritance:
12
12
  ```
13
13
 
14
+ ```{eval-rst}
15
+ .. automodule:: mesa.visualization.components.__init__
16
+ :members:
17
+ :undoc-members:
18
+ :show-inheritance:
19
+ ```
20
+
14
21
  ## User Parameters
15
22
 
16
23
  ```{eval-rst}
@@ -37,6 +44,7 @@ For a detailed tutorial, please refer to our [Visualization Tutorial](../tutoria
37
44
  :show-inheritance:
38
45
  ```
39
46
 
47
+
40
48
  ## Altair-based visualizations
41
49
 
42
50
  ```{eval-rst}
@@ -47,6 +47,7 @@ extensions = [
47
47
  "sphinx.ext.viewcode",
48
48
  "sphinx.ext.napoleon", # for google style docstrings
49
49
  "myst_nb", # For Markdown and Jupyter notebooks
50
+ "sphinx_copybutton" # For copying the code in the documentation
50
51
  ]
51
52
 
52
53
  # Add any paths that contain templates here, relative to this directory.
@@ -68,7 +68,6 @@ model.step()
68
68
 
69
69
  You should see agents 1-5, activated in random order. See the [tutorial](tutorials/intro_tutorial) or API documentation for more detail on how to add model functionality.
70
70
 
71
- To bootstrap a new model install mesa and run `mesa startproject`
72
71
 
73
72
  ### AgentSet and model.agents
74
73
  Mesa 3.0 makes `model.agents` and the AgentSet class central in managing and activating agents.
@@ -178,8 +177,7 @@ The results are returned as a list of dictionaries, which can be easily converte
178
177
  ### Visualization
179
178
  Mesa now uses a new browser-based visualization system called SolaraViz. This allows for interactive, customizable visualizations of your models.
180
179
 
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
-
180
+ Note: SolaraViz is experimental and still in active development in Mesa 3.x. While we attempt to minimize them, there might be API breaking changes in minor releases.
183
181
  > **Note:** SolaraViz instantiates new models using `**model_parameters.value`, so all model inputs must be keyword arguments.
184
182
 
185
183
  Ensure your model's `__init__` method accepts keyword arguments matching the `model_params` keys.
@@ -189,8 +187,8 @@ class MyModel(Model):
189
187
  def __init__(self, n_agents=10, seed=None):
190
188
  super().__init__(seed=seed)
191
189
  # Initialize the model with N agents
192
-
193
- The core functionality for building your own visualizations resides in the [`mesa.visualization`](apis/visualization) namespace
190
+ ```
191
+ The core functionality for building your own visualizations resides in the [`mesa.visualization`](apis/visualization) namespace.
194
192
 
195
193
  Here's a basic example of how to set up a visualization:
196
194
 
@@ -33,7 +33,7 @@ Mesa allows users to quickly create agent-based models using built-in core compo
33
33
 
34
34
  ## Using Mesa
35
35
  ### Installation Options
36
- To install our latest stable release (3.0.x), run:
36
+ To install our latest stable release, run:
37
37
 
38
38
  ```bash
39
39
  pip install -U mesa
@@ -47,12 +47,6 @@ On a Mac, this command might cause an error stating `zsh: no matches found: mesa
47
47
  In that case, change the command to `pip install -U "mesa[rec]"`.
48
48
 
49
49
 
50
- To install our latest pre-release:
51
-
52
- ```bash
53
- pip install -U --pre mesa[rec]
54
- ```
55
-
56
50
  ### Resources
57
51
 
58
52
  For help getting started with Mesa, check out these resources:
@@ -60,6 +54,7 @@ For help getting started with Mesa, check out these resources:
60
54
  - [Getting started] - Learn about Mesa's core concepts and components
61
55
  - [Migration Guide] - Upgrade to Mesa 3.0
62
56
  - [Mesa Examples] - Browse user-contributed models and implementations
57
+ - [Mesa Extensions] - Overview of mesa's Extensions
63
58
  - [GitHub Discussions] - Ask questions and discuss Mesa
64
59
  - [Matrix Chat Room] - Real-time chat with the Mesa community
65
60
 
@@ -97,9 +92,9 @@ API Documentation <apis/api_main>
97
92
  [matrix chat room]: https://matrix.to/#/#project-mesa:matrix.org
98
93
  [mesa]: https://github.com/projectmesa/mesa/
99
94
  [mesa overview]: overview
100
- [mesa examples]: https://github.com/projectmesa/mesa-examples
95
+ [mesa examples]: https://mesa.readthedocs.io/stable/examples.html
101
96
  [mesa introductory tutorial]: tutorials/intro_tutorial
102
97
  [mesa visualization tutorial]: tutorials/visualization_tutorial
103
98
  [migration guide]: migration_guide
104
99
  [Getting started]: getting_started
105
-
100
+ [Mesa Extensions]: mesa_extension.md
@@ -0,0 +1,97 @@
1
+ # Mesa Extensions Overview
2
+
3
+ This contains an overview of Mesa Extensions. Mesa's extensibility is a key feature that allows users to enhance functionality, improve scalability, and foster innovation in agent-based modeling.
4
+
5
+
6
+ ## Mesa-Geo 🌍
7
+
8
+ **Field:** Geographic Information Systems (GIS)
9
+
10
+ ---
11
+ **Description:**
12
+ Mesa-Geo is an extension of the Mesa framework designed to facilitate working with geographic data in agent-based modeling. It introduces a **GeoSpace** to host **GeoAgents**, which are enhanced agents that include a `geometry` attribute ([a Shapely object](https://shapely.readthedocs.io/en/latest/manual.html)) and a `crs` attribute (Coordinate Reference System). These attributes enable the integration of geographic and spatial data into simulations. Geometries can be defined manually using Shapely or imported from various sources, such as vector data files (e.g., shapefiles), GeoJSON objects, or GeoPandas GeoDataFrames.
13
+
14
+ ---
15
+ **Key Features:**
16
+ - **Spatial Reference Systems Support:** Mesa-Geo handles coordinate reference systems (CRS), which is essential for working with geographic data in various projections.
17
+ - **Geometric Operations Support:** Mesa-Geo utilizes Shapely, which provides robust tools for creating and manipulating geometric shapes like points, polygons, and lines.
18
+ - **Topological Operations Support:** Functions for analyzing spatial relationships between geometries.
19
+
20
+ ---
21
+ **Author(s):** Wang Boyu
22
+
23
+ ---
24
+ **Additional Resources:**
25
+ For more information, visit the official [Mesa-Geo repository](https://github.com/projectmesa/mesa-geo?tab=readme-ov-file).
26
+
27
+ ---
28
+
29
+ ## Mesa Examples 📊
30
+
31
+ **Description:**
32
+ Mesa Examples provide a collection of models and use cases demonstrating the features and capabilities of the Mesa framework for agent-based modeling. These examples include core and user-submitted models covering a variety of domains like grid spaces, networks, visualization, and GIS.
33
+
34
+ ---
35
+
36
+ **Key Features:**
37
+ - **Core Examples:** Fully tested and updated models included directly with the Mesa framework.
38
+ - **User Examples:** Community-contributed models showcasing advanced and diverse use cases.
39
+ - **Extensive Coverage:** Examples for grid spaces, GIS integration, networks, visualization, and more.
40
+ - **Easy Access:** Available directly from the Mesa package or via installation from the repository.
41
+
42
+ ---
43
+
44
+ **Author(s):** Contributions from the Mesa developer community.
45
+
46
+ ---
47
+
48
+ **Examples Include:**
49
+ - **Grid Space:** Models like Bank Reserves, Conway’s Game of Life, and Forest Fire.
50
+ - **GIS:** GeoSchelling Models, Urban Growth, and Population Models.
51
+ - **Network:** Boltzmann Wealth Model and Ant System for the Traveling Salesman Problem.
52
+ - **Visualization:** Charting tools and grid displays.
53
+
54
+ ---
55
+
56
+ **For More Information:**
57
+ For more Detail, Visit the [Mesa Examples Repository](https://github.com/projectmesa/mesa/tree/main/mesa/examples).
58
+
59
+ ---
60
+
61
+ ## **Mesa-Frames** 🚀
62
+
63
+ **Description:**
64
+ Mesa-Frames is an extension of the Mesa framework designed to handle complex simulations with thousands of agents. By utilizing DataFrames (pandas or Polars), it enhances scalability and performance while maintaining a syntax similar to Mesa.
65
+
66
+ ---
67
+
68
+ **Key Features:**
69
+ - **Enhanced Performance:** Uses DataFrames for SIMD processing and vectorized functions to speed up simulations.
70
+ - **Backend Support:** Supports `pandas` (ease of use) and `Polars` (performance innovations with Rust-based backend).
71
+ - **Seamless Integration:** Maintains a similar API and functionality as the base Mesa framework for easier adoption.
72
+ - **In-Place Operations:** Functional programming and fast memory-efficient copy methods.
73
+ - **Future Plans:** GPU functionality, automatic model vectorization, and backend-independent AgentSet class.
74
+
75
+ ---
76
+
77
+ **Usage:**
78
+ - Define agents using `AgentSetPandas` or `AgentSetPolars`.
79
+ - Implement models by subclassing `ModelDF`.
80
+ - Perform vectorized operations to enhance simulation performance.
81
+
82
+ ---
83
+
84
+ **Author(s):**
85
+ Developed and maintained by the Mesa development community.
86
+
87
+ ---
88
+
89
+ **License:**
90
+ Distributed under the MIT License.
91
+
92
+ ---
93
+
94
+ **More Information:**
95
+ Visit the [GitHub Repository](https://github.com/projectmesa/mesa-frames).
96
+
97
+ ---
@@ -15,7 +15,7 @@
15
15
  "source": [
16
16
  "**Important:** \n",
17
17
  "- 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/intro_tutorial.ipynb) or if you do not have a Google account you can use [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/projectmesa/mesa/main?labpath=docs%2Ftutorials%2Fintro_tutorial.ipynb) (This can take 30 seconds to 5 minutes to load)\n",
18
- "- If you have installed mesa and are running locally, please ensure that your Mesa version is greater than or equal to 3.0.0b1.\n",
18
+ "- If you are running locally, please ensure you have the latest Mesa version installed.\n",
19
19
  "\n",
20
20
  "## Tutorial Description\n",
21
21
  "\n",
@@ -44,7 +44,7 @@
44
44
  "If you are looking for other Mesa models or tools here are some additional resources. \n",
45
45
  "\n",
46
46
  "- Interactive Dashboard: There is a separate [visualization tutorial](https://mesa.readthedocs.io/latest/tutorials/visualization_tutorial.html) that will take users through building a dashboard for this model (aka Boltzmann Wealth Model).\n",
47
- "- Classic ABMs: You can also find canonical examples of ABMs written in Mesa in the [Examples Tab](https://mesa.readthedocs.io/latest/tutorials/examples.html)\n",
47
+ "- Classic ABMs: You can also find canonical examples of ABMs written in Mesa in the [Examples Tab](https://mesa.readthedocs.io/stable/examples.html)\n",
48
48
  "- More Examples: Want to integrate Reinforcement Learning or work on the Traveling Salesman Problem checkout [Mesa Examples](https://github.com/projectmesa/mesa-examples/)\n",
49
49
  "- Mesa-Geo: If you need an ABM with Geographic Information Systems (GIS) checkout [Mesa-Geo](https://mesa-geo.readthedocs.io/latest/)\n",
50
50
  "- Mesa Frames: Have a large complex model that you need to speed up, check out [Mesa Frames](https://github.com/projectmesa/mesa-frames)"
@@ -85,12 +85,6 @@
85
85
  "pip install --upgrade mesa[rec] \n",
86
86
  "```\n",
87
87
  "\n",
88
- "If you want to use our newest features, you can also opt to install our latest pre-release version:\n",
89
- "\n",
90
- "```bash\n",
91
- "pip install --upgrade --pre mesa[rec]\n",
92
- "```\n",
93
- "\n",
94
88
  "Install Jupyter notebook (optional):\n",
95
89
  "\n",
96
90
  "```bash\n",
@@ -118,7 +112,7 @@
118
112
  "cell_type": "raw",
119
113
  "metadata": {},
120
114
  "source": [
121
- "pip install --quiet --upgrade --pre mesa[rec] #installs Mesa 3.0"
115
+ "pip install --quiet --upgrade mesa[rec] #installs Mesa 3.1.3"
122
116
  ]
123
117
  },
124
118
  {
@@ -615,8 +609,8 @@
615
609
  " # Create agents\n",
616
610
  " agents = MoneyAgent.create_agents(model=self, n=n)\n",
617
611
  " # 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",
612
+ " x = self.rng.integers(0, self.grid.width, size=(n,))\n",
613
+ " y = self.rng.integers(0, self.grid.height, size=(n,))\n",
620
614
  " for a, i, j in zip(agents, x, y):\n",
621
615
  " # Add the agent to a random grid cell\n",
622
616
  " self.grid.place_agent(a, (i, j))"
@@ -11,9 +11,7 @@
11
11
  "cell_type": "markdown",
12
12
  "metadata": {},
13
13
  "source": [
14
- "*This version of the visualisation tutorial is updated for Mesa 3.0, and works with Mesa `3.0.0` and above.*\n",
15
- "\n",
16
- "> **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.\n",
14
+ "*This version of the visualisation tutorial is updated for Mesa 3.1, and works with Mesa `3.1.0` and above.*\n",
17
15
  "\n",
18
16
  "**Important:** \n",
19
17
  "- If you are just exploring Mesa and want the fastest way to the the dashboard and code checkout [![py.cafe](https://img.shields.io/badge/launch-py.cafe-blue)](https://py.cafe/app/tpike3/boltzmann-wealth-model) (click \"Editor\" to see the code)\n",
@@ -22,7 +22,7 @@ __all__ = [
22
22
  ]
23
23
 
24
24
  __title__ = "mesa"
25
- __version__ = "3.1.3"
25
+ __version__ = "3.1.4"
26
26
  __license__ = "Apache 2.0"
27
27
  _this_year = datetime.datetime.now(tz=datetime.UTC).date().year
28
28
  __copyright__ = f"Copyright {_this_year} Project Mesa Team"
@@ -117,6 +117,9 @@ class DataCollector:
117
117
  self._agenttype_records = {}
118
118
  self.tables = {}
119
119
 
120
+ # add the signal of the validation of model reporter
121
+ self._validated = False
122
+
120
123
  if model_reporters is not None:
121
124
  for name, reporter in model_reporters.items():
122
125
  self._new_model_reporter(name, reporter)
@@ -134,13 +137,66 @@ class DataCollector:
134
137
  for name, columns in tables.items():
135
138
  self._new_table(name, columns)
136
139
 
140
+ def _validate_model_reporter(self, name, reporter, model):
141
+ """Validate model reporter and handle validation results appropriately.
142
+
143
+ Args:
144
+ name: Name of the reporter
145
+ reporter: Reporter definition (lambda/method/attribute/function list)
146
+ model: Model instance
147
+
148
+ Raises:
149
+ ValueError: If reporter is None or has invalid format
150
+ AttributeError: If model attribute doesn't exist
151
+ TypeError: If reporter type is not supported
152
+ RuntimeError: If reporter execution fails
153
+ """
154
+ self._validated = True # put the change of signal firstly avoid losing efficacy
155
+
156
+ # Type 1: Lambda function
157
+ if isinstance(reporter, types.LambdaType):
158
+ try:
159
+ reporter(model)
160
+ except Exception as e:
161
+ raise RuntimeError(
162
+ f"Lambda reporter '{name}' failed validation: {e!s}\n"
163
+ f"Example: lambda m: len(m.agents)"
164
+ ) from e
165
+
166
+ # Type 2: Method of class/instance
167
+ if not callable(reporter) and not isinstance(reporter, types.LambdaType):
168
+ pass
169
+
170
+ # Type 3: Model attribute (string)
171
+ if isinstance(reporter, str):
172
+ try:
173
+ if not hasattr(model, reporter):
174
+ raise AttributeError(
175
+ f"Model reporter '{name}' references non-existent attribute '{reporter}'\n"
176
+ )
177
+ getattr(model, reporter) # 验证属性是否可访问
178
+ except AttributeError as e:
179
+ raise AttributeError(
180
+ f"Model reporter '{name}' attribute validation failed: {e!s}\n"
181
+ ) from e
182
+
183
+ # Type 4: Function with parameters in list
184
+ if isinstance(reporter, list) and (not reporter or not callable(reporter[0])):
185
+ raise ValueError(
186
+ f"Invalid function list format for reporter '{name}'\n"
187
+ f"Expected: [function, [param1, param2]], got: {reporter}"
188
+ )
189
+
137
190
  def _new_model_reporter(self, name, reporter):
138
191
  """Add a new model-level reporter to collect.
139
192
 
140
193
  Args:
141
194
  name: Name of the model-level variable to collect.
142
- reporter: Attribute string, or function object that returns the
143
- variable when given a model instance.
195
+ reporter: Can be one of four types:
196
+ 1. Attribute name (str): "attribute_name"
197
+ 2. Lambda function: lambda m: len(m.agents)
198
+ 3. Method: model.get_count or Model.get_count
199
+ 4. List of [function, [parameters]]
144
200
  """
145
201
  self.model_reporters[name] = reporter
146
202
  self.model_vars[name] = []
@@ -262,6 +318,10 @@ class DataCollector:
262
318
  def collect(self, model):
263
319
  """Collect all the data for the given model object."""
264
320
  if self.model_reporters:
321
+ if not self._validated:
322
+ for name, reporter in self.model_reporters.items():
323
+ self._validate_model_reporter(name, reporter, model)
324
+
265
325
  for var, reporter in self.model_reporters.items():
266
326
  # Check if lambda or partial function
267
327
  if isinstance(reporter, types.LambdaType | partial):
@@ -1,46 +1,24 @@
1
- import numpy as np
2
- import solara
3
- from matplotlib.figure import Figure
4
-
5
1
  from mesa.examples.advanced.sugarscape_g1mt.model import SugarscapeG1mt
6
2
  from mesa.visualization import Slider, SolaraViz, make_plot_component
3
+ from mesa.visualization.components.matplotlib_components import make_mpl_space_component
4
+
7
5
 
6
+ def agent_portrayal(agent):
7
+ return {"marker": "o", "color": "red", "size": 10}
8
8
 
9
- def SpaceDrawer(model):
10
- def portray(g):
11
- layers = {
12
- "trader": {"x": [], "y": [], "c": "tab:red", "marker": "o", "s": 10},
13
- }
14
9
 
15
- for agent in g.all_cells.agents:
16
- i, j = agent.cell.coordinate
17
- layers["trader"]["x"].append(i)
18
- layers["trader"]["y"].append(j)
19
- return layers
10
+ propertylayer_portrayal = {
11
+ "sugar": {"color": "blue", "alpha": 0.8, "colorbar": True, "vmin": 0, "vmax": 10},
12
+ "spice": {"color": "red", "alpha": 0.8, "colorbar": True, "vmin": 0, "vmax": 10},
13
+ }
20
14
 
21
- fig = Figure()
22
- ax = fig.subplots()
23
- out = portray(model.grid)
24
- # Sugar
25
- # Important note: imshow by default draws from upper left. You have to
26
- # always explicitly specify origin="lower".
27
- im = ax.imshow(
28
- np.ma.masked_where(model.grid.sugar.data <= 1, model.grid.sugar.data),
29
- cmap="spring",
30
- origin="lower",
31
- )
32
- fig.colorbar(im, orientation="vertical")
33
- # Spice
34
- ax.imshow(
35
- np.ma.masked_where(model.grid.spice.data <= 1, model.grid.spice.data),
36
- cmap="winter",
37
- origin="lower",
38
- )
39
- # Trader
40
- ax.scatter(**out["trader"])
41
- ax.set_axis_off()
42
- return solara.FigureMatplotlib(fig)
43
15
 
16
+ sugarscape_space = make_mpl_space_component(
17
+ agent_portrayal=agent_portrayal,
18
+ propertylayer_portrayal=propertylayer_portrayal,
19
+ post_process=None,
20
+ draw_grid=False,
21
+ )
44
22
 
45
23
  model_params = {
46
24
  "seed": {
@@ -72,7 +50,7 @@ model = SugarscapeG1mt()
72
50
  page = SolaraViz(
73
51
  model,
74
52
  components=[
75
- SpaceDrawer,
53
+ sugarscape_space,
76
54
  make_plot_component("#Traders"),
77
55
  make_plot_component("Price"),
78
56
  ],