Skip to content

Commit

Permalink
Merge pull request projectmesa#486 from ihopethiswillfi/master
Browse files Browse the repository at this point in the history
Batchrunner fixes: properly initialize models with correct parameters during subsequent runs.
  • Loading branch information
jackiekazil authored Mar 18, 2018
2 parents 3380f6c + eda02ea commit c2015bb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mesa/batchrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ def run_all(self):
for param_values in product(*param_ranges):
kwargs = dict(zip(param_names, param_values))
kwargs.update(self.fixed_parameters)
model = self.model_cls(**kwargs)

for _ in range(self.iterations):
kwargscopy = copy.deepcopy(kwargs)
model = self.model_cls(**kwargscopy)
self.run_model(model)
# Collect and store results:
model_key = param_values + (next(run_count),)
Expand Down Expand Up @@ -194,7 +195,12 @@ def _prepare_report_table(self, vars_dict, extra_cols=None):
rest_cols = set(df.columns) - set(index_cols)
ordered = df[index_cols + list(sorted(rest_cols))]
ordered.sort_values(by='Run', inplace=True)

if self._include_fixed:
for param in self.fixed_parameters.keys():
ordered[param] = self.fixed_parameters[param]
val = self.fixed_parameters[param]

# avoid error when val is an iterable
vallist = [val for i in range(ordered.shape[0])]
ordered[param] = vallist
return ordered

0 comments on commit c2015bb

Please sign in to comment.