You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently agents' step() functions are executed sequentially through AgentSet's do() and shuffle_do() functions. If there are I/O operations involved in step() (e.g., disk or network I/O operations), they can potentially reduce performance and reponsiveness of the model. For example, in the upcoming Mesa-LLM project, agents will most likely need to query large language models at each step, through either local deployment or API calls.
Note that sequential execution of agents' step() functions may be necessary, depending on specific model logic. For example in Schelling's segregation model, each agent's decision depends on other agents' earlier actions, so step() functions need to be called one after another. Conversely, in models where agents can observe and act simultaneously, or if I/O operations can be performed independently, these expensive I/Os might be a bottleneck.
Potential Solution?
I'm wondering whether these cases can benefit from asynchronous execution of agents' step() functions. There could be a new async step function (or with any other function name) defined by users such as:
classMyAgent(mesa.Agent):
...
# new method for async ioasyncdefasync_step(self):
# expensive I/O operations
....
...
But AgentSet will need to be updated accordingly, for instance with new async versions of do() and shuffle_do():
classAgentSet(MutableSet, Sequence):
...
asyncdefdo(self, method: str|Callable, *args, **kwargs) ->AgentSet:
# use asyncio module to gather results from agents' `async_step()` functionsawait ...
# and similarly for `shuffle_do()`asyncdefshuffle_do(self, method: str|Callable, *args, **kwargs) ->AgentSet:
await ...
However, this means that model.step() functions will also need to be async:
As a result, SolaraViz will not work unless we update it to use async model step function too.
I also thought about letting users create their own AgentSet class:
classCustomAgentSet(mesa.AgentSet):
...
asyncdefdo(self, method: str|Callable, *args, **kwargs) ->AgentSet:
# use asyncio module to gather results from agents' `async_step()` functionsawait ...
# and similarly for `shuffle_do()`asyncdefshuffle_do(self, method: str|Callable, *args, **kwargs) ->AgentSet:
await ...
But mesa.Model uses our own mesa.AgentSet and there's no way of inserting a custom AgentSet. Even if it can be done, there is still the same problem of converting model.step() to async and making it work with SolaraViz.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Motivation
Currently agents'
step()
functions are executed sequentially through AgentSet'sdo()
andshuffle_do()
functions. If there are I/O operations involved instep()
(e.g., disk or network I/O operations), they can potentially reduce performance and reponsiveness of the model. For example, in the upcoming Mesa-LLM project, agents will most likely need to query large language models at each step, through either local deployment or API calls.Note that sequential execution of agents'
step()
functions may be necessary, depending on specific model logic. For example in Schelling's segregation model, each agent's decision depends on other agents' earlier actions, sostep()
functions need to be called one after another. Conversely, in models where agents can observe and act simultaneously, or if I/O operations can be performed independently, these expensive I/Os might be a bottleneck.Potential Solution?
I'm wondering whether these cases can benefit from asynchronous execution of agents'
step()
functions. There could be a new async step function (or with any other function name) defined by users such as:But AgentSet will need to be updated accordingly, for instance with new async versions of
do()
andshuffle_do()
:However, this means that
model.step()
functions will also need to be async:As a result, SolaraViz will not work unless we update it to use async model step function too.
I also thought about letting users create their own AgentSet class:
But mesa.Model uses our own mesa.AgentSet and there's no way of inserting a custom AgentSet. Even if it can be done, there is still the same problem of converting
model.step()
to async and making it work with SolaraViz.Any better ideas?
Beta Was this translation helpful? Give feedback.
All reactions