-
-
Notifications
You must be signed in to change notification settings - Fork 209
Description
Describe the bug
The BankReservesModel is missing the rng parameter in its __init__() method, which causes batch_run.py to fail with a TypeError when executed. The mesa.batch_run() function automatically injects the rng parameter for reproducibility, but the model doesn't accept it.
Notably, bank_reserves is the only example in the repository that includes a batch_run.py file, making this bug particularly important as it breaks the only demonstration of Mesa's batch_run functionality.
Expected behavior
Running python batch_run.py should complete successfully and generate a CSV file with data from all parameter combinations, similar to other Mesa examples that support batch runs.
To Reproduce
cd examples/bank_reserves
python batch_run.pyError Output
0%| | 0/4 [00:00<?, ?it/s]
Traceback (most recent call last):
File "/path/to/mesa-examples/examples/bank_reserves/batch_run.py", line 49, in <module>
main()
File "/path/to/mesa-examples/examples/bank_reserves/batch_run.py", line 40, in main
data = mesa.batch_run(
BankReservesModel,
br_params,
)
File "/path/to/mesa/mesa/batchrunner.py", line 122, in batch_run
data = process_func(run)
File "/path/to/mesa/mesa/batchrunner.py", line 204, in _model_run_func
model = model_cls(**kwargs)
TypeError: BankReservesModel.__init__() got an unexpected keyword argument 'rng'
Additional context
- Mesa version:
>=3.1.4(from requirements.txt) - Python version: 3.10+ (tested on 3.13.5)
- OS: macOS/Linux/Windows (reproducible on all platforms)
Root cause:
This appears to be an incomplete part of the Mesa 3.x migration. Commit b23f89c (#267) updated the visualization from server.py to Solara but didn't add the rng parameter to the model's __init__() method.
Pattern comparison:
Other examples like forest_fire, hotelling_law, and hex_snowflake already follow the correct pattern by accepting rng or seed parameters and passing them to super().__init__().
Why this wasn't caught:
The bank_reserves example is the only one with a batch_run.py file in the examples directory, which is why this issue wasn't caught during the migration.
Solution:
I have a fix ready and will submit a PR shortly.