mesa icon indicating copy to clipboard operation
mesa copied to clipboard

Run BatchRunner with only fixed_parameters and no variable_parameters

Open AndrewC19 opened this issue 4 years ago • 10 comments

To my understanding, I should be able to run my model multiple times using BatchRunner with only fixed_parameters. However, if I set variable_parameters to None, I get the following AttributeError: 'NoneType' object has no attribute 'items'.

It would be useful to be able to run a model using the BatchRunner without using variable parameters. For example, I want to run my model multiple times under baseline conditions so I don't have any variable parameters. Does this feature already exist and I just cannot find it?

This issue was previously raised in #466 and subsequently fixed in #596, but this fix doesn't seem to work anymore.

AndrewC19 avatar Nov 03 '20 15:11 AndrewC19

This was fixed in the most recent BatchRunner fix, however there has not been a new release to PyPI just yet so you would need to install from github using

pip install git+https://github.com/projectmesa/mesa.git

tpike3 avatar Nov 08 '20 13:11 tpike3

Hmm, just installed from github (Mesa-0.8.8.1) as suggested and now getting different error if I use variable_parameters=None or omit entirely.

TypeError: unhashable type: 'dict'

at line 168 of batchrunner.py

If I pass in a dummy variable parameter that takes on a single value, everything runs fine.

misken avatar Dec 02 '20 22:12 misken

@misken Could you post your instantiation of BatchRunner? Thanks

tpike3 avatar Dec 02 '20 23:12 tpike3

Yep, here it is:

batch_run = BatchRunner(
        CovidHospModel,
        variable_parameters=None,
        fixed_parameters=model_params,
        iterations=num_iterations,
        max_steps=num_steps,
        model_reporters={
                    "DC": get_datacollector
                },
        display_progress=True)

model_params is a dict and get_datacollector returns a model.DataCollector object (so I can get at the step level dataframe). If I replace the variable_parameters=None, with variable_parameters=var_params where var_params = {"dummy": range(25,50,25)}, then everything runs fine. If variable_parameters=None, omitted then get same error as if included.

misken avatar Dec 03 '20 13:12 misken

@misken Thanks I will take a look this weekend.

tpike3 avatar Dec 03 '20 22:12 tpike3

Reopening this issue... since this is not resolved. @tpike3 -- if this is going to be a bigger thing, maybe we should move to a new ticket.

jackiekazil avatar Dec 05 '20 06:12 jackiekazil

@misken If I am understanding correctly, your get model_reporters={ "DC": get_datacollector }, is intended to get the individual model runs data collectors where you are reporting each agent by step. If that is the case then I would recommend not adding a model_reporter so you instantiation will look like this...

batch_run = BatchRunner(
        CovidHospModel,
        fixed_parameters=model_params,
        iterations=num_iterations,
        max_steps=num_steps,
        display_progress=True)

the data is collected as a part of batch_runner, so then you can get the data you collected with each model run by calling

batch_run.run_all()
model_data = batch_run.get_collector_model() #For each model reporters
agent_data = batch_run.get_collector_agents() #For each agent reporter

Each of these will return a dictionary with: key = (Param1, Param2, ....) value = Pandas dataframe for those params.

Based on the error being at line 168 of BatchRunner this should solve that problem.

Please, let me know if it works?

tpike3 avatar Dec 05 '20 13:12 tpike3

@jackiekazil if this resolves the issue then the challenge is making BatchRunner more intuitive/user-friendly. I think this will be in @Corvince's leaner version under development.

I don't think it is a fixed-param only issue any more as that is now part of the tests.

I think this is a great data point to shape the next batchrunner iteration.

tpike3 avatar Dec 05 '20 14:12 tpike3

@tpike3 thanks. I wasn't exactly sure how to interpret the following sentence in the BatchRunner API docs:

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.

misken avatar Dec 05 '20 15:12 misken

@misken Thanks for the feedback, that is a vague sentence. We will get it updated.

tpike3 avatar Dec 06 '20 11:12 tpike3