Skip to content

Conversation

@Jayantparashar10
Copy link

@Jayantparashar10 Jayantparashar10 commented Jan 30, 2026

Description

Fixes #316

This PR adds the missing rng parameter to BankReservesModel.__init__() to make it compatible with mesa.batch_run().

Changes

  • Added rng=None parameter to BankReservesModel.__init__()
  • Pass rng to super().__init__(rng=rng) for proper RNG initialization
  • Aligns with the pattern used in other examples (forest_fire, hotelling_law, hex_snowflake)

Testing

  • Verified batch_run.py executes successfully without errors
  • Generates correct CSV output with all parameter combinations
  • Backward compatible with interactive visualization (solara run app.py)

Context

This completes the Mesa 3.x migration for bank_reserves that was started in #267, which updated the visualization but missed the RNG parameter update.

Since bank_reserves is currently the only example with a batch_run.py file, this fix is particularly important for demonstrating Mesa's batch_run functionality to users.

Code Changes

Before

def __init__(self, height=..., width=..., init_people=..., 
             rich_threshold=..., reserve_percent=...):
    super().__init__()  # Missing rng parameter

After

def __init__(self, height=..., width=..., init_people=..., 
             rich_threshold=..., reserve_percent=..., rng=None):
    super().__init__(rng=rng)   # Properly passes rng to parent

Related

- Add rng parameter to BankReservesModel.__init__()
- Pass rng to super().__init__() for proper RNG initialization
- Fixes batch_run() TypeError when using mesa.batch_run()
- Aligns with other examples (forest_fire, hotelling_law, etc.)

This resolves the issue where batch_run.py would fail with:
TypeError: BankReservesModel.__init__() got an unexpected keyword argument 'rng'
Copilot AI review requested due to automatic review settings January 30, 2026 07:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for Mesa’s batch_run() RNG injection by updating the BankReservesModel constructor to accept and forward an rng argument.

Changes:

  • Added an optional rng=None parameter to BankReservesModel.__init__().
  • Forwarded rng to mesa.Model via super().__init__(rng=rng) to ensure proper RNG initialization during batch runs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BankReservesModel missing rng parameter causes batch_run to fail

1 participant