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

TST: Add Notebook tests #203

Merged
merged 13 commits into from
Jul 11, 2022
Merged

TST: Add Notebook tests #203

merged 13 commits into from
Jul 11, 2022

Conversation

Jacob-Stevens-Haas
Copy link
Member

Tests are skipped by default.  Run `pytest -m "slow"` in order
to run slow tests.

Also require upgrading to pytest ~=6.0.0 in order to read
pyproject.toml configs.

Change pyproject.toml black table to use extend-exclude, which
also excludes anything gitignored

To test this change, run

pytest --co

and

pytest --co -m "slow"

The first shows that regular testing ignores the notebooks. The second shows that the tests can be selected.

    Tests are skipped by default.  Run `pytest -m "slow"` in order
    to run slow tests.

    Also require upgrading to pytest ~=6.0.0 in order to read
    pyproject.toml configs.

    Change pyproject.toml black table to use extend-exclude, which
    also excludes anything gitignored
@Jacob-Stevens-Haas
Copy link
Member Author

Not sure if we want to run notebook tests in CI, but if so, it's as simply as adding -m "slow and not slow" to the pytest line in the workflow. Thoughts?

@akaptano
Copy link
Collaborator

I think it's a good idea to run all the notebook tests in CI too.

@akaptano
Copy link
Collaborator

My only comment is to add some comments to test_notebook since some of the lines are somewhat opaque.

Best,
Alan

@codecov-commenter
Copy link

codecov-commenter commented Jun 14, 2022

Codecov Report

Merging #203 (285b02c) into master (632585a) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #203   +/-   ##
=======================================
  Coverage   93.48%   93.48%           
=======================================
  Files          34       34           
  Lines        3425     3425           
=======================================
  Hits         3202     3202           
  Misses        223      223           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 632585a...285b02c. Read the comment docs.

@Jacob-Stevens-Haas
Copy link
Member Author

Added notebook tests to CI - I'll check the CI report, but if it works, should we remove papermill?

@akaptano
Copy link
Collaborator

Looks like you need to add sympy as a requirement, fix a timebase issue, etc. to get these tests working.

@Jacob-Stevens-Haas
Copy link
Member Author

Jacob-Stevens-Haas commented Jun 15, 2022

Wdym timebase issue? It looks like the four failures were 1 sympy, 2 dead kernels, and 1 ZeroDivisionError (solved in my other PR, but I can move that commit over to a separate PR if you'd like since it's independent.)

@akaptano
Copy link
Collaborator

Given what you said about the fix, maybe it is better to merge this in after merging in the other pull request?

@Jacob-Stevens-Haas
Copy link
Member Author

Yeah, definitely post #185. At that point it would be a question of whether we can resolve the DeadKernelError in GH actions, send them to the AMATH server for test, or just skip them.

Jacob-Stevens-Haas and others added 4 commits July 5, 2022 15:49
Add jupytext dev requirements.  Jupytext creates notebooks from scripts.
Add publish_notebook.py script to regenerate and run notebook.
Demonstrated on the shortest notebook we have.

Added some flake8 config to handle the idiosyncracies of python
files created from notebooks (long comments and imports not at top)
@Jacob-Stevens-Haas
Copy link
Member Author

Added method to refactor and test notebooks much faster by putting data generation in example_data.py and putting mock data generation in mock_data.py. See the updated examples/README.rst. Note that these changes require a new development requirement: jupytext. This package allows syncing of .py and .ipynb files.

My thoughts were that we needed:

  • debug notebooks in IDE
  • Easy diff views of notebooks
  • very fast testing of notebooks
  • easy for regular users to still use example notebooks out of the box

I think this solution, demonstrated on examples/2_introduction_to_sindy, meets all those needs. A lot of design choices went into this PR that could go various ways, and I'm happy to hear input & change things.

Goal is to get all examples in .py format, then use examples/publish_notebook.py to convert the python file to a notebook and run it. However, for this PR, I would suggest we remove the slow, complete notebook tests from CI, since the current PR is a discrete improvement on previous functionality. Notebooks can be later converted to the new test-compatible format and will automatically become covered by tests.

@akaptano , @znicolaou , what are your thoughts?

@Jacob-Stevens-Haas
Copy link
Member Author

Having trouble with the pre-commit hook for jupytext: mwouts/jupytext#974

@Jacob-Stevens-Haas Jacob-Stevens-Haas mentioned this pull request Jul 6, 2022
@Jacob-Stevens-Haas
Copy link
Member Author

Ok @akaptano , @znicolaou, this PR should be good to review - in particular, look at the new notebook directory format. I removed the CI testing for notebooks not yet converted to this new format because they were running for several hours, which really gets in the way of development. As notebooks get converted to the new format, the test will automatically pick them up.

A good example of the power of this commit: testing notebook 5 went from 30+ minutes to 7.5 seconds! 🚀

@akaptano
Copy link
Collaborator

@znicolaou and @Jacob-Stevens-Haas Let's try to get this done this week, and get the release published. I am worried about delaying the release too long, considering the substantial changes that have been made in the past weeks. Thanks for your monumental efforts on the code!

Best,
Alan

@akaptano
Copy link
Collaborator

Reminder (to myself) that when a new release comes out we need to update all the binder links in the notebooks. Presumably there is some automatic way to do this but it is easy to do, just hard to remember to do!

@Jacob-Stevens-Haas Jacob-Stevens-Haas merged commit d0d96f4 into dynamicslab:master Jul 11, 2022
@Jacob-Stevens-Haas Jacob-Stevens-Haas deleted the notebook-tests branch July 11, 2022 20:45
jpcurbelo pushed a commit to jpcurbelo/pysindy_fork that referenced this pull request Apr 30, 2024
jpcurbelo pushed a commit to jpcurbelo/pysindy_fork that referenced this pull request May 9, 2024
This broke with a refactoring a while ago and needed adjustment to new
xarray versions. Reported in neuralhydrology/neuralhydrology#133.

Also fixes an issue where the metrics csv file would be empty for multi-frequency runs.
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