-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
I was trying to use BatchRunner to run multiple iterations of my model that had only fixed parameter sets. Initially, when reading the docs, I saw that the variable_parameters is specified as an optional keyword argument. However, if I do not pass in any variable parameters, then BatchRunner fails with the error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-54-793336723b8d> in <module>()
8 iterations=10,
9 max_steps=12 * 20,
---> 10 model_reporters={'Projects': stage_counts})
11 batch_run.run_all()
~/anaconda/envs/prog_forecast/lib/python3.6/site-packages/mesa/batchrunner.py in __init__(self, model_cls, variable_parameters, fixed_parameters, iterations, max_steps, model_reporters, agent_reporters, display_progress)
81 """
82 self.model_cls = model_cls
---> 83 self.variable_parameters = self._process_parameters(variable_parameters)
84 self.fixed_parameters = fixed_parameters or {}
85 self._include_fixed = len(self.fixed_parameters.keys()) > 0
~/anaconda/envs/prog_forecast/lib/python3.6/site-packages/mesa/batchrunner.py in _process_parameters(self, params)
101 params = copy.deepcopy(params)
102 bad_names = []
--> 103 for name, values in params.items():
104 if (isinstance(values, str) or
105 not hasattr(values, "__iter__")):
AttributeError: 'NoneType' object has no attribute 'items'
I felt confused when I first encountered this error, as I was expecting BatchRunner to gracefully handle the variable_parameters=None scenario. It thus appeared as a bug to me.
If this is truly a bug, I think there's two different ways fixing this could go. If the intent is to make variable_parameters an optional keyword argument, then adding code to deal with its optionality would be good, e.g. some conditionals that deal with it. Otherwise, if the intent is to make variable_parameters a non-optional argument, it should not have a default value of None.
May I ask which of these design choices is the intended one? If it's the latter, I'm happy to put in a PR to make it non-optional. If it's the former, then I'd like to ask for guidance on putting in a PR, as there's probably a few places I'll need to add in conditionals that I wouldn't be fully aware of.