Mesa 3.1.0__py3-none-any.whl → 3.1.0.dev0__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.
- mesa/__init__.py +3 -3
- mesa/agent.py +0 -48
- mesa/batchrunner.py +1 -14
- mesa/datacollection.py +6 -1
- mesa/examples/__init__.py +2 -2
- mesa/examples/advanced/epstein_civil_violence/app.py +0 -5
- mesa/examples/advanced/pd_grid/app.py +0 -5
- mesa/examples/advanced/sugarscape_g1mt/app.py +2 -7
- mesa/examples/basic/boid_flockers/app.py +0 -5
- mesa/examples/basic/boltzmann_wealth_model/app.py +5 -8
- mesa/examples/basic/boltzmann_wealth_model/st_app.py +1 -1
- mesa/examples/basic/conways_game_of_life/app.py +0 -5
- mesa/examples/basic/conways_game_of_life/st_app.py +2 -2
- mesa/examples/basic/schelling/app.py +0 -5
- mesa/examples/basic/virus_on_network/app.py +0 -5
- mesa/experimental/UserParam.py +67 -0
- mesa/experimental/__init__.py +10 -17
- mesa/experimental/cell_space/__init__.py +7 -19
- mesa/experimental/cell_space/cell.py +37 -22
- mesa/experimental/cell_space/cell_agent.py +1 -12
- mesa/experimental/cell_space/cell_collection.py +3 -18
- mesa/experimental/cell_space/discrete_space.py +64 -15
- mesa/experimental/cell_space/grid.py +4 -74
- mesa/experimental/cell_space/network.py +1 -13
- mesa/experimental/cell_space/voronoi.py +1 -13
- mesa/experimental/components/altair.py +81 -0
- mesa/experimental/components/matplotlib.py +242 -0
- mesa/experimental/devs/__init__.py +2 -20
- mesa/experimental/devs/eventlist.py +1 -19
- mesa/experimental/devs/examples/epstein_civil_violence.py +305 -0
- mesa/experimental/devs/examples/wolf_sheep.py +250 -0
- mesa/experimental/devs/simulator.py +8 -24
- mesa/experimental/solara_viz.py +453 -0
- mesa/model.py +23 -17
- mesa/visualization/__init__.py +2 -2
- mesa/visualization/mpl_space_drawing.py +2 -2
- mesa/visualization/solara_viz.py +5 -23
- {mesa-3.1.0.dist-info → mesa-3.1.0.dev0.dist-info}/METADATA +1 -1
- {mesa-3.1.0.dist-info → mesa-3.1.0.dev0.dist-info}/RECORD +43 -43
- {mesa-3.1.0.dist-info → mesa-3.1.0.dev0.dist-info}/WHEEL +1 -1
- mesa/experimental/cell_space/property_layer.py +0 -444
- mesa/experimental/mesa_signals/__init__.py +0 -23
- mesa/experimental/mesa_signals/mesa_signal.py +0 -485
- mesa/experimental/mesa_signals/observable_collections.py +0 -133
- mesa/experimental/mesa_signals/signals_util.py +0 -52
- mesa/mesa_logging.py +0 -190
- {mesa-3.1.0.dist-info → mesa-3.1.0.dev0.dist-info}/entry_points.txt +0 -0
- {mesa-3.1.0.dist-info → mesa-3.1.0.dev0.dist-info}/licenses/LICENSE +0 -0
- {mesa-3.1.0.dist-info → mesa-3.1.0.dev0.dist-info}/licenses/NOTICE +0 -0
mesa/mesa_logging.py
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
"""This provides logging functionality for MESA.
|
|
2
|
-
|
|
3
|
-
It is modeled on the default `logging approach that comes with Python <https://docs.python.org/library/logging.html>`_.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
import inspect
|
|
9
|
-
import logging
|
|
10
|
-
from functools import wraps
|
|
11
|
-
from logging import DEBUG, INFO
|
|
12
|
-
|
|
13
|
-
__all__ = [
|
|
14
|
-
"DEBUG",
|
|
15
|
-
"DEFAULT_LEVEL",
|
|
16
|
-
"INFO",
|
|
17
|
-
"LOGGER_NAME",
|
|
18
|
-
"function_logger",
|
|
19
|
-
"get_module_logger",
|
|
20
|
-
"get_rootlogger",
|
|
21
|
-
"log_to_stderr",
|
|
22
|
-
"method_logger",
|
|
23
|
-
]
|
|
24
|
-
LOGGER_NAME = "MESA"
|
|
25
|
-
DEFAULT_LEVEL = DEBUG
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def create_module_logger(name: str | None = None):
|
|
29
|
-
"""Helper function for creating a module logger.
|
|
30
|
-
|
|
31
|
-
Args:
|
|
32
|
-
name (str): The name to be given to the logger. If the name is None, the name defaults to the name of the module.
|
|
33
|
-
|
|
34
|
-
"""
|
|
35
|
-
if name is None:
|
|
36
|
-
frm = inspect.stack()[1]
|
|
37
|
-
mod = inspect.getmodule(frm[0])
|
|
38
|
-
name = mod.__name__
|
|
39
|
-
logger = logging.getLogger(f"{LOGGER_NAME}.{name}")
|
|
40
|
-
|
|
41
|
-
_module_loggers[name] = logger
|
|
42
|
-
return logger
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def get_module_logger(name: str):
|
|
46
|
-
"""Helper function for getting the module logger.
|
|
47
|
-
|
|
48
|
-
Args:
|
|
49
|
-
name (str): The name of the module in which the method being decorated is located
|
|
50
|
-
|
|
51
|
-
"""
|
|
52
|
-
try:
|
|
53
|
-
logger = _module_loggers[name]
|
|
54
|
-
except KeyError:
|
|
55
|
-
logger = create_module_logger(name)
|
|
56
|
-
|
|
57
|
-
return logger
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
_rootlogger = None
|
|
61
|
-
_module_loggers = {}
|
|
62
|
-
_logger = get_module_logger(__name__)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
class MESAColorFormatter(logging.Formatter):
|
|
66
|
-
"""Custom formatter for color based formatting."""
|
|
67
|
-
|
|
68
|
-
grey = "\x1b[38;20m"
|
|
69
|
-
green = "\x1b[32m"
|
|
70
|
-
yellow = "\x1b[33;20m"
|
|
71
|
-
red = "\x1b[31;20m"
|
|
72
|
-
bold_red = "\x1b[31;1m"
|
|
73
|
-
reset = "\x1b[0m"
|
|
74
|
-
format = (
|
|
75
|
-
"[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s [%(filename)s:%(lineno)d]"
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
FORMATS = {
|
|
79
|
-
logging.DEBUG: grey + format + reset,
|
|
80
|
-
logging.INFO: green + format + reset,
|
|
81
|
-
logging.WARNING: yellow + format + reset,
|
|
82
|
-
logging.ERROR: red + format + reset,
|
|
83
|
-
logging.CRITICAL: bold_red + format + reset,
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
def format(self, record):
|
|
87
|
-
"""Format record."""
|
|
88
|
-
log_fmt = self.FORMATS.get(record.levelno)
|
|
89
|
-
formatter = logging.Formatter(log_fmt)
|
|
90
|
-
return formatter.format(record)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
def method_logger(name: str):
|
|
94
|
-
"""Decorator for adding logging to a method.
|
|
95
|
-
|
|
96
|
-
Args:
|
|
97
|
-
name (str): The name of the module in which the method being decorated is located
|
|
98
|
-
|
|
99
|
-
"""
|
|
100
|
-
logger = get_module_logger(name)
|
|
101
|
-
classname = inspect.getouterframes(inspect.currentframe())[1][3]
|
|
102
|
-
|
|
103
|
-
def real_decorator(func):
|
|
104
|
-
@wraps(func)
|
|
105
|
-
def wrapper(*args, **kwargs):
|
|
106
|
-
# hack, because log is applied to methods, we can get
|
|
107
|
-
# object instance as first arguments in args
|
|
108
|
-
logger.debug(
|
|
109
|
-
f"calling {classname}.{func.__name__} with {args[1::]} and {kwargs}"
|
|
110
|
-
)
|
|
111
|
-
res = func(*args, **kwargs)
|
|
112
|
-
return res
|
|
113
|
-
|
|
114
|
-
return wrapper
|
|
115
|
-
|
|
116
|
-
return real_decorator
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
def function_logger(name):
|
|
120
|
-
"""Decorator for adding logging to a Function.
|
|
121
|
-
|
|
122
|
-
Args:
|
|
123
|
-
name (str): The name of the module in which the function being decorated is located
|
|
124
|
-
|
|
125
|
-
"""
|
|
126
|
-
logger = get_module_logger(name)
|
|
127
|
-
|
|
128
|
-
def real_decorator(func):
|
|
129
|
-
@wraps(func)
|
|
130
|
-
def wrapper(*args, **kwargs):
|
|
131
|
-
logger.debug(f"calling {func.__name__} with {args} and {kwargs}")
|
|
132
|
-
res = func(*args, **kwargs)
|
|
133
|
-
return res
|
|
134
|
-
|
|
135
|
-
return wrapper
|
|
136
|
-
|
|
137
|
-
return real_decorator
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
def get_rootlogger():
|
|
141
|
-
"""Returns root logger used by MESA.
|
|
142
|
-
|
|
143
|
-
Returns:
|
|
144
|
-
the root logger of MESA
|
|
145
|
-
|
|
146
|
-
"""
|
|
147
|
-
global _rootlogger # noqa: PLW0603
|
|
148
|
-
|
|
149
|
-
if not _rootlogger:
|
|
150
|
-
_rootlogger = logging.getLogger(LOGGER_NAME)
|
|
151
|
-
_rootlogger.handlers = []
|
|
152
|
-
_rootlogger.addHandler(logging.NullHandler())
|
|
153
|
-
_rootlogger.setLevel(DEBUG)
|
|
154
|
-
|
|
155
|
-
return _rootlogger
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
def log_to_stderr(level: int | None = None, pass_root_logger_level: bool = False):
|
|
159
|
-
"""Turn on logging and add a handler which prints to stderr.
|
|
160
|
-
|
|
161
|
-
Args:
|
|
162
|
-
level: minimum level of the messages that will be logged
|
|
163
|
-
pass_root_logger_level: bool, optional. Default False
|
|
164
|
-
if True, all module loggers will be set to the same logging level as the root logger.
|
|
165
|
-
|
|
166
|
-
"""
|
|
167
|
-
if not level:
|
|
168
|
-
level = DEFAULT_LEVEL
|
|
169
|
-
|
|
170
|
-
logger = get_rootlogger()
|
|
171
|
-
|
|
172
|
-
# avoid creation of multiple stream handlers for logging to console
|
|
173
|
-
for entry in logger.handlers:
|
|
174
|
-
if (isinstance(entry, logging.StreamHandler)) and (
|
|
175
|
-
isinstance(entry.formatter, MESAColorFormatter)
|
|
176
|
-
):
|
|
177
|
-
return logger
|
|
178
|
-
|
|
179
|
-
formatter = MESAColorFormatter()
|
|
180
|
-
handler = logging.StreamHandler()
|
|
181
|
-
handler.setLevel(level)
|
|
182
|
-
handler.setFormatter(formatter)
|
|
183
|
-
logger.addHandler(handler)
|
|
184
|
-
logger.propagate = False
|
|
185
|
-
|
|
186
|
-
if pass_root_logger_level:
|
|
187
|
-
for _, mod_logger in _module_loggers.items():
|
|
188
|
-
mod_logger.setLevel(level)
|
|
189
|
-
|
|
190
|
-
return logger
|
|
File without changes
|
|
File without changes
|
|
File without changes
|