Introduce AbstractAgentSet to agent.py and refactor AgentSet to inherit from it#3210
Introduce AbstractAgentSet to agent.py and refactor AgentSet to inherit from it#3210
Conversation
|
Performance benchmarks:
|
c4f36e1 to
c75459b
Compare
|
I also have a refactoring suggestion: In
I have not introduced it here to keep it atomic |
It would also be a backward-incompatibility change, so we cannot do that in Mesa 3.x because of semver. |
1. AbstractAgentSet no longer inherits from Sequence 2. AgentSet explicitly inherits from Sequence to maintain backward compatibility
40c2659 to
feb1b39
Compare
|
few observations @codebreaker32:
|
You are mistaken, both are using
See The main agenda for StrongAgentSet is performance and determinism, but we know that handling strong references manually creates a high risk of memory leaks for end-users. The goal is that operations creating a "view" or "copy" of the data (like shuffle(inplace=False) or copy()) should default to returning a standard AgentSet (weak refs). This ensures that while the Model uses strong refs internally for stability, objects handed back to the user are "safe" by default and won't keep dead agents alive. So yes StrongAgentSet will override them |
|
with the update to agent.py, there is now a conflict. I guess it has to do with deprecating sequence behavior on AgentSet. Can you take a look at the conflict and resolve it? I think this will be ready to be merged afterwards. |
Done. |
Summary
This PR introduces AbstractAgentSet as an abstract base class for all agent collection implementations in Mesa. This establishes a formal interface and sets the foundation for introducing alternative storage mechanisms (strong vs weak references) while maintaining backward compatibility. Further, It refactors
AgentSetclass to inherit from itMotive
For complete discussion: see #3128 and #3160
Changes
New: AbstractAgentSet class: Defines the minimal interface for agent collections via abstract methods.
Refactored: AgentSet class
Fully backward compatible - No breaking changes
Ticks (1) from #3209