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

kwargs can be passed from System.generate_ode_function to the matrix generator #356

Merged
merged 2 commits into from
Jul 24, 2016

Conversation

moorepants
Copy link
Member

@moorepants moorepants commented Jul 14, 2016

This implements an _options attribute to the subclass of ODEFunctionGenerator
and thus allows various options needed for a specific MatrixGenerator to be
supplied all the way at the System.generate_ode_function and
generate_ode_function levels.

  • There are no merge conflicts.
  • If there is a related issue, a reference to that issue is in the
    commit message.
  • Unit tests have been added for the new feature.
  • The PR passes tests both locally (run nosetests) and on Travis CI.
  • All public methods and classes have docstrings. (We use the numpydoc
    format
    .)
  • An explanation has been added to the online documentation. (docs
    directory)
  • The code follows PEP8 guidelines. (use a linter, e.g.
    pylint, to check your code)
  • The new feature is documented in the Release
    Notes
    .
  • The code is backwards compatible. (All public methods/classes must
    follow deprecation cycles.)
  • All reviewer comments have been addressed.

@asmeurer This fixes the issue you had this morning.

…generator.

This implements an _options attribute to the subclass of ODEFunctionGenerator
and thus allows various options needed for a specific MatrixGenerator to be
supplied all the way at the System.generate_ode_function and
generate_ode_function levels.
self._options = {'tmp_dir': None,
'prefix': 'pydy_codegen',
'cse': True,
'verbose': False}
Copy link
Member Author

Choose a reason for hiding this comment

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

This _options dictionary could probably be built by inspecting the methods of the CythonMatrixGenerator, but I didn't try to figure that out.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll be able to give it more of a look over later today or possibly tomorrow. First look though it appears that you are adding more things that a user can set. If this is the case should this be added to a docstring or documentation somewhere? If I remember right the docstring is built dynamically for this class and may be difficult to edit.

@moorepants
Copy link
Member Author

@jbm950, would you mind reviewing this?

'verbose': False}
for k, v in self._options.items():
self._options[k] = kwargs.pop(k, v)

Copy link
Contributor

Choose a reason for hiding this comment

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

This works as a way to pull the arguments out of kwargs properly but ends up setting each item in the self._options dictionary twice. Another way would be to just call kwargs for each item like this

self._options = {}
self._options['tmp_dir'] = kwargs.pop('tmp_dir', None)
self._options['prefix'] = kwargs.pop('prefix', 'pydy_codegen')
self._options['cse'] = kwargs.pop('cse', True)
self._options['False'] = kwargs.pop('verbose', False)

This method probably a bit more verbose and thus readability is reduced but I imagine the performance would improve because each item in the dictionary is only being set once. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, my code might fail if the options aren't in kwargs. I'll look at this again.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, no it is fine. Yeah, I could write it your way too. I'm not sure it really matters, as this is not a place that performance matters.

@jbm950
Copy link
Contributor

jbm950 commented Jul 24, 2016

Looks like you added input support for four new arguments (prefix, tmp_dir, cse and verbose) but only added tests for prefix and tmp_dir. I understand a test for verbose would probably be difficult because it's have to read the output of the function call somehow but would it be difficult to add a test for the cse option?

That, the documentation comments and the question on possibly increasing the efficiency are the only things I have. Other than that it looks like the functionality was extended well.

@moorepants
Copy link
Member Author

Looks like you added input support for four new arguments (prefix, tmp_dir, cse and verbose) but only added tests for prefix and tmp_dir. I understand a test for verbose would probably be difficult because it's have to read the output of the function call somehow but would it be difficult to add a test for the cse option?

All of the options are tested in the CythonMatrixGeneratorTests. All that is needed to test here is whether the arguments are passed in from System.__init__() to CythonMatrixGenerator. The tests I have prove that the args make it there. I don't think it's necessary to check more than one of the optional arguments.

That, the documentation comments and the question on possibly increasing the efficiency are the only things I have. Other than that it looks like the functionality was extended well.

The docstring of system says that any extra kwargs will be passed through to the underlying routines and those routines have clear docstrings about their optional arguments. I don't think added all of the options for the underlying generators is necessary in System's docstrings. But I'll look into adding something if there is a good spot for it.

@jbm950
Copy link
Contributor

jbm950 commented Jul 24, 2016

That works for me then. What did you think about building the options dictionary one item at a time and getting rid of the call to enumerate()?

@jbm950
Copy link
Contributor

jbm950 commented Jul 24, 2016

I'm not sure it really matters, as this is not a place that performance matters.

In that case readability > performance and I think the way you have it currently written makes it easier to see at a glance what is supposed to be in the self._options dictionary.

I'll go ahead and merge this unless you have any objections.

@jbm950 jbm950 merged commit ab85da4 into pydy:master Jul 24, 2016
@moorepants
Copy link
Member Author

FYI, for next time. Please review the list at the top of the PR and check off things that have been taken care of before merging.

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.

2 participants