Batchrunner

Batchrunner

A single class to manage a batch run or parameter sweep of a given model.

class batchrunner.BatchRunner(model_cls, variable_parameters=None, fixed_parameters=None, iterations=1, max_steps=1000, model_reporters=None, agent_reporters=None, display_progress=True)[source]

This class is instantiated with a model class, and model parameters associated with one or more values. It is also instantiated with model and agent-level reporters, dictionaries mapping a variable name to a function which collects some data from the model or its agents at the end of the run and stores it.

Note that by default, the reporters only collect data at the end of the run. To get step by step data, simply have a reporter store the model’s entire DataCollector object.

class batchrunner.BatchRunnerMP(model_cls, nr_processes=None, **kwargs)[source]

Child class of BatchRunner, extended with multiprocessing support.

run_all()[source]

Run the model at all parameter combinations and store results, overrides run_all from BatchRunner.

class batchrunner.FixedBatchRunner(model_cls, parameters_list=None, fixed_parameters=None, iterations=1, max_steps=1000, model_reporters=None, agent_reporters=None, display_progress=True)[source]

This class is instantiated with a model class, and model parameters associated with one or more values. It is also instantiated with model and agent-level reporters, dictionaries mapping a variable name to a function which collects some data from the model or its agents at the end of the run and stores it.

Note that by default, the reporters only collect data at the end of the run. To get step by step data, simply have a reporter store the model’s entire DataCollector object.

collect_agent_vars(model)[source]

Run reporters and collect agent-level variables.

collect_model_vars(model)[source]

Run reporters and collect model-level variables.

get_agent_vars_dataframe()[source]

Generate a pandas DataFrame from the agent-level variables collected.

get_collector_agents()[source]

Passes pandas dataframes from datacollector module in dictionary format of agent reporters :return: dict {(Param1, Param2,…,iteration): <DataCollector Pandas DataFrame>}

get_collector_model()[source]

Passes pandas dataframes from datacollector module in dictionary format of model reporters :return: dict {(Param1, Param2,…,iteration): <DataCollector Pandas DataFrame>}

get_model_vars_dataframe()[source]

Generate a pandas DataFrame from the model-level variables collected.

run_all()[source]

Run the model at all parameter combinations and store results.

run_model(model)[source]

Run a model object to completion, or until reaching max steps.

If your model runs in a non-standard way, this is the method to modify in your subclass.

exception batchrunner.ParameterError(bad_names)[source]
exception batchrunner.VariableParameterError(bad_names)[source]