Skip to content

Commit 033facc

Browse files
authored
docs: Improve batch_run documentation for parallel processing (#2707)
- Add explanation of number_processes parameter in getting started guide - Clarify why parallel processing should be avoided in Jupyter notebooks
1 parent 8c3c9dc commit 033facc

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

docs/overview.md

+1
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ results = mesa.batch_run(
240240
iterations=5,
241241
max_steps=100,
242242
data_collection_period=1,
243+
number_processes=1 # Change to use multiple CPU cores for parallel execution
243244
)
244245
```
245246

mesa/batchrunner.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
To take advantage of parallel execution of experiments, `batch_run` uses
44
multiprocessing if ``number_processes`` is larger than 1. It is strongly advised
55
to only run in parallel using a normal python file (so don't try to do it in a
6-
jupyter notebook). Moreover, best practice when using multiprocessing is to
6+
jupyter notebook). This is because Jupyter notebooks have a different execution
7+
model that can cause issues with Python's multiprocessing module, especially on
8+
Windows. The main problems include the lack of a traditional __main__ entry
9+
point, serialization issues, and potential deadlocks.
10+
11+
Moreover, best practice when using multiprocessing is to
712
put the code inside an ``if __name__ == '__main__':`` code black as shown below::
813
914
from mesa.batchrunner import batch_run
@@ -21,8 +26,6 @@
2126
display_progress=True,
2227
)
2328
24-
25-
2629
"""
2730

2831
import itertools

0 commit comments

Comments
 (0)