Skip to content

Commit

Permalink
Update some DeprecationWarnings to note they are removed in Mesa 3.1 (#…
Browse files Browse the repository at this point in the history
…2481)

This improves some of the DeprecationWarnings to make it explicit that certain features will be removed in Mesa 3.1. This communicated this clearly in line with our recommend upgrade strategy  https://github.com/projectmesa/mesa/blob/main/docs/migration_guide.md#upgrade-strategy.
  • Loading branch information
EwoutH authored Nov 11, 2024
1 parent 617be77 commit 8ae9b22
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/migration_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ You can access it by `Model.steps`, and it's internally in the datacollector, ba
- The `Model._advance_time()` method is removed. This now happens automatically.

#### Replacing Schedulers with AgentSet functionality
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.
The whole Time module in Mesa is deprecated and will be removed in Mesa 3.1. All schedulers should be 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.

Here's how to replace each scheduler:

Expand Down
7 changes: 4 additions & 3 deletions mesa/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def select(
"""
if n is not None:
warnings.warn(
"The parameter 'n' is deprecated. Use 'at_most' instead.",
"The parameter 'n' is deprecated and will be removed in Mesa 3.1. Use 'at_most' instead.",
DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -287,8 +287,9 @@ def do(self, method: str | Callable, *args, **kwargs) -> AgentSet:
return_results = False
else:
warnings.warn(
"Using return_results is deprecated. Use AgenSet.do in case of return_results=False, and "
"AgentSet.map in case of return_results=True",
"Using return_results is deprecated and will be removed in Mesa 3.1."
"Use AgenSet.do in case of return_results=False, and AgentSet.map in case of return_results=True",
DeprecationWarning,
stacklevel=2,
)

Expand Down
8 changes: 4 additions & 4 deletions mesa/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _wrapped_step(self, *args: Any, **kwargs: Any) -> None:

def next_id(self) -> int: # noqa: D102
warnings.warn(
"using model.next_id() is deprecated. Agents track their unique ID automatically",
"using model.next_id() is deprecated and will be removed in Mesa 3.1. Agents track their unique ID automatically",
DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -146,8 +146,8 @@ def agents_by_type(self) -> dict[type[Agent], AgentSet]:
def get_agents_of_type(self, agenttype: type[Agent]) -> AgentSet:
"""Deprecated: Retrieves an AgentSet containing all agents of the specified type."""
warnings.warn(
f"Model.get_agents_of_type() is deprecated, please replace get_agents_of_type({agenttype})"
f"with the property agents_by_type[{agenttype}].",
f"Model.get_agents_of_type() is deprecated and will be removed in Mesa 3.1."
f"Please replace get_agents_of_type({agenttype}) with the property agents_by_type[{agenttype}].",
DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -262,7 +262,7 @@ def initialize_data_collector(
"""
warnings.warn(
"initialize_data_collector() is deprecated. Please use the DataCollector class directly. "
"initialize_data_collector() is deprecated and will be removed in Mesa 3.1. Please use the DataCollector class directly. "
"by using `self.datacollector = DataCollector(...)`.",
DeprecationWarning,
stacklevel=2,
Expand Down
8 changes: 4 additions & 4 deletions mesa/time.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Mesa Time Module.
.. warning::
The time module and all its Schedulers are deprecated and will be removed in a future version.
The time module and all its Schedulers are deprecated and will be removed in Mesa 3.1.
They can be replaced with AgentSet functionality. See the migration guide for details:
https://mesa.readthedocs.io/latest/migration_guide.html#time-and-schedulers
Expand Down Expand Up @@ -63,7 +63,7 @@ def __init__(self, model: Model, agents: Iterable[Agent] | None = None) -> None:
"""
warnings.warn(
"The time module and all its Schedulers are deprecated and will be removed in a future version. "
"The time module and all its Schedulers are deprecated and will be removed in Mesa 3.1. "
"They can be replaced with AgentSet functionality. See the migration guide for details. "
"https://mesa.readthedocs.io/latest/migration_guide.html#time-and-schedulers",
DeprecationWarning,
Expand Down Expand Up @@ -375,7 +375,7 @@ def get_type_count(self, agenttype: type[Agent]) -> int:


class DiscreteEventScheduler(BaseScheduler):
"""This class has been deprecated and replaced by the functionality provided by experimental.devs."""
"""This class has been removed and replaced by the functionality provided by experimental.devs."""

def __init__(self, model: Model, time_step: TimeT = 1) -> None:
"""Initialize DiscreteEventScheduler.
Expand All @@ -387,5 +387,5 @@ def __init__(self, model: Model, time_step: TimeT = 1) -> None:
"""
super().__init__(model)
raise Exception(
"DiscreteEventScheduler is deprecated in favor of the functionality provided by experimental.devs"
"DiscreteEventScheduler is removed in favor of the functionality provided by experimental.devs"
)

0 comments on commit 8ae9b22

Please sign in to comment.