How to use the mesa.batchrunner.BatchRunner function in Mesa

To help you get started, we’ve selected a few Mesa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github projectmesa / mesa / tests / test_batchrunner.py View on Github external
def launch_batch_processing(self):
        batch = BatchRunner(
            self.mock_model,
            variable_parameters=self.variable_params,
            fixed_parameters=self.fixed_params,
            iterations=self.iterations,
            max_steps=self.max_steps,
            model_reporters=self.model_reporters,
            agent_reporters=self.agent_reporters)
        batch.run_all()
        return batch
github projectmesa / mesa / mesa / batchrunner.py View on Github external
display_progress: Display progresss bar with time estimation?

        """
        super().__init__(model_cls, ParameterProduct(variable_parameters),
                     fixed_parameters, iterations, max_steps,
                     model_reporters, agent_reporters,
                     display_progress)


class MPSupport(Exception):
    def __str__(self):
        return ("BatchRunnerMP depends on pathos, which is either not "
               "installed, or the path can not be found. ")


class BatchRunnerMP(BatchRunner):
    """ Child class of BatchRunner, extended with multiprocessing support. """

    def __init__(self, model_cls, nr_processes=2, **kwargs):
        """ Create a new BatchRunnerMP for a given model with the given
        parameters.

        Args:
            model_cls: The class of model to batch-run.
            nr_processes: the number of separate processes the BatchRunner
                should start, all running in parallel.
            kwargs: the kwargs required for the parent BatchRunner class
        """
        if not pathos_support:
            raise MPSupport
        super().__init__(model_cls, **kwargs)
        self.pool = ProcessPool(nodes=nr_processes)
github projectmesa / mesa / examples / bank_reserves / batch_run.py View on Github external
# collect data
        self.datacollector.collect(self)
        # tell all the agents in the model to run their step function
        self.schedule.step()

    def run_model(self):
        for i in range(self.run_time):
            self.step()


# parameter lists for each parameter to be tested in batch run
br_params = {"init_people": [25, 100, 150, 200],
             "rich_threshold": [5, 10, 15, 20],
             "reserve_percent": [0, 50, 100]}

br = BatchRunner(BankReservesModel,
                 br_params,
                 iterations=1,
                 max_steps=1000,
                 model_reporters={"Data Collector": lambda m: m.datacollector})

if __name__ == '__main__':
    br.run_all()
    br_df = br.get_model_vars_dataframe()
    br_step_data = pd.DataFrame()
    for i in range(len(br_df["Data Collector"])):
        if isinstance(br_df["Data Collector"][i], DataCollector):
            i_run_data = br_df["Data Collector"][i].get_model_vars_dataframe()
            br_step_data = br_step_data.append(i_run_data, ignore_index=True)
    br_step_data.to_csv("BankReservesModel_Step_Data.csv")