Mesa 2.3.4__tar.gz → 2.4.0__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 (145) hide show
  1. {mesa-2.3.4 → mesa-2.4.0}/.github/workflows/build_lint.yml +3 -0
  2. {mesa-2.3.4 → mesa-2.4.0}/.readthedocs.yml +1 -1
  3. {mesa-2.3.4 → mesa-2.4.0}/CONTRIBUTING.md +1 -1
  4. {mesa-2.3.4 → mesa-2.4.0}/HISTORY.md +64 -0
  5. {mesa-2.3.4 → mesa-2.4.0}/PKG-INFO +5 -4
  6. {mesa-2.3.4 → mesa-2.4.0}/README.md +3 -3
  7. {mesa-2.3.4 → mesa-2.4.0}/benchmarks/WolfSheep/wolf_sheep.py +3 -2
  8. mesa-2.4.0/docs/_static/switcher.json +12 -0
  9. {mesa-2.3.4 → mesa-2.4.0}/docs/conf.py +9 -1
  10. {mesa-2.3.4 → mesa-2.4.0}/docs/index.md +1 -0
  11. mesa-2.4.0/docs/migration_guide.md +294 -0
  12. {mesa-2.3.4 → mesa-2.4.0}/docs/overview.md +49 -0
  13. {mesa-2.3.4 → mesa-2.4.0}/docs/packages.md +2 -2
  14. {mesa-2.3.4 → mesa-2.4.0}/docs/tutorials/adv_tutorial_legacy.ipynb +1 -1
  15. {mesa-2.3.4 → mesa-2.4.0}/docs/tutorials/intro_tutorial.ipynb +2 -2
  16. {mesa-2.3.4 → mesa-2.4.0}/docs/tutorials/visualization_tutorial.ipynb +1 -1
  17. {mesa-2.3.4 → mesa-2.4.0}/mesa/__init__.py +1 -1
  18. mesa-2.4.0/mesa/agent.py +641 -0
  19. {mesa-2.3.4 → mesa-2.4.0}/mesa/batchrunner.py +3 -0
  20. {mesa-2.3.4 → mesa-2.4.0}/mesa/datacollection.py +135 -20
  21. {mesa-2.3.4 → mesa-2.4.0}/mesa/experimental/devs/examples/epstein_civil_violence.py +2 -1
  22. {mesa-2.3.4 → mesa-2.4.0}/mesa/experimental/devs/examples/wolf_sheep.py +3 -2
  23. {mesa-2.3.4 → mesa-2.4.0}/mesa/experimental/jupyter_viz.py +9 -8
  24. {mesa-2.3.4 → mesa-2.4.0}/mesa/model.py +91 -21
  25. {mesa-2.3.4 → mesa-2.4.0}/mesa/space.py +9 -3
  26. {mesa-2.3.4 → mesa-2.4.0}/pyproject.toml +1 -0
  27. mesa-2.4.0/tests/test_agent.py +594 -0
  28. {mesa-2.3.4 → mesa-2.4.0}/tests/test_datacollector.py +176 -5
  29. {mesa-2.3.4 → mesa-2.4.0}/tests/test_model.py +17 -1
  30. {mesa-2.3.4 → mesa-2.4.0}/tests/test_space.py +17 -0
  31. {mesa-2.3.4 → mesa-2.4.0}/tests/test_time.py +1 -1
  32. mesa-2.3.4/mesa/agent.py +0 -377
  33. mesa-2.3.4/tests/test_agent.py +0 -308
  34. {mesa-2.3.4 → mesa-2.4.0}/.codespellignore +0 -0
  35. {mesa-2.3.4 → mesa-2.4.0}/.coveragerc +0 -0
  36. {mesa-2.3.4 → mesa-2.4.0}/.github/ISSUE_TEMPLATE/asking-help.md +0 -0
  37. {mesa-2.3.4 → mesa-2.4.0}/.github/ISSUE_TEMPLATE/bug-report.md +0 -0
  38. {mesa-2.3.4 → mesa-2.4.0}/.github/ISSUE_TEMPLATE/feature-request.md +0 -0
  39. {mesa-2.3.4 → mesa-2.4.0}/.github/dependabot.yml +0 -0
  40. {mesa-2.3.4 → mesa-2.4.0}/.github/release.yml +0 -0
  41. {mesa-2.3.4 → mesa-2.4.0}/.github/workflows/benchmarks.yml +0 -0
  42. {mesa-2.3.4 → mesa-2.4.0}/.github/workflows/release.yml +0 -0
  43. {mesa-2.3.4 → mesa-2.4.0}/.gitignore +0 -0
  44. {mesa-2.3.4 → mesa-2.4.0}/.pre-commit-config.yaml +0 -0
  45. {mesa-2.3.4 → mesa-2.4.0}/CITATION.bib +0 -0
  46. {mesa-2.3.4 → mesa-2.4.0}/CODE_OF_CONDUCT.md +0 -0
  47. {mesa-2.3.4 → mesa-2.4.0}/Dockerfile +0 -0
  48. {mesa-2.3.4 → mesa-2.4.0}/LICENSE +0 -0
  49. {mesa-2.3.4 → mesa-2.4.0}/benchmarks/Flocking/__init__.py +0 -0
  50. {mesa-2.3.4 → mesa-2.4.0}/benchmarks/Flocking/flocking.py +0 -0
  51. {mesa-2.3.4 → mesa-2.4.0}/benchmarks/Schelling/__init__.py +0 -0
  52. {mesa-2.3.4 → mesa-2.4.0}/benchmarks/Schelling/schelling.py +0 -0
  53. {mesa-2.3.4 → mesa-2.4.0}/benchmarks/WolfSheep/__init__.py +0 -0
  54. {mesa-2.3.4 → mesa-2.4.0}/benchmarks/compare_timings.py +0 -0
  55. {mesa-2.3.4 → mesa-2.4.0}/benchmarks/configurations.py +0 -0
  56. {mesa-2.3.4 → mesa-2.4.0}/benchmarks/global_benchmark.py +0 -0
  57. {mesa-2.3.4 → mesa-2.4.0}/codecov.yaml +0 -0
  58. {mesa-2.3.4 → mesa-2.4.0}/docker-compose.yml +0 -0
  59. {mesa-2.3.4 → mesa-2.4.0}/docs/Makefile +0 -0
  60. {mesa-2.3.4 → mesa-2.4.0}/docs/README.md +0 -0
  61. {mesa-2.3.4 → mesa-2.4.0}/docs/apis/api_main.md +0 -0
  62. {mesa-2.3.4 → mesa-2.4.0}/docs/apis/batchrunner.md +0 -0
  63. {mesa-2.3.4 → mesa-2.4.0}/docs/apis/datacollection.md +0 -0
  64. {mesa-2.3.4 → mesa-2.4.0}/docs/apis/experimental.md +0 -0
  65. {mesa-2.3.4 → mesa-2.4.0}/docs/apis/init.md +0 -0
  66. {mesa-2.3.4 → mesa-2.4.0}/docs/apis/space.md +0 -0
  67. {mesa-2.3.4 → mesa-2.4.0}/docs/apis/time.md +0 -0
  68. {mesa-2.3.4 → mesa-2.4.0}/docs/apis/visualization.md +0 -0
  69. {mesa-2.3.4 → mesa-2.4.0}/docs/best-practices.md +0 -0
  70. {mesa-2.3.4 → mesa-2.4.0}/docs/howto.md +0 -0
  71. {mesa-2.3.4 → mesa-2.4.0}/docs/images/Mesa_Screenshot.png +0 -0
  72. {mesa-2.3.4 → mesa-2.4.0}/docs/images/mesa_logo.ico +0 -0
  73. {mesa-2.3.4 → mesa-2.4.0}/docs/images/mesa_logo.png +0 -0
  74. {mesa-2.3.4 → mesa-2.4.0}/docs/images/tutorial/br_ginis.png +0 -0
  75. {mesa-2.3.4 → mesa-2.4.0}/docs/images/tutorial/dc_endwealth.png +0 -0
  76. {mesa-2.3.4 → mesa-2.4.0}/docs/images/tutorial/dc_gini.png +0 -0
  77. {mesa-2.3.4 → mesa-2.4.0}/docs/images/tutorial/dc_oneagent.png +0 -0
  78. {mesa-2.3.4 → mesa-2.4.0}/docs/images/tutorial/first_hist.png +0 -0
  79. {mesa-2.3.4 → mesa-2.4.0}/docs/images/tutorial/multirun_hist.png +0 -0
  80. {mesa-2.3.4 → mesa-2.4.0}/docs/images/tutorial/numpy_grid.png +0 -0
  81. {mesa-2.3.4 → mesa-2.4.0}/docs/images/tutorial/viz_chart.png +0 -0
  82. {mesa-2.3.4 → mesa-2.4.0}/docs/images/tutorial/viz_empty.png +0 -0
  83. {mesa-2.3.4 → mesa-2.4.0}/docs/images/tutorial/viz_greycircles.png +0 -0
  84. {mesa-2.3.4 → mesa-2.4.0}/docs/images/tutorial/viz_histogram.png +0 -0
  85. {mesa-2.3.4 → mesa-2.4.0}/docs/images/tutorial/viz_redcircles.png +0 -0
  86. {mesa-2.3.4 → mesa-2.4.0}/docs/make.bat +0 -0
  87. {mesa-2.3.4 → mesa-2.4.0}/docs/mesa.md +0 -0
  88. {mesa-2.3.4 → mesa-2.4.0}/docs/mesa.visualization.md +0 -0
  89. {mesa-2.3.4 → mesa-2.4.0}/docs/mesa.visualization.modules.md +0 -0
  90. {mesa-2.3.4 → mesa-2.4.0}/docs/modular-visualization.md +0 -0
  91. {mesa-2.3.4 → mesa-2.4.0}/docs/tutorials/MoneyModel.py +0 -0
  92. {mesa-2.3.4 → mesa-2.4.0}/docs/tutorials/files/viz_chart.png +0 -0
  93. {mesa-2.3.4 → mesa-2.4.0}/docs/tutorials/files/viz_empty.png +0 -0
  94. {mesa-2.3.4 → mesa-2.4.0}/docs/tutorials/files/viz_greycircles.png +0 -0
  95. {mesa-2.3.4 → mesa-2.4.0}/docs/tutorials/files/viz_histogram.png +0 -0
  96. {mesa-2.3.4 → mesa-2.4.0}/docs/tutorials/files/viz_redcircles.png +0 -0
  97. {mesa-2.3.4 → mesa-2.4.0}/docs/tutorials/files/viz_slider.png +0 -0
  98. {mesa-2.3.4 → mesa-2.4.0}/mesa/cookiecutter-mesa/cookiecutter.json +0 -0
  99. {mesa-2.3.4 → mesa-2.4.0}/mesa/cookiecutter-mesa/hooks/post_gen_project.py +0 -0
  100. {mesa-2.3.4 → mesa-2.4.0}/mesa/cookiecutter-mesa/{{cookiecutter.snake}}/README.md +0 -0
  101. {mesa-2.3.4 → mesa-2.4.0}/mesa/cookiecutter-mesa/{{cookiecutter.snake}}/run.pytemplate +0 -0
  102. {mesa-2.3.4 → mesa-2.4.0}/mesa/cookiecutter-mesa/{{cookiecutter.snake}}/setup.pytemplate +0 -0
  103. {mesa-2.3.4 → mesa-2.4.0}/mesa/cookiecutter-mesa/{{cookiecutter.snake}}/{{cookiecutter.snake}}/__init__.py +0 -0
  104. {mesa-2.3.4 → mesa-2.4.0}/mesa/cookiecutter-mesa/{{cookiecutter.snake}}/{{cookiecutter.snake}}/model.pytemplate +0 -0
  105. {mesa-2.3.4 → mesa-2.4.0}/mesa/cookiecutter-mesa/{{cookiecutter.snake}}/{{cookiecutter.snake}}/server.pytemplate +0 -0
  106. {mesa-2.3.4 → mesa-2.4.0}/mesa/experimental/UserParam.py +0 -0
  107. {mesa-2.3.4 → mesa-2.4.0}/mesa/experimental/__init__.py +0 -0
  108. {mesa-2.3.4 → mesa-2.4.0}/mesa/experimental/cell_space/__init__.py +0 -0
  109. {mesa-2.3.4 → mesa-2.4.0}/mesa/experimental/cell_space/cell.py +0 -0
  110. {mesa-2.3.4 → mesa-2.4.0}/mesa/experimental/cell_space/cell_agent.py +0 -0
  111. {mesa-2.3.4 → mesa-2.4.0}/mesa/experimental/cell_space/cell_collection.py +0 -0
  112. {mesa-2.3.4 → mesa-2.4.0}/mesa/experimental/cell_space/discrete_space.py +0 -0
  113. {mesa-2.3.4 → mesa-2.4.0}/mesa/experimental/cell_space/grid.py +0 -0
  114. {mesa-2.3.4 → mesa-2.4.0}/mesa/experimental/cell_space/network.py +0 -0
  115. {mesa-2.3.4 → mesa-2.4.0}/mesa/experimental/components/altair.py +0 -0
  116. {mesa-2.3.4 → mesa-2.4.0}/mesa/experimental/components/matplotlib.py +0 -0
  117. {mesa-2.3.4 → mesa-2.4.0}/mesa/experimental/devs/__init__.py +0 -0
  118. {mesa-2.3.4 → mesa-2.4.0}/mesa/experimental/devs/eventlist.py +0 -0
  119. {mesa-2.3.4 → mesa-2.4.0}/mesa/experimental/devs/simulator.py +0 -0
  120. {mesa-2.3.4 → mesa-2.4.0}/mesa/flat/__init__.py +0 -0
  121. {mesa-2.3.4 → mesa-2.4.0}/mesa/flat/visualization.py +0 -0
  122. {mesa-2.3.4 → mesa-2.4.0}/mesa/main.py +0 -0
  123. {mesa-2.3.4 → mesa-2.4.0}/mesa/time.py +0 -0
  124. {mesa-2.3.4 → mesa-2.4.0}/mesa/visualization/ModularVisualization.py +0 -0
  125. {mesa-2.3.4 → mesa-2.4.0}/mesa/visualization/TextVisualization.py +0 -0
  126. {mesa-2.3.4 → mesa-2.4.0}/mesa/visualization/UserParam.py +0 -0
  127. {mesa-2.3.4 → mesa-2.4.0}/mesa/visualization/__init__.py +0 -0
  128. {mesa-2.3.4 → mesa-2.4.0}/mesa/visualization/modules.py +0 -0
  129. {mesa-2.3.4 → mesa-2.4.0}/mypy.ini +0 -0
  130. {mesa-2.3.4 → mesa-2.4.0}/tests/__init__.py +0 -0
  131. {mesa-2.3.4 → mesa-2.4.0}/tests/read_requirements.py +0 -0
  132. {mesa-2.3.4 → mesa-2.4.0}/tests/test_batch_run.py +0 -0
  133. {mesa-2.3.4 → mesa-2.4.0}/tests/test_cell_space.py +0 -0
  134. {mesa-2.3.4 → mesa-2.4.0}/tests/test_devs.py +0 -0
  135. {mesa-2.3.4 → mesa-2.4.0}/tests/test_end_to_end_viz.sh +0 -0
  136. {mesa-2.3.4 → mesa-2.4.0}/tests/test_examples.py +0 -0
  137. {mesa-2.3.4 → mesa-2.4.0}/tests/test_grid.py +0 -0
  138. {mesa-2.3.4 → mesa-2.4.0}/tests/test_import_namespace.py +0 -0
  139. {mesa-2.3.4 → mesa-2.4.0}/tests/test_jupyter_viz.py +0 -0
  140. {mesa-2.3.4 → mesa-2.4.0}/tests/test_lifespan.py +0 -0
  141. {mesa-2.3.4 → mesa-2.4.0}/tests/test_main.py +0 -0
  142. {mesa-2.3.4 → mesa-2.4.0}/tests/test_scaffold.py +0 -0
  143. {mesa-2.3.4 → mesa-2.4.0}/tests/test_tornado.py +0 -0
  144. {mesa-2.3.4 → mesa-2.4.0}/tests/test_usersettableparam.py +0 -0
  145. {mesa-2.3.4 → mesa-2.4.0}/tests/test_visualization.py +0 -0
@@ -33,6 +33,8 @@ jobs:
33
33
  os: [windows, ubuntu, macos]
34
34
  python-version: ["3.12"]
35
35
  include:
36
+ - os: ubuntu
37
+ python-version: "3.13"
36
38
  - os: ubuntu
37
39
  python-version: "3.11"
38
40
  - os: ubuntu
@@ -49,6 +51,7 @@ jobs:
49
51
  uses: actions/setup-python@v5
50
52
  with:
51
53
  python-version: ${{ matrix.python-version }}
54
+ allow-prereleases: true
52
55
  cache: 'pip'
53
56
  - name: Install uv
54
57
  run: pip install uv
@@ -1,5 +1,5 @@
1
1
  # Read the Docs configuration file
2
- # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
2
+ # See https://docs.readthedocs.io/stable/config-file/v2.html for details
3
3
 
4
4
  # Required
5
5
  version: 2
@@ -53,7 +53,7 @@ Learn the tools, talk to us about what you want to change, and open a small PR.
53
53
  Awesome! You have the basics of open-source software development (if not check above), but not much modelling experience.
54
54
 
55
55
  First step is to start thinking like a modeller. To understand the fine details about our library and contribute meaningfully, get some modelling experience:
56
- - Go though our [Introductory Tutorial](https://mesa.readthedocs.io/en/latest/tutorials/intro_tutorial.html) and [Visualization Tutorial](https://mesa.readthedocs.io/en/latest/tutorials/visualization_tutorial.html). While going through them, dive into the source code to really see what everything does.
56
+ - Go though our [Introductory Tutorial](https://mesa.readthedocs.io/latest/tutorials/intro_tutorial.html) and [Visualization Tutorial](https://mesa.readthedocs.io/latest/tutorials/visualization_tutorial.html). While going through them, dive into the source code to really see what everything does.
57
57
  - Follow an ABM course (if possible). They might be a bit outdated programming language wise, but conceptual they're sound.
58
58
  - This MOOC on ABM concepts: [Agent Based Modeling](https://ocw.tudelft.nl/course-lectures/agent-based-modeling/)
59
59
  - This MOOC on practical ABM modelling: [Agent-Based Models with Python: An Introduction to Mesa](https://www.complexityexplorer.org/courses/172-agent-based-models-with-python-an-introduction-to-mesa)
@@ -1,6 +1,70 @@
1
1
  ---
2
2
  title: Release History
3
3
  ---
4
+ # 2.4.0 (2024-09-24)
5
+ ## Highlights
6
+ Mesa 2.4.0 brings several key improvements from the upcoming 3.0 series, while maintaining compatibility with existing Mesa 2.x models.
7
+
8
+ The DataCollector now supports collecting data from specific Agent subclasses using the new `agenttype_reporters` parameter ([#2300](https://github.com/projectmesa/mesa/pull/2300)). This allows collecting different metrics for different agent types. For example:
9
+
10
+ ```python
11
+ self.datacollector = DataCollector(
12
+ agenttype_reporters={
13
+ Wolf: {"sheep_eaten": "sheep_eaten"},
14
+ Sheep: {"wool": "wool_amount"}
15
+ }
16
+ )
17
+ ```
18
+
19
+ The AgentSet class, which underpins `model.agents`, has received major enhancements:
20
+ - A new `groupby()` method to split agents into groups ([#2220](https://github.com/projectmesa/mesa/pull/2220))
21
+ - An `agg()` method to quickly compute aggregate values ([#2266](https://github.com/projectmesa/mesa/pull/2266))
22
+ - A faster `shuffle_do()` method for more efficient random agent activation ([#2283](https://github.com/projectmesa/mesa/pull/2283))
23
+ - The `select()` method now allows choosing a fraction of agents ([#2253](https://github.com/projectmesa/mesa/pull/2253))
24
+ - The `do()` method can now take any callable function, not just string method names ([#2219](https://github.com/projectmesa/mesa/pull/2219))
25
+
26
+ Other notable improvements include:
27
+ - The Model class now exposes an `agents_by_type` property for easier access to agents of specific types ([#2267](https://github.com/projectmesa/mesa/pull/2267))
28
+ - Performance enhancements for `Model.agents` ([#2251](https://github.com/projectmesa/mesa/pull/2251))
29
+ - The `AgentSet.get()` method now handles missing values with optional default value ([#2279](https://github.com/projectmesa/mesa/pull/2279))
30
+
31
+ This release also fixes a bug in the Grid's `move_agent_to_one_of` method with `selection="closest"`, which previously selected locations deterministically instead of randomly ([#2118](https://github.com/projectmesa/mesa/pull/2118)).
32
+
33
+ Finally, we've made significant documentation improvements, including the addition of a new [Migration guide](https://mesa.readthedocs.io/latest/migration_guide.html) to help users transition to future Mesa versions ([#2257](https://github.com/projectmesa/mesa/pull/2257)).
34
+
35
+ ## What's Changed
36
+ ### 🎉 New features added
37
+ * Add AgentSet.groupby by @quaquel in [#2220](https://github.com/projectmesa/mesa/pull/2220)
38
+ * AgentSet: Add `agg` method by @EwoutH in [#2266](https://github.com/projectmesa/mesa/pull/2266)
39
+ * GroupBy: Add `count` and `agg` methods by @EwoutH in [#2290](https://github.com/projectmesa/mesa/pull/2290)
40
+ * datacollector: Allow collecting data from Agent (sub)classes by @EwoutH in [#2300](https://github.com/projectmesa/mesa/pull/2300)
41
+ * Add optimized shuffle_do() method to AgentSet by @EwoutH in [#2283](https://github.com/projectmesa/mesa/pull/2283)
42
+
43
+ ### 🛠 Enhancements made
44
+ * Allow AgentSet.do() to take Callable function by @quaquel in [#2219](https://github.com/projectmesa/mesa/pull/2219)
45
+ * Split AgentSet into map and do to separate return types by @quaquel in [#2237](https://github.com/projectmesa/mesa/pull/2237)
46
+ * Performance enhancements for Model.agents by @quaquel in [#2251](https://github.com/projectmesa/mesa/pull/2251)
47
+ * AgentSet: Allow selecting a fraction of agents in the AgentSet by @EwoutH in [#2253](https://github.com/projectmesa/mesa/pull/2253)
48
+ * Model: Replace `get_agents_of_type` method with `agents_by_type` property by @EwoutH in [#2267](https://github.com/projectmesa/mesa/pull/2267)
49
+ * Add default values and missing value handling to `agentset.get` by @quaquel in [#2279](https://github.com/projectmesa/mesa/pull/2279)
50
+
51
+ ### 🐛 Bugs fixed
52
+ * Jupyter_viz: Allow measures to be None by @EwoutH in [#2163](https://github.com/projectmesa/mesa/pull/2163)
53
+ * Fix deterministic behavior in `move_agent_to_one_of` with `selection="closest"` by @OrenBochman in [#2118](https://github.com/projectmesa/mesa/pull/2118)
54
+
55
+ ### 📜 Documentation improvements
56
+ * Contribution: Add "I have no idea where to start" section by @EwoutH in [#2258](https://github.com/projectmesa/mesa/pull/2258)
57
+ * Write initial Mesa Migration guide by @EwoutH in [#2257](https://github.com/projectmesa/mesa/pull/2257)
58
+ * Docs: Fix broken relative links by removing `.html` suffix by @EwoutH in [#2274](https://github.com/projectmesa/mesa/pull/2274)
59
+ * Readthedocs: Don't let notebook failures pass silently by @EwoutH in [#2276](https://github.com/projectmesa/mesa/pull/2276)
60
+ * update migration guide to describe solaraviz updates by @Corvince in [#2297](https://github.com/projectmesa/mesa/pull/2297)
61
+ * Migration Guide: Add Model initialization requirement and automatic Agent.unique_id assignment by @EwoutH in [#2302](https://github.com/projectmesa/mesa/pull/2302)
62
+
63
+ ### 🔧 Maintenance
64
+ * make typing behavior of AgentSet.get explicit by @quaquel in [#2293](https://github.com/projectmesa/mesa/pull/2293)
65
+
66
+ **Full Changelog**: [https://github.com/projectmesa/mesa/compare/v2.3.4...v2.4.0](https://github.com/projectmesa/mesa/compare/v2.3.4...v2.4.0)
67
+
4
68
  # 2.3.4 (2024-09-04)
5
69
  ## Highlights
6
70
  Two fixes in our docs: The visualization tutorial started using an example model that wasn't compatible with Mesa 2.x anymore, and some relative links were broken. This release fixes both.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: Mesa
3
- Version: 2.3.4
3
+ Version: 2.4.0
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
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.9
18
18
  Classifier: Programming Language :: Python :: 3.10
19
19
  Classifier: Programming Language :: Python :: 3.11
20
20
  Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
21
22
  Classifier: Topic :: Scientific/Engineering
22
23
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
24
  Classifier: Topic :: Scientific/Engineering :: Artificial Life
@@ -55,7 +56,7 @@ Description-Content-Type: text/markdown
55
56
  | Meta | [![linting - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![Hatch project](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://github.com/pypa/hatch) |
56
57
  | Chat | [![chat](https://img.shields.io/matrix/project-mesa:matrix.org?label=chat&logo=Matrix)](https://matrix.to/#/#project-mesa:matrix.org) |
57
58
 
58
- *This is the `2.3.x-maintenance` branch. Example models for Mesa 2.x can be found [here](https://github.com/projectmesa/mesa-examples/tree/mesa-2.x/examples).*
59
+ *This is the `2.4.x-maintenance` branch. Example models for Mesa 2.x can be found [here](https://github.com/projectmesa/mesa-examples/tree/mesa-2.x/examples).*
59
60
 
60
61
  Mesa allows users to quickly create agent-based models using built-in
61
62
  core components (such as spatial grids and agent schedulers) or
@@ -101,13 +102,13 @@ For resources or help on using Mesa, check out the following:
101
102
 
102
103
  - [Intro to Mesa Tutorial](http://mesa.readthedocs.org/en/stable/tutorials/intro_tutorial.html) (An introductory model, the Boltzmann
103
104
  Wealth Model, for beginners or those new to Mesa.)
104
- - [Visualization Tutorial](https://mesa.readthedocs.io/en/stable/tutorials/visualization_tutorial.html) (An introduction into our Solara visualization)
105
+ - [Visualization Tutorial](https://mesa.readthedocs.io/stable/tutorials/visualization_tutorial.html) (An introduction into our Solara visualization)
105
106
  - [Complexity Explorer Tutorial](https://www.complexityexplorer.org/courses/172-agent-based-models-with-python-an-introduction-to-mesa) (An advanced-beginner model,
106
107
  SugarScape with Traders, with instructional videos)
107
108
  - [Mesa Examples](https://github.com/projectmesa/mesa-examples/tree/mesa-2.x/examples) (A repository of seminal ABMs using Mesa and
108
109
  examples of employing specific Mesa Features)
109
110
  - [Docs](http://mesa.readthedocs.org/) (Mesa's documentation, API and useful snippets)
110
- - [Development version docs](https://mesa.readthedocs.io/en/latest/) (the latest version docs if you're using a pre-release Mesa version)
111
+ - [Development version docs](https://mesa.readthedocs.io/latest/) (the latest version docs if you're using a pre-release Mesa version)
111
112
  - [Discussions](https://github.com/projectmesa/mesa/discussions) (GitHub threaded discussions about Mesa)
112
113
  - [Matrix Chat](https://matrix.to/#/#project-mesa:matrix.org) (Chat Forum via Matrix to talk about Mesa)
113
114
 
@@ -7,7 +7,7 @@
7
7
  | Meta | [![linting - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![Hatch project](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://github.com/pypa/hatch) |
8
8
  | Chat | [![chat](https://img.shields.io/matrix/project-mesa:matrix.org?label=chat&logo=Matrix)](https://matrix.to/#/#project-mesa:matrix.org) |
9
9
 
10
- *This is the `2.3.x-maintenance` branch. Example models for Mesa 2.x can be found [here](https://github.com/projectmesa/mesa-examples/tree/mesa-2.x/examples).*
10
+ *This is the `2.4.x-maintenance` branch. Example models for Mesa 2.x can be found [here](https://github.com/projectmesa/mesa-examples/tree/mesa-2.x/examples).*
11
11
 
12
12
  Mesa allows users to quickly create agent-based models using built-in
13
13
  core components (such as spatial grids and agent schedulers) or
@@ -53,13 +53,13 @@ For resources or help on using Mesa, check out the following:
53
53
 
54
54
  - [Intro to Mesa Tutorial](http://mesa.readthedocs.org/en/stable/tutorials/intro_tutorial.html) (An introductory model, the Boltzmann
55
55
  Wealth Model, for beginners or those new to Mesa.)
56
- - [Visualization Tutorial](https://mesa.readthedocs.io/en/stable/tutorials/visualization_tutorial.html) (An introduction into our Solara visualization)
56
+ - [Visualization Tutorial](https://mesa.readthedocs.io/stable/tutorials/visualization_tutorial.html) (An introduction into our Solara visualization)
57
57
  - [Complexity Explorer Tutorial](https://www.complexityexplorer.org/courses/172-agent-based-models-with-python-an-introduction-to-mesa) (An advanced-beginner model,
58
58
  SugarScape with Traders, with instructional videos)
59
59
  - [Mesa Examples](https://github.com/projectmesa/mesa-examples/tree/mesa-2.x/examples) (A repository of seminal ABMs using Mesa and
60
60
  examples of employing specific Mesa Features)
61
61
  - [Docs](http://mesa.readthedocs.org/) (Mesa's documentation, API and useful snippets)
62
- - [Development version docs](https://mesa.readthedocs.io/en/latest/) (the latest version docs if you're using a pre-release Mesa version)
62
+ - [Development version docs](https://mesa.readthedocs.io/latest/) (the latest version docs if you're using a pre-release Mesa version)
63
63
  - [Discussions](https://github.com/projectmesa/mesa/discussions) (GitHub threaded discussions about Mesa)
64
64
  - [Matrix Chat](https://matrix.to/#/#project-mesa:matrix.org) (Chat Forum via Matrix to talk about Mesa)
65
65
 
@@ -227,8 +227,9 @@ class WolfSheep(Model):
227
227
  patch.move_to(cell)
228
228
 
229
229
  def step(self):
230
- self.get_agents_of_type(Sheep).shuffle(inplace=True).do("step")
231
- self.get_agents_of_type(Wolf).shuffle(inplace=True).do("step")
230
+ """Run one step of the model."""
231
+ self.agents_by_type[Sheep].shuffle_do("step")
232
+ self.agents_by_type[Wolf].shuffle_do("step")
232
233
 
233
234
 
234
235
  if __name__ == "__main__":
@@ -0,0 +1,12 @@
1
+ [
2
+ {
3
+ "name": "Stable",
4
+ "version": "stable",
5
+ "url": "https://mesa.readthedocs.io/stable/"
6
+ },
7
+ {
8
+ "name": "Latest",
9
+ "version": "latest",
10
+ "url": "https://mesa.readthedocs.io/latest/"
11
+ }
12
+ ]
@@ -113,6 +113,8 @@ pygments_style = "gruvbox-dark"
113
113
 
114
114
  nb_execution_timeout = 60
115
115
  nb_execution_mode = "cache"
116
+ nb_execution_allow_errors = False
117
+ nb_execution_raise_on_error = True
116
118
 
117
119
  # -- Options for HTML output ----------------------------------------------
118
120
 
@@ -123,7 +125,13 @@ html_theme = "pydata_sphinx_theme"
123
125
  # Theme options are theme-specific and customize the look and feel of a theme
124
126
  # further. For a list of options available for each theme, see the
125
127
  # documentation.
126
- # html_theme_options = {}
128
+ html_theme_options = {
129
+ "navbar_start": ["navbar-logo", "version-switcher"], # Show switcher in navbar
130
+ "switcher": {
131
+ "json_url": "https://mesa.readthedocs.io/latest/_static/switcher.json", # URL of your switcher.json file
132
+ "version_match": version # Automatically matches the current version
133
+ }
134
+ }
127
135
 
128
136
  # Add any paths that contain custom themes here, relative to this directory.
129
137
  # html_theme_path = []
@@ -81,6 +81,7 @@ ABM features users have shared that you may want to use in your model
81
81
  Mesa Overview <overview>
82
82
  tutorials/intro_tutorial
83
83
  tutorials/visualization_tutorial
84
+ Migration guide <migration_guide>
84
85
  Best Practices <best-practices>
85
86
  How-to Guide <howto>
86
87
  API Documentation <apis/api_main>
@@ -0,0 +1,294 @@
1
+ # Mesa Migration guide
2
+ This guide contains breaking changes between major Mesa versions and how to resolve them.
3
+
4
+ Non-breaking changes aren't included, for those see our [Release history](https://github.com/projectmesa/mesa/releases).
5
+
6
+
7
+ ## Mesa 3.0
8
+ Mesa 3.0 introduces significant changes to core functionalities, including agent and model initialization, scheduling, and visualization. The guide below outlines these changes and provides instructions for migrating your existing Mesa projects to version 3.0.
9
+
10
+ _This guide is a work in progress. The development of it is tracked in [Issue #2233](https://github.com/projectmesa/mesa/issues/2233)._
11
+
12
+
13
+ ### Upgrade strategy
14
+ We recommend the following upgrade strategy:
15
+ - Update the the latest Mesa 2.x release (`mesa<3`).
16
+ - Update the the latest Mesa 3.0.x release (`mesa<3.1`).
17
+ - Update to the latest Mesa 3.x release (`mesa<4`).
18
+
19
+ With each update, resolve all errors and warnings, before updating to the next one.
20
+
21
+
22
+ ### Reserved and private variables
23
+ <!-- TODO: Update this section based on https://github.com/projectmesa/mesa/discussions/2230 -->
24
+
25
+ #### Reserved variables
26
+ Currently, we have reserved the following variables:
27
+ - Model: `agents`, `current_id`, `random`, `running`, `steps`, `time`.
28
+ - Agent: `unique_id`, `model`.
29
+
30
+ You can use (read) any reserved variable, but Mesa may update them automatically and rely on them, so modify/update at your own risk.
31
+
32
+ #### Private variables
33
+ Any variables starting with an underscore (`_`) are considered private and for Mesa's internal use. We might use any of those. Modifying or overwriting any private variable is at your own risk.
34
+
35
+ - Ref: [Discussion #2230](https://github.com/projectmesa/mesa/discussions/2230), [PR #2225](https://github.com/projectmesa/mesa/pull/2225)
36
+
37
+
38
+ ### Removal of `mesa.flat` namespace
39
+ The `mesa.flat` namespace is removed. Use the full namespace for your imports.
40
+
41
+ - Ref: [PR #2091](https://github.com/projectmesa/mesa/pull/2091)
42
+
43
+
44
+ ### Mandatory Model initialization with `super().__init__()`
45
+ In Mesa 3.0, it is now mandatory to call `super().__init__()` when initializing your model class. This ensures that all necessary Mesa model variables are correctly set up and agents are properly added to the model.
46
+
47
+ Make sure all your model classes explicitly call `super().__init__()` in their `__init__` method:
48
+
49
+ ```python
50
+ class MyModel(mesa.Model):
51
+ def __init__(self, *args, **kwargs):
52
+ super().__init__() # This is now required!
53
+ # Your model initialization code here
54
+ ```
55
+
56
+ This change ensures that all Mesa models are properly initialized, which is crucial for:
57
+ - Correctly adding agents to the model
58
+ - Setting up other essential Mesa model variables
59
+ - Maintaining consistency across all models
60
+
61
+ If you forget to call `super().__init__()`, you'll now see this error:
62
+
63
+ ```
64
+ RuntimeError: The Mesa Model class was not initialized. You must explicitly initialize the Model by calling super().__init__() on initialization.
65
+ ```
66
+
67
+ - Ref: [PR #2218](https://github.com/projectmesa/mesa/pull/2218), [PR #1928](https://github.com/projectmesa/mesa/pull/1928), Mesa-examples [PR #83](https://github.com/projectmesa/mesa-examples/pull/83)
68
+
69
+
70
+ ### Automatic assignment of `unique_id` to Agents
71
+ In Mesa 3.0, `unique_id` for agents is now automatically assigned, simplifying agent creation and ensuring unique IDs across all agents in a model.
72
+
73
+ 1. Remove `unique_id` from agent initialization:
74
+ ```python
75
+ # Old
76
+ agent = MyAgent(self.next_id(), self, ...)
77
+
78
+ # New
79
+ agent = MyAgent(self, ...)
80
+ ```
81
+ 2. `Model.next_id()` is deprecated and will always return 0. Remove any calls to this method.
82
+ 3. `unique_id` is now unique relative to a Model instance and starts from 1.
83
+ 4. If you previously used custom `unique_id` values, you'll need to store that information in a separate attribute.
84
+ 5. Deprecation warning: Initializing an agent with two arguments (`unique_id` and `model`) will raise a warning. The `unique_id` argument will be ignored.
85
+
86
+ - Ref: [PR #2226](https://github.com/projectmesa/mesa/pull/2226), [PR #2260](https://github.com/projectmesa/mesa/pull/2260), Mesa-examples [PR #194](https://github.com/projectmesa/mesa-examples/pull/194), [Issue #2213](https://github.com/projectmesa/mesa/issues/2213)
87
+
88
+
89
+ ### AgentSet and `Model.agents`
90
+ In Mesa 3.0, the Model class internally manages agents using several data structures:
91
+
92
+ - `self._agents`: A dictionary containing hard references to all agents, indexed by their `unique_id`.
93
+ - `self._agents_by_type`: A dictionary of AgentSets, organizing agents by their type.
94
+ - `self._all_agents`: An AgentSet containing all agents in the model.
95
+
96
+ These internal structures are used to efficiently manage and access agents. Users should interact with agents through the public `model.agents` property, which returns the `self._all_agents` AgentSet.
97
+
98
+ #### `Model.agents`
99
+ - Attempting to set `model.agents` now raises an `AttributeError` instead of a warning. This attribute is reserved for internal use by Mesa.
100
+ - If you were previously setting `model.agents` in your code, you must update it to use a different attribute name for custom agent storage.
101
+
102
+ For example, replace:
103
+ ```python
104
+ model.agents = my_custom_agents
105
+ ```
106
+
107
+ With:
108
+ ```python
109
+ model.custom_agents = my_custom_agents
110
+ ```
111
+
112
+
113
+ ### Time and schedulers
114
+ <!-- TODO general explanation-->
115
+
116
+ #### Automatic increase of the `steps` counter
117
+ The `steps` counter is now automatically increased. With each call to `Model.steps()` it's increased by 1, at the beginning of the step.
118
+
119
+ You can access it by `Model.steps`, and it's internally in the datacollector, batchrunner and the visualisation.
120
+
121
+ - Ref: [PR #2223](https://github.com/projectmesa/mesa/pull/2223), Mesa-examples [PR #161](https://github.com/projectmesa/mesa-examples/pull/161)
122
+
123
+ #### Removal of `Model._time` and rename `._steps`
124
+ - `Model._time` is removed. You can define your own time variable if needed.
125
+ - `Model._steps` steps is renamed to `Model.steps`.
126
+
127
+ #### Removal of `Model._advance_time()`
128
+ - The `Model._advance_time()` method is removed. This now happens automatically.
129
+
130
+ #### Replacing Schedulers with AgentSet functionality
131
+ The whole Time module in Mesa is deprecated, and all schedulers are being replaced with AgentSet functionality and the internal `Model.steps` counter. This allows much more flexibility in how to activate Agents and makes it explicit what's done exactly.
132
+
133
+ Here's how to replace each scheduler:
134
+
135
+ ##### BaseScheduler
136
+ Replace:
137
+ ```python
138
+ self.schedule = BaseScheduler(self)
139
+ self.schedule.step()
140
+ ```
141
+ With:
142
+ ```python
143
+ self.agents.do("step")
144
+ ```
145
+
146
+ ##### RandomActivation
147
+ Replace:
148
+ ```python
149
+ self.schedule = RandomActivation(self)
150
+ self.schedule.step()
151
+ ```
152
+ With:
153
+ ```python
154
+ self.agents.shuffle_do("step")
155
+ ```
156
+
157
+ ##### SimultaneousActivation
158
+ Replace:
159
+ ```python
160
+ self.schedule = SimultaneousActivation(self)
161
+ self.schedule.step()
162
+ ```
163
+ With:
164
+ ```python
165
+ self.agents.do("step")
166
+ self.agents.do("advance")
167
+ ```
168
+
169
+ ##### StagedActivation
170
+ Replace:
171
+ ```python
172
+ self.schedule = StagedActivation(self, ["stage1", "stage2", "stage3"])
173
+ self.schedule.step()
174
+ ```
175
+ With:
176
+ ```python
177
+ for stage in ["stage1", "stage2", "stage3"]:
178
+ self.agents.do(stage)
179
+ ```
180
+
181
+ If you were using the `shuffle` and/or `shuffle_between_stages` options:
182
+ ```python
183
+ stages = ["stage1", "stage2", "stage3"]
184
+ if shuffle:
185
+ self.random.shuffle(stages)
186
+ for stage in stages:
187
+ if shuffle_between_stages:
188
+ self.agents.shuffle_do(stage)
189
+ else:
190
+ self.agents.do(stage)
191
+ ```
192
+
193
+ ##### RandomActivationByType
194
+ Replace:
195
+ ```python
196
+ self.schedule = RandomActivationByType(self)
197
+ self.schedule.step()
198
+ ```
199
+ With:
200
+ ```python
201
+ for agent_class in self.agent_types:
202
+ self.agents_by_type[agent_class].shuffle_do("step")
203
+ ```
204
+
205
+ ###### Replacing `step_type`
206
+ The `RandomActivationByType` scheduler had a `step_type` method that allowed stepping only agents of a specific type. To replicate this functionality using AgentSet:
207
+
208
+ Replace:
209
+ ```python
210
+ self.schedule.step_type(AgentType)
211
+ ```
212
+
213
+ With:
214
+ ```python
215
+ self.agents_by_type[AgentType].shuffle_do("step")
216
+ ```
217
+
218
+ ##### General Notes
219
+
220
+ 1. The `Model.steps` counter is now automatically incremented. You don't need to manage it manually.
221
+ 2. If you were using `self.schedule.agents`, replace it with `self.agents`.
222
+ 3. If you were using `self.schedule.get_agent_count()`, replace it with `len(self.agents)`.
223
+ 4. If you were using `self.schedule.agents_by_type`, replace it with `self.agents_by_type`.
224
+ 5. Instead of `self.schedule.add()` and `self.schedule.remove()`, agents are now automatically added to and removed from the model's AgentSet when they are created or removed.
225
+
226
+ From now on you're now not bound by 5 distinct schedulers, but can mix and match any combination of AgentSet methods (`do`, `shuffle`, `select`, etc.) to get the desired Agent activation.
227
+
228
+ Ref: Original discussion [#1912](https://github.com/projectmesa/mesa/discussions/1912), decision discussion [#2231](https://github.com/projectmesa/mesa/discussions/2231), example updates [#183](https://github.com/projectmesa/mesa-examples/pull/183) and [#201](https://github.com/projectmesa/mesa-examples/pull/201), PR [#2306](https://github.com/projectmesa/mesa/pull/2306)
229
+
230
+ ### Visualisation
231
+
232
+ Mesa has adopted a new API for our frontend. If you already migrated to the experimental new SolaraViz you can still use
233
+ the import from mesa.experimental. Otherwise here is a list of things you need to change.
234
+
235
+ #### Model Initialization
236
+
237
+ 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()`.
238
+
239
+ #### Default space visualization
240
+
241
+ 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
242
+
243
+ ```python
244
+ # old
245
+ from mesa.experimental import SolaraViz
246
+
247
+ SolaraViz(model_cls, model_params, agent_portrayal=agent_portrayal)
248
+
249
+ # new
250
+ from mesa.visualization import SolaraViz, make_space_matplotlib
251
+
252
+ SolaraViz(model, components=[make_space_matplotlib(agent_portrayal)])
253
+ ```
254
+
255
+ #### Plotting "measures"
256
+
257
+ "Measure" plots also need to be made explicit here. Previously, measure could either be 1) A function that receives a model and returns a solara component or 2) A string or list of string of variables that are collected by the datacollector and are to be plotted as a line plot. 1) still works, but you can pass that function to "components" directly. 2) needs to explicitly call the `make_plot_measure()`function.
258
+
259
+ ```python
260
+ # old
261
+ from mesa.experimental import SolaraViz
262
+
263
+ def make_plot(model):
264
+ ...
265
+
266
+ SolaraViz(model_cls, model_params, measures=[make_plot, "foo", ["bar", "baz"]])
267
+
268
+ # new
269
+ from mesa.visualization import SolaraViz, make_plot_measure
270
+
271
+ SolaraViz(model, components=[make_plot, make_plot_measure("foo"), make_plot_measure("bar", "baz")])
272
+ ```
273
+
274
+ #### Plotting text
275
+
276
+ To plot model-dependent text the experimental SolaraViz provided a `make_text` function that wraps another functions that receives the model and turns its string return value into a solara text component. Again, this other function can now be passed directly to the new SolaraViz components array. It is okay if your function just returns a string.
277
+
278
+ ```python
279
+ # old
280
+ from mesa.experimental import SolaraViz, make_text
281
+
282
+ def show_steps(model):
283
+ return f"Steps: {model.steps}"
284
+
285
+ SolaraViz(model_cls, model_params, measures=make_text(show_steps))
286
+
287
+ # new
288
+ from mesa.visualisation import SolaraViz
289
+
290
+ def show_steps(model):
291
+ return f"Steps: {model.steps}"
292
+
293
+ SolaraViz(model, components=[show_steps])
294
+ ```
@@ -60,6 +60,55 @@ You should see agents 0-4, activated in random order. See the [tutorial](tutoria
60
60
 
61
61
  To bootstrap a new model install mesa and run `mesa startproject`
62
62
 
63
+ ### AgentSet and model.agents
64
+ Mesa 3.0 makes `model.agents` and the AgentSet class central in managing and activating agents.
65
+
66
+ #### model.agents
67
+ `model.agents` is an AgentSet containing all agents in the model. It's automatically updated when agents are added or removed:
68
+
69
+ ```python
70
+ # Get total number of agents
71
+ num_agents = len(model.agents)
72
+
73
+ # Iterate over all agents
74
+ for agent in model.agents:
75
+ print(agent.unique_id)
76
+ ```
77
+
78
+ #### AgentSet Functionality
79
+ AgentSet offers several methods for efficient agent management:
80
+
81
+ 1. **Selecting**: Filter agents based on criteria.
82
+ ```python
83
+ high_energy_agents = model.agents.select(lambda a: a.energy > 50)
84
+ ```
85
+ 2. **Shuffling and Sorting**: Randomize or order agents.
86
+ ```python
87
+ shuffled_agents = model.agents.shuffle()
88
+ sorted_agents = model.agents.sort(key="energy", ascending=False)
89
+ ```
90
+ 3. **Applying methods**: Execute methods on all agents.
91
+ ```python
92
+ model.agents.do("step")
93
+ model.agents.shuffle_do("move") # Shuffle then apply method
94
+ ```
95
+ 4. **Aggregating**: Compute aggregate values across agents.
96
+ ```python
97
+ avg_energy = model.agents.agg("energy", func=np.mean)
98
+ ```
99
+ 5. **Grouping**: Group agents by attributes.
100
+ ```python
101
+ grouped_agents = model.agents.groupby("species")
102
+
103
+ for _, agent_group in grouped_agents:
104
+ agent_group.shuffle_do()
105
+ species_counts = grouped_agents.count()
106
+ mean_age_by_group = grouped_agents.agg("age", np.mean)
107
+ ```
108
+ `model.agents` can also be accessed within a model instance using `self.agents`.
109
+
110
+ These are just some examples of using the AgentSet, there are many more possibilities
111
+
63
112
  ### Analysis modules
64
113
 
65
114
  If you're using modeling for research, you'll want a way to collect the data each model run generates. You'll probably also want to run the model multiple times, to see how some output changes with different parameters. Data collection and batch running are implemented in the appropriately-named analysis modules:
@@ -73,9 +73,9 @@ Most likely you created an ABM that has the code that you want to share in it, w
73
73
 
74
74
  **Sharing your package**
75
75
 
76
- > 1. Layout a new file structure to move the code into and then make sure it is callable from Mesa, in a simple, easy to understand way. For example, `from example_package import foo`. See [Creating the Scaffolding](https://python-packaging.readthedocs.io/en/latest/minimal.html#creating-the-scaffolding).
76
+ > 1. Layout a new file structure to move the code into and then make sure it is callable from Mesa, in a simple, easy to understand way. For example, `from example_package import foo`. See [Creating the Scaffolding](https://python-packaging.readthedocs.io/latest/minimal.html#creating-the-scaffolding).
77
77
  >
78
- > 2. [Pick a name](https://python-packaging.readthedocs.io/en/latest/minimal.html#picking-a-name).
78
+ > 2. [Pick a name](https://python-packaging.readthedocs.io/latest/minimal.html#picking-a-name).
79
79
  >
80
80
  > 3. [Create a repo on GitHub](https://help.github.com/articles/create-a-repo/).
81
81
  >
@@ -29,7 +29,7 @@
29
29
  "source": [
30
30
  "#### Grid Visualization\n",
31
31
  "\n",
32
- "To start with, let's have a visualization where we can watch the agents moving around the grid. For this, you will need to put your model code in a separate Python source file. For now, let us use the `MoneyModel` created in the [Introductory Tutorial](https://mesa.readthedocs.io/en/stable/tutorials/intro_tutorial.html) saved to `MoneyModel.py` file provided.\n",
32
+ "To start with, let's have a visualization where we can watch the agents moving around the grid. For this, you will need to put your model code in a separate Python source file. For now, let us use the `MoneyModel` created in the [Introductory Tutorial](https://mesa.readthedocs.io/stable/tutorials/intro_tutorial.html) saved to `MoneyModel.py` file provided.\n",
33
33
  "Next, in a new source file (e.g. `MoneyModel_Viz.py`) include the code shown in the following cells to run and avoid Jupyter compatibility issue."
34
34
  ]
35
35
  },
@@ -29,9 +29,9 @@
29
29
  "\n",
30
30
  "### More Tutorials: \n",
31
31
  "\n",
32
- "Visualization: There is a separate [visualization tutorial](https://mesa.readthedocs.io/en/stable/tutorials/visualization_tutorial.html) that will take users through building a visualization for this model (aka Boltzmann Wealth Model).\n",
32
+ "Visualization: There is a separate [visualization tutorial](https://mesa.readthedocs.io/stable/tutorials/visualization_tutorial.html) that will take users through building a visualization for this model (aka Boltzmann Wealth Model).\n",
33
33
  "\n",
34
- "Advanced Visualization (legacy): There is also an [advanced visualization tutorial](https://mesa.readthedocs.io/en/stable/tutorials/adv_tutorial_legacy.html) that will show users how to use the JavaScript based visualization option, which also uses this model as its base. "
34
+ "Advanced Visualization (legacy): There is also an [advanced visualization tutorial](https://mesa.readthedocs.io/stable/tutorials/adv_tutorial_legacy.html) that will show users how to use the JavaScript based visualization option, which also uses this model as its base. "
35
35
  ]
36
36
  },
37
37
  {
@@ -28,7 +28,7 @@
28
28
  "source": [
29
29
  "#### Grid Visualization\n",
30
30
  "\n",
31
- "To start with, let's have a visualization where we can watch the agents moving around the grid. Let us use the same `MoneyModel` created in the [Introductory Tutorial](https://mesa.readthedocs.io/en/stable/tutorials/intro_tutorial.html).\n"
31
+ "To start with, let's have a visualization where we can watch the agents moving around the grid. Let us use the same `MoneyModel` created in the [Introductory Tutorial](https://mesa.readthedocs.io/stable/tutorials/intro_tutorial.html).\n"
32
32
  ]
33
33
  },
34
34
  {
@@ -26,7 +26,7 @@ __all__ = [
26
26
  ]
27
27
 
28
28
  __title__ = "mesa"
29
- __version__ = "2.3.4"
29
+ __version__ = "2.4.0"
30
30
  __license__ = "Apache 2.0"
31
31
  _this_year = datetime.datetime.now(tz=datetime.timezone.utc).date().year
32
32
  __copyright__ = f"Copyright {_this_year} Project Mesa Team"