-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Tracking Issue: AgentSet Refactoring and _HardKeyAgentSet Implementation using AbstractAgentSet #3209
Copy link
Copy link
Closed
Description
This is a tracking issue(See #3128 and #3160 for more)
The current AgentSet implementation relies on WeakKeyDictionary for storage. While memory-efficient, this approach introduces performance overheads. To solve this fundamentally, we propose refactoring the AgentSet hierarchy to use an Abstract Base Class (ABC) pattern(credits to @quaquel) . This ensures a clean separation between the interface and the storage mechanism (Weak vs. Strong).
Proposed Roadmap
This refactor will be executed in three stages to maintain backward compatibility and easy to review
Phase 1: Introduce AbstractAgentSet
- Define a new
abc.ABCnamedAbstractAgentSet. - Move common logic (iteration, selection, etc) into the abstract base.
- Refactor the existing
AgentSetto inherit fromAbstractAgentSet, preserving its currentWeakKeyDictionarybehavior for backward compatibility.
Merged PR: #3210
Phase 2: Implement StrongAgentSet (Hard Refs)
- Create a new class
StrongAgentSet(orHardKeyAgentSet) inheriting fromAbstractAgentSet. - Implement storage using a standard Python
dictto guarantee deterministic behavior.
Merged PR: #3219
Phase 3: Integration & Cleanup
- Update
mesa.Modelto useStrongAgentSetas the internal storage formodel._agents_by_typeandmodel_all_agents. - Remove redundant internal attributes such as
model._agents.
Merged PR: #3224
Definition of Done
-
AbstractAgentSetimplemented and tested. -
StrongAgentSetimplemented with full test coverage for liveness/removal scenarios. -
mesa.Modelupdated to useStrongAgentSet - Legacy internal attributes removed from
Model.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels