Skip to content

Issue: Bank Reserves Example Crashes with ValueError and Deprecation Warnings #318

@Rishabh-77

Description

@Rishabh-77

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:
    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:
    python batch_run.py

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions