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

Include notebook tutorials in documentation #565

Merged
merged 17 commits into from
Sep 26, 2022

Conversation

ernestum
Copy link
Collaborator

@ernestum ernestum commented Sep 14, 2022

Description

While cleaning up the documentation, I found a nice way to integrate the tutorial notebooks with the sphinx documentation.

There is a number of redundant options we could also remove in this PR:

  1. Since the notebooks are executed during the conversion to HTML, they are implicitly tested and we can consider removing the test_examples.py:test_run_tutorial_notebooks_notebooks test.
  2. In the docs circleci job, we could remove the make doctest step since this is executed by the readthedocs job anyways.
  3. I think the integration of the tutorials in the sidebar is optional. I am happy to remove it there when you think it is too cluttered. The tutorials are still discoverable via the algorithm articles.

Testing

Description of how you've tested your changes.

@ernestum ernestum force-pushed the include_tutorials_in_documentation branch from a8499df to 4adb536 Compare September 14, 2022 12:18
@codecov
Copy link

codecov bot commented Sep 14, 2022

Codecov Report

Merging #565 (a364a0e) into master (32467bf) will decrease coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #565      +/-   ##
==========================================
- Coverage   97.28%   97.23%   -0.06%     
==========================================
  Files          88       88              
  Lines        8030     8028       -2     
==========================================
- Hits         7812     7806       -6     
- Misses        218      222       +4     
Impacted Files Coverage Δ
tests/test_examples.py 100.00% <100.00%> (ø)
src/imitation/envs/examples/model_envs.py 96.15% <0.00%> (-3.08%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@ernestum ernestum marked this pull request as draft September 14, 2022 12:41
@ernestum ernestum force-pushed the include_tutorials_in_documentation branch from 63835ad to d5e2861 Compare September 14, 2022 13:11
@AdamGleave
Copy link
Member

In principle seems good, nice to have everything in one place, though we should still link to the examples as these kinds of notebooks are better if people "follow along" rather than just passively reading it.

My only concern is that this may end up making building the docs too slow? Doesn't seem too bad right now: ReadTheDocs is just under 6 minutes, which is fine for CI. But what about for pre-commit hooks? We build docs right now in ci/code_checks.sh, and I don't want that to take more than 30s max as it'd make commits painfully slow. Perhaps we can cache or just exclude building these parts of the doc?

@ernestum
Copy link
Collaborator Author

Building docs becomes slower but test should pass faster if we decide to remove the notebook tests.

Good point with the building docs in the pre-commit hooks. I think there is a way to cache the results. I will have a look into this.

@ernestum ernestum force-pushed the include_tutorials_in_documentation branch from a2b5eb9 to dc6aee0 Compare September 15, 2022 13:23
@ernestum
Copy link
Collaborator Author

ernestum commented Sep 15, 2022

I switched from nbsphinx to myst_nb which supports caching. So the notebooks are only executed in the first run and then only when their contents changes.

Also setting the environment variable NB_EXECUTION_MODE="off" will disable any execution of notebooks during the sphinx build.

@ernestum
Copy link
Collaborator Author

Where do you think we should place the reference to the examples (now called tutorials)? Options that I see:

  1. Each notebook links to itself in github at the top
  2. We link the folder (on github) on the First Steps page.
  3. We add the a "open in colab" badge to the top of each notebook (details see here

What do you prefer?
I am reluctant towards 3. since then we need to ensure the notebooks actually run on colab, which we can not automatically test.
My favorite would be 2. since it does not involve changes to the notebooks.

@ernestum ernestum marked this pull request as ready for review September 15, 2022 16:57
@AdamGleave
Copy link
Member

Where do you think we should place the reference to the examples (now called tutorials)? Options that I see:

  1. Each notebook links to itself in github at the top
  2. We link the folder (on github) on the First Steps page.
  3. We add the a "open in colab" badge to the top of each notebook (details see here

What do you prefer? I am reluctant towards 3. since then we need to ensure the notebooks actually run on colab, which we can not automatically test. My favorite would be 2. since it does not involve changes to the notebooks.

I agree 3 is more effort than it's worth -- I doubt things will work with Colab out of the box.

  1. "First steps" though seems a bit user unfriendly. It's an easy detail to miss.

Of these options my vote would be for 1). But better yet would be if we could make Sphinx automatically add a link? It already includes a (somewhat subtle) edit link, so perhaps we could mod that. Not worth much time though. executablebooks/MyST-NB#148 is a related issue but with no clear resolution.

Copy link
Member

@AdamGleave AdamGleave left a comment

Choose a reason for hiding this comment

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

Change largely LGTM.

In addition to the notebook linking issue discussed above, one concern I have is that this change means we are no longer testing the notebooks on Windows/Mac as we are relying entirely on the RTD executor to test them.

Given this, I'm inclined to think it's worth keeping the test for them in test_examples.py. Skipping them in the doctest build makes sense though -- no reason to run the doctests from the example algorithms on both RTD and CircleCI. WDYT?

@ernestum
Copy link
Collaborator Author

ernestum commented Sep 19, 2022

In addition to the notebook linking issue discussed above, one concern I have is that this change means we are no longer testing the notebooks on Windows/Mac as we are relying entirely on the RTD executor to test them.

Good point. I added them back again but we skip the test when on linux.

Btw: we can ignore the coverage changes here. They are due to the coverage being measured on linux.

Copy link
Member

@AdamGleave AdamGleave left a comment

Choose a reason for hiding this comment

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

LGTM, one minor suggestion.

We've lost some coverage in the test suite itself because skipping notebooks on Linux, and CodeCov is calculated from the Linux run only...

I agree no point in running the notebooks on both Linux CircleCI and RTD, so I'd be OK adding a # pragma: no cover here (with a comment explaining why.)

tests/test_examples.py Outdated Show resolved Hide resolved
@ernestum
Copy link
Collaborator Author

What about the remaining indirect coverage change? Do we also add the pragma: no cover or do we just leave it?

@AdamGleave
Copy link
Member

Is the only remaining indirect coverage change the plotting code in src/imitation/envs/examples/model_envs.py?

I'd be fine ignoring that, we're going to remove that file from imitation soon anyway in #541

We try pretty hard to maintain 100% coverage of the tests themselves to make sure we're not missing test code accidentally. But other code we can be much more lenient on. Especially stuff in the examples directory IIRC we actually exclude from the CodeCov calculation.

@ernestum ernestum merged commit 754c25e into master Sep 26, 2022
@ernestum ernestum deleted the include_tutorials_in_documentation branch September 26, 2022 19:15
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