Skip to content

Commit

Permalink
Remove deprecated functionality
Browse files Browse the repository at this point in the history
Remove some deprecated functionality that is scheduled to be removed with 3.1.
  • Loading branch information
EwoutH committed Nov 11, 2024
1 parent b171136 commit 0616b49
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 76 deletions.
25 changes: 0 additions & 25 deletions mesa/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ def select(
at_most: int | float = float("inf"),
inplace: bool = False,
agent_type: type[Agent] | None = None,
n: int | None = None,
) -> AgentSet:
"""Select a subset of agents from the AgentSet based on a filter function and/or quantity limit.
Expand All @@ -167,7 +166,6 @@ def select(
- If a float between 0 and 1, at most that fraction of original the agents are selected.
inplace (bool, optional): If True, modifies the current AgentSet; otherwise, returns a new AgentSet. Defaults to False.
agent_type (type[Agent], optional): The class type of the agents to select. Defaults to None, meaning no type filtering is applied.
n (int): deprecated, use at_most instead
Returns:
AgentSet: A new AgentSet containing the selected agents, unless inplace is True, in which case the current AgentSet is updated.
Expand All @@ -176,14 +174,6 @@ def select(
- at_most just return the first n or fraction of agents. To take a random sample, shuffle() beforehand.
- at_most is an upper limit. When specifying other criteria, the number of agents returned can be smaller.
"""
if n is not None:
warnings.warn(
"The parameter 'n' is deprecated and will be removed in Mesa 3.1. Use 'at_most' instead.",
DeprecationWarning,
stacklevel=2,
)
at_most = n

inf = float("inf")
if filter_func is None and agent_type is None and at_most == inf:
return self if inplace else copy.copy(self)
Expand Down Expand Up @@ -281,21 +271,6 @@ def do(self, method: str | Callable, *args, **kwargs) -> AgentSet:
Returns:
AgentSet | list[Any]: The results of the callable calls if return_results is True, otherwise the AgentSet itself.
"""
try:
return_results = kwargs.pop("return_results")
except KeyError:
return_results = False
else:
warnings.warn(
"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,
)

if return_results:
return self.map(method, *args, **kwargs)

# we iterate over the actual weakref keys and check if weakref is alive before calling the method
if isinstance(method, str):
for agentref in self._agents.keyrefs():
Expand Down
51 changes: 0 additions & 51 deletions mesa/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import numpy as np

from mesa.agent import Agent, AgentSet
from mesa.datacollection import DataCollector

SeedLike = int | np.integer | Sequence[int] | np.random.SeedSequence
RNGLike = np.random.Generator | np.random.BitGenerator
Expand Down Expand Up @@ -112,14 +111,6 @@ def _wrapped_step(self, *args: Any, **kwargs: Any) -> None:
# Call the original user-defined step method
self._user_step(*args, **kwargs)

def next_id(self) -> int: # noqa: D102
warnings.warn(
"using model.next_id() is deprecated and will be removed in Mesa 3.1. Agents track their unique ID automatically",
DeprecationWarning,
stacklevel=2,
)
return 0

@property
def agents(self) -> AgentSet:
"""Provides an AgentSet of all agents in the model, combining agents from all types."""
Expand All @@ -143,16 +134,6 @@ def agents_by_type(self) -> dict[type[Agent], AgentSet]:
"""A dictionary where the keys are agent types and the values are the corresponding AgentSets."""
return self._agents_by_type

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 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,
)
return self.agents_by_type[agenttype]

def _setup_agent_registration(self):
"""Helper method to initialize the agent registration datastructures."""
self._agents = {} # the hard references to all agents in the model
Expand Down Expand Up @@ -245,38 +226,6 @@ def reset_rng(self, rng: RNGLike | SeedLike | None = None) -> None:
self.rng = np.random.default_rng(rng)
self._rng = self.rng.bit_generator.state

def initialize_data_collector(
self,
model_reporters=None,
agent_reporters=None,
agenttype_reporters=None,
tables=None,
) -> None:
"""Initialize the data collector for the model.
Args:
model_reporters: model reporters to collect
agent_reporters: agent reporters to collect
agenttype_reporters: agent type reporters to collect
tables: tables to collect
"""
warnings.warn(
"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,
)

self.datacollector = DataCollector(
model_reporters=model_reporters,
agent_reporters=agent_reporters,
agenttype_reporters=agenttype_reporters,
tables=tables,
)
# Collect data for the first time during initialization.
self.datacollector.collect(self)

def remove_all_agents(self):
"""Remove all agents from the model.
Expand Down

0 comments on commit 0616b49

Please sign in to comment.