Skip to content

Commit

Permalink
fix: Make bank_reserves batch_run example work
Browse files Browse the repository at this point in the history
  • Loading branch information
rht authored and tpike3 committed Apr 27, 2022
1 parent 63bca3e commit def2c1b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions examples/bank_reserves/batch_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,27 @@ def run_model(self):
data = batch_run(
BankReservesModel,
br_params,
model_reporters={"Rich": get_num_rich_agents},
agent_reporters={"Wealth": "wealth"},
)
br_df = pd.DataFrame(data)
br_df.to_csv("BankReservesModel_Data.csv")

# The commented out code below is the equivalent code as above, but done
# via the legacy BatchRunner class. This is a good example to look at if
# you want to migrate your code to use `batch_run()` from `BatchRunner`.
# Things to note:
# - You have to set "reserve_percent" in br_params to `[5]`, because the
# legacy BatchRunner doesn't auto-detect that it is single-valued.
# - The model reporters need to be explicitly specified in the legacy
# BatchRunner
"""
br = BatchRunner(
from mesa.batchrunner import BatchRunnerMP
br = BatchRunnerMP(
BankReservesModel,
br_params,
nr_processes=2,
variable_parameters=br_params,
iterations=2,
max_steps=1000,
nr_processes=None,
# model_reporters={"Data Collector": lambda m: m.datacollector},
model_reporters={"Data Collector": lambda m: m.datacollector},
)
br.run_all()
br_df = br.get_model_vars_dataframe()
Expand Down

0 comments on commit def2c1b

Please sign in to comment.