Mesa 2.4.0__py3-none-any.whl → 3.0.0__py3-none-any.whl

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 (110) hide show
  1. mesa/__init__.py +3 -5
  2. mesa/agent.py +105 -92
  3. mesa/batchrunner.py +55 -31
  4. mesa/datacollection.py +10 -14
  5. mesa/examples/README.md +37 -0
  6. mesa/examples/__init__.py +21 -0
  7. mesa/examples/advanced/epstein_civil_violence/Epstein Civil Violence.ipynb +116 -0
  8. mesa/examples/advanced/epstein_civil_violence/Readme.md +34 -0
  9. mesa/examples/advanced/epstein_civil_violence/__init__.py +0 -0
  10. mesa/examples/advanced/epstein_civil_violence/agents.py +164 -0
  11. mesa/examples/advanced/epstein_civil_violence/app.py +73 -0
  12. mesa/examples/advanced/epstein_civil_violence/model.py +114 -0
  13. mesa/examples/advanced/pd_grid/Readme.md +43 -0
  14. mesa/examples/advanced/pd_grid/__init__.py +0 -0
  15. mesa/examples/advanced/pd_grid/agents.py +50 -0
  16. mesa/examples/advanced/pd_grid/analysis.ipynb +228 -0
  17. mesa/examples/advanced/pd_grid/app.py +54 -0
  18. mesa/examples/advanced/pd_grid/model.py +71 -0
  19. mesa/examples/advanced/sugarscape_g1mt/Readme.md +64 -0
  20. mesa/examples/advanced/sugarscape_g1mt/__init__.py +0 -0
  21. mesa/examples/advanced/sugarscape_g1mt/agents.py +344 -0
  22. mesa/examples/advanced/sugarscape_g1mt/app.py +62 -0
  23. mesa/examples/advanced/sugarscape_g1mt/model.py +180 -0
  24. mesa/examples/advanced/sugarscape_g1mt/sugar-map.txt +50 -0
  25. mesa/examples/advanced/sugarscape_g1mt/tests.py +69 -0
  26. mesa/examples/advanced/wolf_sheep/Readme.md +57 -0
  27. mesa/examples/advanced/wolf_sheep/__init__.py +0 -0
  28. mesa/examples/advanced/wolf_sheep/agents.py +102 -0
  29. mesa/examples/advanced/wolf_sheep/app.py +84 -0
  30. mesa/examples/advanced/wolf_sheep/model.py +137 -0
  31. mesa/examples/basic/__init__.py +0 -0
  32. mesa/examples/basic/boid_flockers/Readme.md +22 -0
  33. mesa/examples/basic/boid_flockers/__init__.py +0 -0
  34. mesa/examples/basic/boid_flockers/agents.py +71 -0
  35. mesa/examples/basic/boid_flockers/app.py +58 -0
  36. mesa/examples/basic/boid_flockers/model.py +69 -0
  37. mesa/examples/basic/boltzmann_wealth_model/Readme.md +56 -0
  38. mesa/examples/basic/boltzmann_wealth_model/__init__.py +0 -0
  39. mesa/examples/basic/boltzmann_wealth_model/agents.py +31 -0
  40. mesa/examples/basic/boltzmann_wealth_model/app.py +74 -0
  41. mesa/examples/basic/boltzmann_wealth_model/model.py +43 -0
  42. mesa/examples/basic/boltzmann_wealth_model/st_app.py +115 -0
  43. mesa/examples/basic/conways_game_of_life/Readme.md +39 -0
  44. mesa/examples/basic/conways_game_of_life/__init__.py +0 -0
  45. mesa/examples/basic/conways_game_of_life/agents.py +47 -0
  46. mesa/examples/basic/conways_game_of_life/app.py +51 -0
  47. mesa/examples/basic/conways_game_of_life/model.py +31 -0
  48. mesa/examples/basic/conways_game_of_life/st_app.py +72 -0
  49. mesa/examples/basic/schelling/Readme.md +40 -0
  50. mesa/examples/basic/schelling/__init__.py +0 -0
  51. mesa/examples/basic/schelling/agents.py +26 -0
  52. mesa/examples/basic/schelling/analysis.ipynb +205 -0
  53. mesa/examples/basic/schelling/app.py +42 -0
  54. mesa/examples/basic/schelling/model.py +59 -0
  55. mesa/examples/basic/virus_on_network/Readme.md +61 -0
  56. mesa/examples/basic/virus_on_network/__init__.py +0 -0
  57. mesa/examples/basic/virus_on_network/agents.py +69 -0
  58. mesa/examples/basic/virus_on_network/app.py +114 -0
  59. mesa/examples/basic/virus_on_network/model.py +96 -0
  60. mesa/experimental/UserParam.py +18 -7
  61. mesa/experimental/__init__.py +10 -2
  62. mesa/experimental/cell_space/__init__.py +16 -1
  63. mesa/experimental/cell_space/cell.py +93 -23
  64. mesa/experimental/cell_space/cell_agent.py +117 -21
  65. mesa/experimental/cell_space/cell_collection.py +56 -19
  66. mesa/experimental/cell_space/discrete_space.py +92 -8
  67. mesa/experimental/cell_space/grid.py +33 -9
  68. mesa/experimental/cell_space/network.py +15 -10
  69. mesa/experimental/cell_space/voronoi.py +257 -0
  70. mesa/experimental/components/altair.py +11 -2
  71. mesa/experimental/components/matplotlib.py +132 -26
  72. mesa/experimental/devs/__init__.py +2 -0
  73. mesa/experimental/devs/eventlist.py +54 -15
  74. mesa/experimental/devs/examples/epstein_civil_violence.py +69 -38
  75. mesa/experimental/devs/examples/wolf_sheep.py +42 -43
  76. mesa/experimental/devs/simulator.py +57 -16
  77. mesa/experimental/{jupyter_viz.py → solara_viz.py} +151 -99
  78. mesa/model.py +136 -78
  79. mesa/space.py +208 -148
  80. mesa/time.py +63 -80
  81. mesa/visualization/__init__.py +25 -6
  82. mesa/visualization/components/__init__.py +83 -0
  83. mesa/visualization/components/altair_components.py +188 -0
  84. mesa/visualization/components/matplotlib_components.py +175 -0
  85. mesa/visualization/mpl_space_drawing.py +593 -0
  86. mesa/visualization/solara_viz.py +458 -0
  87. mesa/visualization/user_param.py +69 -0
  88. mesa/visualization/utils.py +9 -0
  89. {mesa-2.4.0.dist-info → mesa-3.0.0.dist-info}/METADATA +62 -17
  90. mesa-3.0.0.dist-info/RECORD +95 -0
  91. mesa-3.0.0.dist-info/licenses/LICENSE +202 -0
  92. mesa-2.4.0.dist-info/licenses/LICENSE → mesa-3.0.0.dist-info/licenses/NOTICE +2 -2
  93. mesa/cookiecutter-mesa/cookiecutter.json +0 -8
  94. mesa/cookiecutter-mesa/hooks/post_gen_project.py +0 -11
  95. mesa/cookiecutter-mesa/{{cookiecutter.snake}}/README.md +0 -4
  96. mesa/cookiecutter-mesa/{{cookiecutter.snake}}/run.pytemplate +0 -3
  97. mesa/cookiecutter-mesa/{{cookiecutter.snake}}/setup.pytemplate +0 -11
  98. mesa/cookiecutter-mesa/{{cookiecutter.snake}}/{{cookiecutter.snake}}/model.pytemplate +0 -60
  99. mesa/cookiecutter-mesa/{{cookiecutter.snake}}/{{cookiecutter.snake}}/server.pytemplate +0 -36
  100. mesa/flat/__init__.py +0 -6
  101. mesa/flat/visualization.py +0 -5
  102. mesa/main.py +0 -63
  103. mesa/visualization/ModularVisualization.py +0 -1
  104. mesa/visualization/TextVisualization.py +0 -1
  105. mesa/visualization/UserParam.py +0 -1
  106. mesa/visualization/modules.py +0 -1
  107. mesa-2.4.0.dist-info/RECORD +0 -45
  108. /mesa/{cookiecutter-mesa/{{cookiecutter.snake}}/{{cookiecutter.snake}} → examples/advanced}/__init__.py +0 -0
  109. {mesa-2.4.0.dist-info → mesa-3.0.0.dist-info}/WHEEL +0 -0
  110. {mesa-2.4.0.dist-info → mesa-3.0.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,175 @@
1
+ """Matplotlib based solara components for visualization MESA spaces and plots."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import warnings
6
+ from collections.abc import Callable
7
+
8
+ import matplotlib.pyplot as plt
9
+ import solara
10
+ from matplotlib.figure import Figure
11
+
12
+ from mesa.visualization.mpl_space_drawing import draw_space
13
+ from mesa.visualization.utils import update_counter
14
+
15
+
16
+ def make_space_matplotlib(*args, **kwargs): # noqa: D103
17
+ warnings.warn(
18
+ "make_space_matplotlib has been renamed to make_mpl_space_component",
19
+ DeprecationWarning,
20
+ stacklevel=2,
21
+ )
22
+ return make_mpl_space_component(*args, **kwargs)
23
+
24
+
25
+ def make_mpl_space_component(
26
+ agent_portrayal: Callable | None = None,
27
+ propertylayer_portrayal: dict | None = None,
28
+ post_process: Callable | None = None,
29
+ **space_drawing_kwargs,
30
+ ) -> SpaceMatplotlib:
31
+ """Create a Matplotlib-based space visualization component.
32
+
33
+ Args:
34
+ agent_portrayal: Function to portray agents.
35
+ propertylayer_portrayal: Dictionary of PropertyLayer portrayal specifications
36
+ post_process : a callable that will be called with the Axes instance. Allows for fine tuning plots (e.g., control ticks)
37
+ space_drawing_kwargs : additional keyword arguments to be passed on to the underlying space drawer function. See
38
+ the functions for drawing the various spaces for further details.
39
+
40
+ ``agent_portrayal`` is called with an agent and should return a dict. Valid fields in this dict are "color",
41
+ "size", "marker", "zorder", alpha, linewidths, and edgecolors. Other field are ignored and will result in a user warning.
42
+
43
+ Returns:
44
+ function: A function that creates a SpaceMatplotlib component
45
+ """
46
+ if agent_portrayal is None:
47
+
48
+ def agent_portrayal(a):
49
+ return {}
50
+
51
+ def MakeSpaceMatplotlib(model):
52
+ return SpaceMatplotlib(
53
+ model,
54
+ agent_portrayal,
55
+ propertylayer_portrayal,
56
+ post_process=post_process,
57
+ **space_drawing_kwargs,
58
+ )
59
+
60
+ return MakeSpaceMatplotlib
61
+
62
+
63
+ @solara.component
64
+ def SpaceMatplotlib(
65
+ model,
66
+ agent_portrayal,
67
+ propertylayer_portrayal,
68
+ dependencies: list[any] | None = None,
69
+ post_process: Callable | None = None,
70
+ **space_drawing_kwargs,
71
+ ):
72
+ """Create a Matplotlib-based space visualization component."""
73
+ update_counter.get()
74
+
75
+ space = getattr(model, "grid", None)
76
+ if space is None:
77
+ space = getattr(model, "space", None)
78
+
79
+ fig = Figure()
80
+ ax = fig.add_subplot()
81
+
82
+ draw_space(
83
+ space,
84
+ agent_portrayal,
85
+ propertylayer_portrayal=propertylayer_portrayal,
86
+ ax=ax,
87
+ **space_drawing_kwargs,
88
+ )
89
+
90
+ if post_process is not None:
91
+ post_process(ax)
92
+
93
+ solara.FigureMatplotlib(
94
+ fig, format="png", bbox_inches="tight", dependencies=dependencies
95
+ )
96
+
97
+
98
+ def make_plot_measure(*args, **kwargs): # noqa: D103
99
+ warnings.warn(
100
+ "make_plot_measure has been renamed to make_plot_component",
101
+ DeprecationWarning,
102
+ stacklevel=2,
103
+ )
104
+ return make_mpl_plot_component(*args, **kwargs)
105
+
106
+
107
+ def make_mpl_plot_component(
108
+ measure: str | dict[str, str] | list[str] | tuple[str],
109
+ post_process: Callable | None = None,
110
+ save_format="png",
111
+ ):
112
+ """Create a plotting function for a specified measure.
113
+
114
+ Args:
115
+ measure (str | dict[str, str] | list[str] | tuple[str]): Measure(s) to plot.
116
+ post_process: a user-specified callable to do post-processing called with the Axes instance.
117
+ save_format: save format of figure in solara backend
118
+
119
+ Returns:
120
+ function: A function that creates a PlotMatplotlib component.
121
+ """
122
+
123
+ def MakePlotMatplotlib(model):
124
+ return PlotMatplotlib(
125
+ model, measure, post_process=post_process, save_format=save_format
126
+ )
127
+
128
+ return MakePlotMatplotlib
129
+
130
+
131
+ @solara.component
132
+ def PlotMatplotlib(
133
+ model,
134
+ measure,
135
+ dependencies: list[any] | None = None,
136
+ post_process: Callable | None = None,
137
+ save_format="png",
138
+ ):
139
+ """Create a Matplotlib-based plot for a measure or measures.
140
+
141
+ Args:
142
+ model (mesa.Model): The model instance.
143
+ measure (str | dict[str, str] | list[str] | tuple[str]): Measure(s) to plot.
144
+ dependencies (list[any] | None): Optional dependencies for the plot.
145
+ post_process: a user-specified callable to do post-processing called with the Axes instance.
146
+ save_format: format used for saving the figure.
147
+
148
+ Returns:
149
+ solara.FigureMatplotlib: A component for rendering the plot.
150
+ """
151
+ update_counter.get()
152
+ fig = Figure()
153
+ ax = fig.subplots()
154
+ df = model.datacollector.get_model_vars_dataframe()
155
+ if isinstance(measure, str):
156
+ ax.plot(df.loc[:, measure])
157
+ ax.set_ylabel(measure)
158
+ elif isinstance(measure, dict):
159
+ for m, color in measure.items():
160
+ ax.plot(df.loc[:, m], label=m, color=color)
161
+ ax.legend(loc="best")
162
+ elif isinstance(measure, list | tuple):
163
+ for m in measure:
164
+ ax.plot(df.loc[:, m], label=m)
165
+ ax.legend(loc="best")
166
+
167
+ if post_process is not None:
168
+ post_process(ax)
169
+
170
+ ax.set_xlabel("Step")
171
+ # Set integer x axis
172
+ ax.xaxis.set_major_locator(plt.MaxNLocator(integer=True))
173
+ solara.FigureMatplotlib(
174
+ fig, format=save_format, bbox_inches="tight", dependencies=dependencies
175
+ )