Replies: 7 comments 31 replies
-
That's super interesting! I thought about something similar some time ago, but without do_each and select_agents it seemed a bit unwieldy for complex schedulers. But now seems like a good time! Looks like we can do more with less |
Beta Was this translation helpful? Give feedback.
-
Is there a way to perform uniform activation, or activate agents in a user-defined, deterministic order? For example, users may want to sort by agent ids and activate them one-by-one in this order. |
Beta Was this translation helpful? Give feedback.
-
I like the cleanliness of the resulting code. I have some random thoughts to add to the discussion. First, do_each is an operation on a set of agents. So, I would at least consider having an AgentSet class. If you don't have an AgentSet class, From a logical point of view, you need to (1) select the agents, (2) impose some order (so |
Beta Was this translation helpful? Give feedback.
-
Something that poped up in my mind this morning is that without any scheduler users will have to manually track the number of steps. That is right now the number of steps is stored in |
Beta Was this translation helpful? Give feedback.
-
The proposal to replace fixed schedulers in Mesa with select_agents and ask_agents is compelling. It offers a more flexible, Pythonic approach that aligns with principles like "Explicit is better than implicit" and makes agent activation logic more transparent and readable. |
Beta Was this translation helpful? Give feedback.
-
This approach allows for dynamic agent selection and activation, enabling complex behaviors like conditional activation, staggered intervals, and prioritized interactions. The new examples demonstrate how the new syntax simplifies and enhances control over simulation flow. |
Beta Was this translation helpful? Give feedback.
-
Deprecating traditional schedulers and moving to this model brings agent behavior to the forefront, improving accessibility, readability, and customization. It feels intuitive and aligns well with Python's philosophy, making it a strong candidate for adoption. |
Beta Was this translation helpful? Give feedback.
-
Update: View the migration guide on how to replace the deprecated Schedulers with AgentSet functionality.
Mesa currently utilizes a time module and various schedulers to manage agent activation and time progression within simulations. However, for each specific order and selection of agents a new type of scheduler needs to be created. This is highly restrictive and doesn't allow really interesting and complex, conditional interactions.
Recent developments and proposed changes allow moving away from fixed schedulers. In this discussion I want to talk about if we shouldn't just deprecate them all, and embracing a more direct and efficient approach to agent activation and time management, inspired by the NetLogo framework.
The old and the new
Mesa's existing architecture includes a time module that provides different schedulers:
BaseScheduler
,RandomActivation
,SimultaneousActivation
,StagedActivation
,RandomActivationByType
, andDiscreteEventScheduler
. These schedulers offer various strategies for activating agents (e.g., in a fixed order, randomly, or simultaneously) and managing time progression in the simulation.However, we already built a lot of the prerequisites to move away from fixed schedulers:
If we add a
ask_agents()
method and a"step"
counter to the model itself, we're basically there.Replacing current schedulers
The proposal to deprecate schedulers in the Mesa library and replace them with more direct methods of selecting agents and executing actions can be illustrated through several examples. These examples demonstrate how the
model.select_agents
andmodel.do_each
methods can effectively replace the functionality of various schedulers.1. Replacing
RandomActivation
SchedulerCurrent Approach with
RandomActivation
In the existing system, the
RandomActivation
scheduler activates each agent once per step, in a random order. An example of its usage might be:New Approach
Using
model.select_agents
andmodel.do_each
, the same functionality can be achieved as follows:2. Replacing
SimultaneousActivation
SchedulerCurrent Approach with
SimultaneousActivation
The
SimultaneousActivation
scheduler is used when agents need to first calculate their actions (step
) and then update their state (advance
) simultaneously:New Approach
This can be replicated as follows:
3. Replacing
StagedActivation
SchedulerCurrent Approach with
StagedActivation
StagedActivation
allows for multi-stage activation, where agents execute different stages in a defined order:New Approach
The same can be done with the new method:
4. Replacing
RandomActivationByType
SchedulerCurrent Approach with
RandomActivationByType
This scheduler activates each type of agent in a random order:
New Approach
Using the new approach, different agent types can be activated as follows:
Be free, free to do whatever you want
The proposed transition to using
model.select_agents
andmodel.do_each
in the Mesa library offers unprecedented flexibility and enables a wide range of new behaviors that were not easily achievable with the traditional scheduler system. Below are several examples illustrating this enhanced flexibility and the potential for innovative agent behaviors:1. Conditional Activation Based on Dynamic Criteria
New Behavior
Activate agents based on dynamic, complex conditions that can change each step.
Example
2. Sequential Group Activation
New Behavior
Activate groups of agents sequentially, where the activation of one group depends on the state of another.
Example
3. Staggered or Time-Shifted Activation
New Behavior
Activate agents at different intervals, not necessarily in every step.
Example
4. Interleaved and Prioritized Actions
New Behavior
Interleave actions of different agent types or prioritize certain actions over others.
Example
5. Complex Interaction Patterns
New Behavior
Facilitate complex interactions between agents based on multiple criteria, such as proximity, state, or history.
Example
Let's discuss
Let's discuss if this is the approach we want to go! I think it's great, because it feels really Pythonic.
By explicitly defining what happens in the step, you are more in the flow and in control of what happens.
Currently, the behavior is hidden away in a Time module. Let's bring it out in the open.
The examples read like the best programming language in the world: English
I feel some of our schedulers are a bit like this. I think the new syntax is way easier to comprehend.
Beta Was this translation helpful? Give feedback.
All reactions