Issue: Bank Reserves Example Crashes with ValueError and Deprecation Warnings
- Dominant language
- Python
- Stars
- 252
- Forks
- 279
- Avg merge
- 8d 9h
- Merged PRs (30d)
- 2
Description
# 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
1. **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.
2. **Deprecation Warnings**
The terminal displays warnings indicating the example uses an outdated visualization API.
* **Warning:** `FutureWarning: Returning a dict from agent_portrayal is deprecated`.
3. **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.
4. **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
1. Navigate to the directory: `examples/bank_reserves`.
2. Run the application:
```bash
solara run app.py
```
3. Observe the following:
* A `ValueError` appears in the terminal.
4. Check the terminal for the `FutureWarning` regarding `agent_portrayal`.
5. Observe the visualization canvas: note that only 2 agents are shown despite the "People" slider indicating 25.
6. Attempt to run the batch script:
```bash
python batch_run.py
```
## Error Output
Below are the raw tracebacks and warnings observed during execution:
```text
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)
Contributor guide
Research direction
Start in examples/bank_reserves/app.py and batch_run.py, reproducing the issue with `solara run app.py` and `python batch_run.py`. Trace BankReservesModel and the reported visualization errors, then verify that the application runs without the crash or deprecation warnings, the initial agent count matches the slider, and batch processing completes successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- full-stack
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100