Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make mesa faster #882

Open
ghost opened this issue Aug 16, 2020 · 5 comments
Open

Make mesa faster #882

ghost opened this issue Aug 16, 2020 · 5 comments

Comments

@ghost
Copy link

ghost commented Aug 16, 2020

What's the problem this feature will solve?
Sadly, Python belongs to the slowest programming languages, but it's friendly code makes it popular and extremely usable.
Agent-based simulations can involve very large number of agents (e.g. millions), where concurrency control, parallelism and run-time speed of simulations could be crucial.

Describe the solution you'd like
Using:

  • PyPy
  • Cython (like numpy, abcEconomics: an agent-based stuff in economics)
  • numba

could help a lot in simulation speed ups.

@ghost ghost changed the title Make mesa faster (Pypy/CPython) Make mesa faster Aug 16, 2020
@rht
Copy link
Contributor

rht commented Aug 18, 2020

This is the first time PyPy is mentioned in this repo.
Disclaimer: I am also one of the maintainers of abcEconomics.

It should be easy to test if Mesa runs on PyPy with Travis (see e.g. https://github.com/AB-CE/abce/blob/master/.travis.yml#L24).

@rht rht mentioned this issue Aug 18, 2020
@rht
Copy link
Contributor

rht commented Aug 18, 2020

In abcEconomics, there is an option to run the execution of each agents in a separate CPU (https://github.com/AB-CE/abce/blob/master/abcEconomics/scheduler/multiprocess.py). If there are 20 agents and 4 CPUs, each CPU could execute 5 agents sequentially, but the 4 CPUs are doing it in parallel independently of each other. See any pool.map in the file I linked before. Care is needed to ensure that the objects are able to be pickled so they can run in each CPUs.

@Corvince
Copy link
Contributor

There is also a discussion about mesas performance in #798.

To recap my 2 cents on this issue: Mesa is mostly a framework and by itself it doesn't "do" much that could be improved by your suggestions. It really depends on the models it is used for (and if the actions are computationally expensive numba might be a very good and easy to use recommendation).

Re parallelism: Depending on the model running agents concurrently is either trivial or (almost) impossible. But usually you will run multiple simulations any way and running those in parallel is far easier, either manually or by using BatchrunnerMP (although it doesn't work at the moment, but it is being worked on).

@rht
Copy link
Contributor

rht commented Jul 6, 2023

It's worth trying Cinder. Currently discussed in https://news.ycombinator.com/item?id=36612835.

@adamamer20
Copy link

addressing this issue, I started to develop an extension of mesa which makes use of vectorized operations on pandas dataframes to achieve faster runtimes. you can provide a feedback or features you'd like to be supported/introduced here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants