Reimplement schedulers to use AgentSet#1926
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1926 +/- ##
==========================================
+ Coverage 79.14% 80.21% +1.06%
==========================================
Files 15 15
Lines 1098 1137 +39
Branches 236 245 +9
==========================================
+ Hits 869 912 +43
+ Misses 198 195 -3
+ Partials 31 30 -1 ☔ View full report in Codecov by Sentry. |
|
Looks like a nice start! I think a big conceptual design decision we need to make is if we want to support multiple schedulers. Did we do so in the past? If we only have one scheduler, we could simplify and assume a lot, for example that all agents are in the scheduler. We don't have to explicitly add or remove them, or even keep track of them in the scheduler. There would also be one single step/time clock. It would probably allow deprecating all schedulers, and moving a lot of the requesting of behavior to However, if we do want to support multiple schedulers, we need to leave a lot of stuff in the scheduler, at least the time of that scheduler and which agents are part of it. Personally, I can't try of that many cases you can't solve with the AgentSet approach, but there might be any. Also curious what @jackiekazil @tpike3 and @Corvince think on this matter. |
|
I have used multiple schedulers in the past (pre As indicated in #1912, one possible direction could be to shift to a central EventList. This creates a central understanding of time. All existing functionality of the various schedulers could be rebuilt on such an event list. |
mesa/time.py
Outdated
| if not self._remove_warning_given: | ||
| self._remove_warning_given = True | ||
| warnings.warn( | ||
| "Because of the shift to using weakrefs, it is no longer needed to explicitly remove" |
There was a problem hiding this comment.
I think this holds up as long a you use a single scheduler, and assume agents in model == agents in schedulers. However, as you let that assumption go you might want to remove agents from a scheduler but not from a model.
There was a problem hiding this comment.
However, I find it weird you still have to explicitly add agents to the scheduler, but don't explicitly have to remove them.
There was a problem hiding this comment.
This comes back to having one or more than one scheduler. If you have only one, then yes, there is no need to add or remove them. But that would be a backward incompatible change and thus is outside the scope of this PR.
|
I have reviewed the code several times, fixed the docs, and tested against various examples. This is ready for a proper check. @EwoutH, @Corvince, @jackiekazil, or @tpike3 do you have a chance to check this? |
|
Probably not in the coming days, but I really look forward to review this! |
|
Will try to review it later today! |
EwoutH
left a comment
There was a problem hiding this comment.
Looks good in general, and agree with the intend of this PR.
However, I think that we only should make minimal changes until we decide which direction to go with the schedulers (None, one per model, or multiple). So while this PR is good, I think the next step is a broad discussion about how we see the future of activating agents to do things.
| stacklevel=2, | ||
| ) | ||
|
|
||
| agent_keys = [agent.unique_id for agent in self._agents] |
There was a problem hiding this comment.
Agreed on deprecating in this case.
However, while in this way it's probably fine, we're technically deprecating something for which the replacement (AgentSet) is still experimental. Might be something to keep in mind.
There was a problem hiding this comment.
Again, this is outside the scope of this PR, but I want to do a separate discussion on unique_id. Now that it is no longer needed for the schedulers, its only function is to identify agents when gathering statistics.
There was a problem hiding this comment.
Agree - outside of this pr - suggested place for the discussion?
There was a problem hiding this comment.
Given that #1933 also relies on unique_id, we can perhaps discuss it there. Alternatively, we can have a broader discussion on the future of data collection and make it part of that.
|
@quaquel What's your guidance on this regarding the next release? Would you recommend having this in the 2.2.0 release, or to release 2.2.0 first and merge this on the 2.3 development branch? |
|
|
Unfortunately, this PR, together with an implementation error in #1916, broke RandomActivation, and more important, went completely unnoticed for multiple weeks, until an user reported it in #2006. We should evaluate very critically how such a major unintended behavior could slip through the cracks. |
|
|
(and thus the next questions are, should we alter our review process, testing standards or something else, and if so, how) |
|
See #2007. The fix can be found there. |
This PR builds on #1916 and updates the schedulers to use the new AgentSet class and/or weakrefs. It also adds a new feature: schedulers take an optional agents keyword argument in
__init__so you can spawn a scheduler with all agents.My aim with this PR is to be fully backward compatible but raise warnings when methods that have become redundant are being used. The current code passes all unit tests.
Still to do: