Mesa 3.2.0.dev0__py3-none-any.whl → 3.3.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 (58) hide show
  1. mesa/__init__.py +1 -1
  2. mesa/agent.py +9 -7
  3. mesa/datacollection.py +1 -1
  4. mesa/examples/README.md +1 -1
  5. mesa/examples/__init__.py +2 -0
  6. mesa/examples/advanced/alliance_formation/Readme.md +50 -0
  7. mesa/examples/advanced/alliance_formation/__init__ .py +0 -0
  8. mesa/examples/advanced/alliance_formation/agents.py +20 -0
  9. mesa/examples/advanced/alliance_formation/app.py +71 -0
  10. mesa/examples/advanced/alliance_formation/model.py +184 -0
  11. mesa/examples/advanced/epstein_civil_violence/app.py +11 -11
  12. mesa/examples/advanced/pd_grid/Readme.md +4 -6
  13. mesa/examples/advanced/pd_grid/app.py +10 -11
  14. mesa/examples/advanced/sugarscape_g1mt/Readme.md +4 -5
  15. mesa/examples/advanced/sugarscape_g1mt/app.py +34 -16
  16. mesa/examples/advanced/wolf_sheep/Readme.md +2 -17
  17. mesa/examples/advanced/wolf_sheep/app.py +21 -18
  18. mesa/examples/basic/boid_flockers/Readme.md +6 -1
  19. mesa/examples/basic/boid_flockers/app.py +15 -11
  20. mesa/examples/basic/boltzmann_wealth_model/Readme.md +2 -12
  21. mesa/examples/basic/boltzmann_wealth_model/app.py +39 -32
  22. mesa/examples/basic/conways_game_of_life/Readme.md +1 -9
  23. mesa/examples/basic/conways_game_of_life/app.py +13 -16
  24. mesa/examples/basic/schelling/Readme.md +2 -10
  25. mesa/examples/basic/schelling/agents.py +9 -3
  26. mesa/examples/basic/schelling/app.py +50 -3
  27. mesa/examples/basic/schelling/model.py +2 -0
  28. mesa/examples/basic/schelling/resources/blue_happy.png +0 -0
  29. mesa/examples/basic/schelling/resources/blue_unhappy.png +0 -0
  30. mesa/examples/basic/schelling/resources/orange_happy.png +0 -0
  31. mesa/examples/basic/schelling/resources/orange_unhappy.png +0 -0
  32. mesa/examples/basic/virus_on_network/Readme.md +0 -4
  33. mesa/examples/basic/virus_on_network/app.py +31 -14
  34. mesa/experimental/__init__.py +2 -2
  35. mesa/experimental/continuous_space/continuous_space.py +1 -1
  36. mesa/experimental/meta_agents/__init__.py +25 -0
  37. mesa/experimental/meta_agents/meta_agent.py +387 -0
  38. mesa/model.py +3 -3
  39. mesa/space.py +4 -1
  40. mesa/visualization/__init__.py +2 -0
  41. mesa/visualization/backends/__init__.py +23 -0
  42. mesa/visualization/backends/abstract_renderer.py +97 -0
  43. mesa/visualization/backends/altair_backend.py +440 -0
  44. mesa/visualization/backends/matplotlib_backend.py +419 -0
  45. mesa/visualization/components/__init__.py +28 -8
  46. mesa/visualization/components/altair_components.py +86 -0
  47. mesa/visualization/components/matplotlib_components.py +4 -2
  48. mesa/visualization/components/portrayal_components.py +120 -0
  49. mesa/visualization/mpl_space_drawing.py +292 -129
  50. mesa/visualization/solara_viz.py +274 -32
  51. mesa/visualization/space_drawers.py +797 -0
  52. mesa/visualization/space_renderer.py +399 -0
  53. {mesa-3.2.0.dev0.dist-info → mesa-3.3.0.dist-info}/METADATA +13 -4
  54. {mesa-3.2.0.dev0.dist-info → mesa-3.3.0.dist-info}/RECORD +57 -40
  55. mesa/examples/advanced/sugarscape_g1mt/tests.py +0 -69
  56. {mesa-3.2.0.dev0.dist-info → mesa-3.3.0.dist-info}/WHEEL +0 -0
  57. {mesa-3.2.0.dev0.dist-info → mesa-3.3.0.dist-info}/licenses/LICENSE +0 -0
  58. {mesa-3.2.0.dev0.dist-info → mesa-3.3.0.dist-info}/licenses/NOTICE +0 -0
@@ -0,0 +1,120 @@
1
+ """Portrayal Components Module.
2
+
3
+ This module defines data structures for styling visual elements in Mesa agent-based model visualizations.
4
+ It provides user-facing classes to specify how agents and property layers should appear in the rendered space.
5
+
6
+ Classes:
7
+ 1. AgentPortrayalStyle: Controls the appearance of individual agents (e.g., color, shape, size, etc.).
8
+ 2. PropertyLayerStyle: Controls the appearance of background property layers (e.g., color gradients or uniform fills).
9
+
10
+ These components are designed to be passed into Mesa visualizations to customize and standardize how data is presented.
11
+ """
12
+
13
+ from dataclasses import dataclass
14
+ from typing import Any
15
+
16
+ ColorLike = str | tuple | int | float
17
+
18
+
19
+ @dataclass
20
+ class AgentPortrayalStyle:
21
+ """Represents the visual styling options for an agent in a visualization.
22
+
23
+ User facing component to control how agents are drawn.
24
+ Allows specifying properties like color, size,
25
+ marker shape, position, and other plot attributes.
26
+
27
+ x, y are determined automatically according to the agent's type
28
+ (normal/CellAgent) and position in the space if not manually declared.
29
+
30
+ Example:
31
+ >>> def agent_portrayal(agent):
32
+ >>> return AgentPortrayalStyle(
33
+ >>> x=agent.cell.coordinate[0],
34
+ >>> y=agent.cell.coordinate[1],
35
+ >>> color="red",
36
+ >>> marker="o",
37
+ >>> size=20,
38
+ >>> zorder=2,
39
+ >>> alpha=0.8,
40
+ >>> edgecolors="black",
41
+ >>> linewidths=1.5
42
+ >>> )
43
+ >>>
44
+ >>> # or for a default agent portrayal
45
+ >>> def agent_portrayal(agent):
46
+ >>> return AgentPortrayalStyle()
47
+ """
48
+
49
+ x: float | None = None
50
+ y: float | None = None
51
+ color: ColorLike | None = "tab:blue"
52
+ marker: str | None = "o"
53
+ size: int | float | None = 50
54
+ zorder: int | None = 1
55
+ alpha: float | None = 1.0
56
+ edgecolors: str | tuple | None = None
57
+ linewidths: float | int | None = 1.0
58
+
59
+ def update(self, *updates_fields: tuple[str, Any]):
60
+ """Updates attributes from variable (field_name, new_value) tuple arguments.
61
+
62
+ Example:
63
+ >>> def agent_portrayal(agent):
64
+ >>> primary_style = AgentPortrayalStyle(color="blue", marker="^", size=10, x=agent.pos[0], y=agent.pos[1])
65
+ >>> if agent.type == 1:
66
+ >>> primary_style.update(("color", "red"), ("size", 30))
67
+ >>> return primary_style
68
+ """
69
+ for field_to_change, field_to_change_to in updates_fields:
70
+ if hasattr(self, field_to_change):
71
+ setattr(self, field_to_change, field_to_change_to)
72
+ else:
73
+ raise AttributeError(
74
+ f"'{type(self).__name__}' object has no attribute '{field_to_change}'"
75
+ )
76
+
77
+ def __post_init__(self):
78
+ """Validate that color and size are non-negative."""
79
+ if isinstance(self.color, int | float) and self.color < 0:
80
+ raise ValueError("Scalar color values must be non-negative")
81
+ if isinstance(self.size, int | float) and self.size < 0:
82
+ raise ValueError("Size must be a non-negative number")
83
+
84
+
85
+ @dataclass
86
+ class PropertyLayerStyle:
87
+ """Represents the visual styling options for a property layer in a visualization.
88
+
89
+ User facing component to control how property layers are drawn.
90
+ Allows specifying properties like colormap, single color, value limits
91
+ (vmin, vmax), transparency (alpha) and colorbar visibility.
92
+
93
+ Note: vmin and vmax are the lower and upper bounds for the colorbar and the data is
94
+ normalized between these values for color/colormap rendering. If they are not
95
+ declared the values are automatically determined from the data range.
96
+
97
+ Note: You can specify either a 'colormap' (for varying data) or a single
98
+ 'color' (for a uniform layer appearance), but not both simultaneously.
99
+
100
+ Example:
101
+ >>> def propertylayer_portrayal(layer):
102
+ >>> return PropertyLayerStyle(colormap="viridis", vmin=0, vmax=100, alpha=0.5, colorbar=True)
103
+ >>> # or for a uniform color layer
104
+ >>> def propertylayer_portrayal(layer):
105
+ >>> return PropertyLayerStyle(color="lightblue", alpha=0.8, colorbar=False)
106
+ """
107
+
108
+ colormap: str | None = None
109
+ color: str | None = None
110
+ alpha: float = 0.8
111
+ colorbar: bool = True
112
+ vmin: float | None = None
113
+ vmax: float | None = None
114
+
115
+ def __post_init__(self):
116
+ """Validate that color and colormap are not simultaneously specified."""
117
+ if self.color is not None and self.colormap is not None:
118
+ raise ValueError("Specify either 'color' or 'colormap', not both.")
119
+ if self.color is None and self.colormap is None:
120
+ raise ValueError("Specify one of 'color' or 'colormap'")