Issues with Bank Reserves Example: Crashes, Deprecations, and State Mismatches
Description
The bank_reserves example exhibits multiple issues preventing stable execution, proper visualization, and batch processing.
Detailed Issues
-
Crash (Race Condition)
Running the example with solara run app.py often results in a crash.
- Error:
ValueError: Length of values does not match length of index.
- Cause: This appears to be a race condition in
mesa.DataCollector where the Solara visualization thread reads data while the model thread is simultaneously writing to it.
-
Deprecation Warnings
The terminal displays warnings indicating the example uses an outdated visualization API.
- Warning:
FutureWarning: Returning a dict from agent_portrayal is deprecated.
-
Initialization Mismatch
The visualization loads with UI sliders set to default values (e.g., 25 "People"), but the model initializes with mismatching internal defaults (e.g., 2 "People").
- Result: A confusing initial state where the UI indicates a high agent count, but only 2 dots are visible.
-
Batch Run Failure
Executing batch_run.py fails.
- Cause:
BankReservesModel does not accept seed or rng arguments, which are automatically passed by the batch runner.
Steps to Reproduce
- Navigate to the directory:
examples/bank_reserves.
- Run the application:
- Observe the following:
- A
ValueError appears in the terminal.
- Check the terminal for the
FutureWarning regarding agent_portrayal.
- Observe the visualization canvas: note that only 2 agents are shown despite the "People" slider indicating 25.
- Attempt to run the batch script:
Error Output
Below are the raw tracebacks and warnings observed during execution:
FutureWarning: Returning a dict from agent_portrayal is deprecated. Please return an AgentPortrayalStyle instance instead.
UserWarning: The following keys from the returned dict were ignored: Shape, r, Layer, Filled
ERROR: Component ... PlotMatplotlib raised exception ValueError('Length of values (180) does not match length of index (179)')
Traceback (most recent call last):
File ".../reacton/core.py", line 1702, in _render
root_element = el.component.f(*el.args, **el.kwargs)
File ".../mesa/visualization/components/matplotlib_components.py", line 156, in PlotMatplotlib
df = model.datacollector.get_model_vars_dataframe()
...
ValueError: Length of values (180) does not match length of index (179)
ERROR: ... ValueError('Length of values (3296) does not match length of index (3269)')
[... second traceback ...]
Expected Behavior
- Stability: The application should run stably without crashing due to race conditions.
- Clean Output: No deprecation warnings should appear in the terminal.
- Consistency: The initial visualization state (number of agents rendered) should match the initial UI slider values.
- Batch Processing:
batch_run.py should execute successfully without argument errors.
System Info
- OS: Windows/Linux/macOS
- Python Version: 3.x
- Mesa Version: (Current Main)
Issues with Bank Reserves Example: Crashes, Deprecations, and State Mismatches
Description
The
bank_reservesexample exhibits multiple issues preventing stable execution, proper visualization, and batch processing.Detailed Issues
Crash (Race Condition)
Running the example with
solara run app.pyoften results in a crash.ValueError: Length of values does not match length of index.mesa.DataCollectorwhere the Solara visualization thread reads data while the model thread is simultaneously writing to it.Deprecation Warnings
The terminal displays warnings indicating the example uses an outdated visualization API.
FutureWarning: Returning a dict from agent_portrayal is deprecated.Initialization Mismatch
The visualization loads with UI sliders set to default values (e.g., 25 "People"), but the model initializes with mismatching internal defaults (e.g., 2 "People").
Batch Run Failure
Executing
batch_run.pyfails.BankReservesModeldoes not acceptseedorrngarguments, which are automatically passed by the batch runner.Steps to Reproduce
examples/bank_reserves.ValueErrorappears in the terminal.FutureWarningregardingagent_portrayal.Error Output
Below are the raw tracebacks and warnings observed during execution:
Expected Behavior
batch_run.pyshould execute successfully without argument errors.System Info