Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit fixed and variable parameters for batchrunner #374

Closed
wants to merge 13 commits into from

Conversation

njvrzm
Copy link
Contributor

@njvrzm njvrzm commented May 22, 2017

A fix for #307. The batchrunner was getting confused if there was a parameter with a single value that was an iterable type, thinking it was getting a range of values instead. This change provides for explicit variable parameters, which take a sequence of values, and fixed parameters, which take a single value (which may itself be a sequence type).

@coveralls
Copy link

coveralls commented May 22, 2017

Coverage Status

Coverage increased (+0.6%) to 77.027% when pulling 4f5f83a on dict_params_fix into 40bfbb2 on master.

@coveralls
Copy link

coveralls commented May 23, 2017

Coverage Status

Coverage increased (+0.6%) to 77.027% when pulling 52c4331 on dict_params_fix into 40bfbb2 on master.

@jackiekazil jackiekazil self-assigned this May 23, 2017
@jackiekazil jackiekazil added this to the Flagstaff (PyCon Sprints) milestone May 23, 2017
@jackiekazil
Copy link
Member

This all looks good, except for the example models need to be updated...

  • mesa/examples/schelling notebook
  • mesa/examples/forest_fire notebook
  • mesa/docs/tutorials intro notebook

I think that is all of them.

@njvrzm
Copy link
Contributor Author

njvrzm commented May 23, 2017 via email

@dmasad
Copy link
Member

dmasad commented Jun 18, 2017

@njvrzm I can tackle updating the examples if that would be helpful.

def _process_parameters(self, params):
params = copy.deepcopy(params)
bad_names = []
for name, values in params.items():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This typecheck can be enforced with PEP484, will be much simpler. The version requirement will have to be bumped to be at least 3.5.

self.parameter_values = {param: self.make_iterable(vals)
for param, vals in parameter_values.items()}
self.variable_parameters = self._process_parameters(variable_parameters)
self.fixed_parameters = fixed_parameters or {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads like fixed_parameters || {} ;) -- {} should have been a default value for fixed_parameters, instead of None.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this absolutely a no-no in Python. Never use mutable objects as default parameters - they're shared between every invocation of the function, so if they're modified, terrible bugs can creep in. The way this works is quite standard.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

total_iterations *= len(param_range)
with tqdm(total_iterations, disable=not self.display_progress) as pbar:
for param_values in product(*param_ranges):
kwargs = dict(zip(param_names, param_values))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically kwargs = self.variable_parameters

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, Cartesian product(), nvm.

bad_names = []
for name, values in params.items():
if (isinstance(values, str) or
not isinstance(values, collections.Sequence)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails with numpy sequences (e.g. in forest_fire/Forest Fire Model.ipynb)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found an unresolved issue, but with a patch here numpy/numpy#2776 (comment). Sequence.register(np.ndarray) has to be added at somewhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's also resolved with hasattr(values, "__iter__")

Updating the examples and documentation, and fixing the bug that
disregarded numpy sequences.
@dmasad
Copy link
Member

dmasad commented Jul 2, 2017

It looks like the tests are failing due to changes in the visualization API. Can someone take a look and confirm / verify, and see whether it's something that needs to be addressed here, or will self-resolve with the merge?

@a4d442663580
Copy link

It has to be addressed here, the error in https://travis-ci.org/projectmesa/mesa/jobs/249398056#L1038
is basically
TypeError: __init__() missing 1 required positional argument: 'val'.

@a4d442663580
Copy link

a4d442663580 commented Jul 3, 2017

It is because MockAgent takes 3 params,

def __init__(self, unique_id, val):
. The fix: MockModel has to be inserted before val. reset_model in ModularServer needs to be modified for this.

@a4d442663580
Copy link

a4d442663580 commented Jul 3, 2017

In addition to having that bug fixed, the branch also needs to be rebased.

@rht
Copy link
Contributor

rht commented Jul 7, 2017

Heads up: to reduce the number of roundtrips, I have fixed the errs, rebased in #393.

@dmasad dmasad closed this Jul 9, 2017
@TaylorMutch TaylorMutch deleted the dict_params_fix branch December 7, 2017 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants