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

Remove strong dependency on matplotlib #872

Merged
merged 4 commits into from
Mar 5, 2018

Conversation

tammoippen
Copy link
Contributor

PyNEST only uses pylab (matplotlib.pylab) in raster_plot and voltage_trace. In
tests, this matplotlib is mostly optional - except for test_sp/test_growth_curves.py.
This PR makes matplotlib completely optional for test.

Making matplotlib optional will greatly simplify maintaining the nest homebrew formula in homebrew-core, as homebrew-science will be deprecated.

@jakobj
Copy link
Contributor

jakobj commented Dec 20, 2017

Nice! How about using the full try,except,else construct:

try:
    import pylab
except ImportError:
    pass
else:
    <plot stuff>

This isolated the exception a bit better ;)
Otherwise 👍 from me

Copy link
Contributor

@jakobj jakobj left a comment

Choose a reason for hiding this comment

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

Beautiful :)

Copy link
Contributor

@heplesser heplesser left a comment

Choose a reason for hiding this comment

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

@tammoippen Thanks for this nice fix! But I am seriously wondering about why we have this plot in the test at all!? The code does, as far as I can see, nothing except check that plotting works. So I would remove it completely. I suppose the plot is here because we converted an example into a test at some point.

import pylab
from nest import raster_plot
except ImportError:
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

I would replace this with return and then have the else part as plain code.

Copy link
Contributor Author

@tammoippen tammoippen Dec 22, 2017

Choose a reason for hiding this comment

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

This would be even nicer.

Edit: On second thought: I am not so sure. This is exactly what the else-branch in a try-catch is supposed to do - perform the code that is only executable, when the try is successful. Putting a return there can easily be overlooked...

pylab.legend(('nest', sei.__class__.__name__))
pylab.savefig('sp' + sei.__class__.__name__ + '.png')
raster_plot.from_device(self.spike_detector)
pylab.savefig('sp_raster_plot.png')
Copy link
Contributor

Choose a reason for hiding this comment

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

Why should we plot in a test at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Look at this line. Apparently, the author of the test wanted to debug the tests...

Copy link
Contributor

Choose a reason for hiding this comment

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

@tammoippen I suppose this is a matter of philosophy, but it makes some sense. To make the code more legible, I would suggest

  • to move the definition of the plot() method to right before
  • rename it _plot() to mark it as internal
  • add a docstring like "Can be called by tearDown() to cross-check tests..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@heplesser

  • to move the definition of the plot() method to right before

Which version are you referring to? The complete _plot code in the try: block?

@terhorstd terhorstd added ZC: PyNEST DO NOT USE THIS LABEL I: No breaking change Previously written code will work as before, no one should note anything changing (aside the fix) ZP: PR Created DO NOT USE THIS LABEL S: Normal Handle this with default priority T: Maintenance Work to keep up the quality of the code and documentation. labels Jan 8, 2018
@tammoippen
Copy link
Contributor Author

@heplesser Please can you clearify that for me:

@heplesser

   to move the definition of the plot() method to right before

Which version are you referring to? The complete _plot code in the try: block?

PyNEST only uses pylab (matplotlib.pylab) in `raster_plot` and `voltage_trace`. In
tests, this matplotlib is mostly optional. This makes matplotlib completely optional
for test.
@tammoippen
Copy link
Contributor Author

I applied the changed I suggest @heplesser asked me to do. This PR is hindering nest to be accepted in homebrew core since Dec 13, 2017. I get no replies since Jan 15. Can somebody please have a look?

Copy link
Contributor

@heplesser heplesser left a comment

Choose a reason for hiding this comment

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

@tammoippen We discussed this during our ongoing hackathon and concluded that test should not contain any plotting, and that "try import except pass" can be dangerous in tests. Could you explicitly remove all plotting-related code?

@tammoippen
Copy link
Contributor Author

@heplesser Done as requested.

@tammoippen
Copy link
Contributor Author

Thanks! 🎉 🍰

@tammoippen tammoippen deleted the rm-matplotlib branch March 5, 2018 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I: No breaking change Previously written code will work as before, no one should note anything changing (aside the fix) S: Normal Handle this with default priority T: Maintenance Work to keep up the quality of the code and documentation. ZC: PyNEST DO NOT USE THIS LABEL ZP: PR Created DO NOT USE THIS LABEL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants