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

[JOSS] docs: Improve batch_run documentation for parallel processing #2707

Merged
merged 1 commit into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ results = mesa.batch_run(
iterations=5,
max_steps=100,
data_collection_period=1,
number_processes=1 # Change to use multiple CPU cores for parallel execution
)
```

Expand Down
9 changes: 6 additions & 3 deletions mesa/batchrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
To take advantage of parallel execution of experiments, `batch_run` uses
multiprocessing if ``number_processes`` is larger than 1. It is strongly advised
to only run in parallel using a normal python file (so don't try to do it in a
jupyter notebook). Moreover, best practice when using multiprocessing is to
jupyter notebook). This is because Jupyter notebooks have a different execution
model that can cause issues with Python's multiprocessing module, especially on
Windows. The main problems include the lack of a traditional __main__ entry
point, serialization issues, and potential deadlocks.

Moreover, best practice when using multiprocessing is to
put the code inside an ``if __name__ == '__main__':`` code black as shown below::

from mesa.batchrunner import batch_run
Expand All @@ -21,8 +26,6 @@
display_progress=True,
)



"""

import itertools
Expand Down
Loading