Skip to content

Commit

Permalink
- Moved model initialization into the iterations loop to ensure that
Browse files Browse the repository at this point in the history
models are also properly initialized when starting a new iteration.

- The deepcopy ensures that on model initialization the kwargs are always
the original ones specified by the user.
The current solution (before this code change) allows parameters to be
overwritten during a model run.  This causes subsequent model runs to
be initialized with the wrong parameters.  This happens for example when
one of the parameters is warehouse stock.  If the first model modifies the
amount of stock in the warehouse, then the second model run would be
initialized with that modified value.
  • Loading branch information
ihopethiswillfi committed Mar 13, 2018
1 parent 3380f6c commit 210889b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion 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

0 comments on commit 210889b

Please sign in to comment.