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

Integrate raster plot #623

Merged
merged 11 commits into from
Feb 21, 2023
Merged

Conversation

ssgier
Copy link
Contributor

@ssgier ssgier commented Feb 14, 2023

Issue Number: #362

Objective of pull request: Integrate raster plot

Pull request checklist

Your PR fulfills the following requirements:

  • Issue created that explains the change and why it's needed
  • Tests are part of the PR (for bug fixes / features)
  • Docs reviewed and added / updated if needed (for bug fixes / features)
  • PR conforms to Coding Conventions
  • PR applys BSD 3-clause or LGPL2.1+ Licenses to all code files
  • Lint (flakeheaven lint src/lava tests/) and (bandit -r src/lava/.) pass locally
  • Build tests (pytest) passes locally

Pull request type

Please check your PR type:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation changes
  • Other (please describe):

What is the current behavior?

  • Code to generate raster plot inlined in tutorial notebook

What is the new behavior?

  • Code to generate raster plot exposed in a new module: lava.utils.plots

Does this introduce a breaking change?

  • Yes
  • No

Supplemental information

  • A few tests fail locally, but they do as well on main. I made sure the same subset of tests are failing and that they are unrelated to my change. The last cause is sqlite3.OperationalError: unable to open database file. I am running pytest with Python 3.10.9 under Linux. Is this issue known? If not, perhaps best to discuss separately. I will also take a look into what might be the root cause.
  • I did not re-evaluate the notebook to make the review easier. However, I suggest that I rerun it eventually, for consistency.
  • The assert pasted in the issue asserts that the stride is less than the number of time steps. But the way I read it, it should be less than the number of neurons. I changed it accordingly. Let me know if I misunderstood this. Also, I replaced the assert with raising a ValueError to placate the linter.
  • I am currently not including a unit test because the new method just creates a plot. Let me know if it should still be tested in some way.

Copy link
Contributor

@mathisrichter mathisrichter left a comment

Choose a reason for hiding this comment

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

Hi @ssgier
Thanks for your first contribution to Lava! I'm glad to see that you dug right in and created a PR. This is a good first start; the code that we had pasted in the issue was just meant as a starting point. I believe we could make this more user friendly by exposing more parameters to the user, making the function more flexible. I would also suggest to add input validation to catch errors early and provide meaningful feedback to users when they make a mistake. This should then be unit tested to ensure that the validation works as expected.

src/lava/utils/plots.py Outdated Show resolved Hide resolved
src/lava/utils/plots.py Show resolved Hide resolved
src/lava/utils/plots.py Outdated Show resolved Hide resolved
src/lava/utils/plots.py Outdated Show resolved Hide resolved
src/lava/utils/plots.py Outdated Show resolved Hide resolved
src/lava/utils/plots.py Outdated Show resolved Hide resolved
src/lava/utils/plots.py Outdated Show resolved Hide resolved
src/lava/utils/plots.py Outdated Show resolved Hide resolved
src/lava/utils/plots.py Outdated Show resolved Hide resolved
@mathisrichter
Copy link
Contributor

Regarding your notes:

A few tests fail locally, but they do as well on main. I made sure the same subset of tests are failing and that they are unrelated to my change. The last cause is sqlite3.OperationalError: unable to open database file. I am running pytest with Python 3.10.9 under Linux. Is this issue known? If not, perhaps best to discuss separately. I will also take a look into what might be the root cause.

I am not aware of this issue. Could you look through the issues in Github to see if this has been filed? If not, please create a separate issue. This could be an environment problem.

I did not re-evaluate the notebook to make the review easier. However, I suggest that I rerun it eventually, for consistency.

Agreed. Re-evaluate it once you think the notebook iteself no longer needs to be changed.

The assert pasted in the issue asserts that the stride is less than the number of time steps. But the way I read it, it should be less than the number of neurons. I changed it accordingly. Let me know if I misunderstood this. Also, I replaced the assert with raising a ValueError to placate the linter.

Yes, I believe you are correct. Good catch. :)

I am currently not including a unit test because the new method just creates a plot. Let me know if it should still be tested in some way.

Best practice is to write tests for every qualitatively different behavior of a piece of code.
Things to test here are, for instance:

  • that a figure object is returned with default parameters
  • that a meaningful error is raised for all the invalid inputs you are handling (I suggested adding more)
  • that no errors are raised when parameters are valid

Copy link
Contributor

@mathisrichter mathisrichter left a comment

Choose a reason for hiding this comment

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

Looks very nice, @ssgier !
I remember you still wanted to reevaluate the Jupyter notebook? We can merge the PR once that is done.

tests/lava/utils/test_plots.py Outdated Show resolved Hide resolved
@ssgier
Copy link
Contributor Author

ssgier commented Feb 21, 2023

Following up on the locally failed unit tests: I had a look and there were actually two separate root causes:

  1. On my system, the ulimit suggested in the documentation (4096) was not high enough. Pytest opened over 11K files during the run, a lot of them shared memory files.
  2. The mnist tutorial test attempted to load a weights file which is stored with Git LFS.

Setting a much higher ulimit and installing Git LFS resolved the issues and made all tests pass. I am not running an officially supported Linux distribution, so I'm not sure if the problems can also arise with the supported OSes.

@mathisrichter mathisrichter merged commit 704dc67 into lava-nc:main Feb 21, 2023
@mathisrichter
Copy link
Contributor

Thanks for following up on that.

The first has been a problem for a while - this is due to a problem with the multiprocessing library we are using, I believe. We are working on exchanging that, which will hopefully resolve that issue.

The second could just be missing documentation about having to use Git LFS to get the files. Feel free to add that to the documentation where you think it would be appropriate.

@mathisrichter
Copy link
Contributor

You PR is now merged. Thanks again for your work on this! We very much hope you will continue to support Lava with new features and bug fixes soon! :)

@ssgier ssgier deleted the feature/integrate-raster-plot branch February 28, 2023 16:23
monkin77 pushed a commit to monkin77/thesis-lava that referenced this pull request Jul 12, 2024
* Integrate raster plot

* Improve interface and validation of raster plot utility. Add tests.

* Modified error messages to be full sentences (capital in the beginning, full stop at the end)

* Modified error messages in unit tests.

* Re-evaluate tutorial notebook

* Move spikes initialization to setUp method

---------

Co-authored-by: PhilippPlank <[email protected]>
Co-authored-by: Mathis Richter <[email protected]>
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.

3 participants