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

Convert example notebooks to Markdown files #243

Merged
merged 3 commits into from
Sep 2, 2022

Conversation

bkktimber
Copy link
Contributor

@bkktimber bkktimber commented Jun 30, 2022

Convert all notebooks in examples to Markdown files (#128). Could you review this PR? @rlouf

A few important guidelines and requirements before we can merge your PR:

  • We should be able to understand what the PR does from its title only;
  • There is a high-level description of the changes;
  • There are links to all the relevant issues, discussions and PRs;
  • The branch is rebased on the latest main commit;
  • Commit messages follow these guidelines;
  • pre-commit is installed and configured on your machine, and you ran it before opening the PR;
  • There are tests covering the changes;
  • The doc is up-to-date;
  • If I add a sampler I added/updated related examples

Consider opening a Draft PR if your work is still in progress but you would like some feedback from other contributors.

@codecov
Copy link

codecov bot commented Jun 30, 2022

Codecov Report

Merging #243 (9d69352) into main (1581424) will not change coverage.
The diff coverage is n/a.

❗ Current head 9d69352 differs from pull request most recent head 7e5738b. Consider uploading reports for the commit 7e5738b to get more accurate results

@@           Coverage Diff           @@
##             main     #243   +/-   ##
=======================================
  Coverage   98.63%   98.63%           
=======================================
  Files          43       43           
  Lines        1757     1757           
=======================================
  Hits         1733     1733           
  Misses         24       24           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Comment on lines 178 to 180
```python

```
Copy link
Member

Choose a reason for hiding this comment

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

Empty cell

states.position["loc"].block_until_ready()
```

In this example the result is a dictionnary and each entry has shape `(num_samples, num_chains)`. Here's how to access the samples of the second chains for `loc`:
Copy link
Member

Choose a reason for hiding this comment

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

It looks like there are some lines missing here?

Copy link
Member

Choose a reason for hiding this comment

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



* L-BFGS algorithm struggles with float32s and log-likelihood functions; it's suggested to use double precision numbers. In order to do that in `jax` a configuration variable needs to be set up at initialization time (see [here](https://jax.readthedocs.io/en/latest/notebooks/Common_Gotchas_in_JAX.html#double-64bit-precision))

Copy link
Member

Choose a reason for hiding this comment

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

The linebreaks are not necessary

name: python3
---

<!-- #region pycharm={"name": "#%% md\n"} -->
Copy link
Member

Choose a reason for hiding this comment

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

Please remove all the <!--- ---> stuff added by PyCharm

Copy link
Member

Choose a reason for hiding this comment

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

many things added by PyCharm in this file, please remove all of them


We plot the resulting tempered density for 5 different values of $\lambda_k$: from $\lambda_k =1$ which correponds to the original density to $\lambda_k=0$. The lower the value of $\lambda_k$ the easier it is to sampler from the posterior log-density.

```python pycharm={"name": "#%%\n"}
Copy link
Member

Choose a reason for hiding this comment

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

same


We first try to sample from the posterior density using an HMC kernel.

```python pycharm={"name": "#%%\n"}
Copy link
Member

Choose a reason for hiding this comment

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

here too

ax.legend(list(lambdas))
```

```python pycharm={"name": "#%%\n"}
Copy link
Member

Choose a reason for hiding this comment

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

here too

name: blackjax
---

<!-- #region id="397995ab" -->
Copy link
Member

Choose a reason for hiding this comment

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

Please clean the file as the previous one.


# Use BlackJAX with TFP

<!-- #region -->
Copy link
Member

Choose a reason for hiding this comment

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

same

@rlouf
Copy link
Member

rlouf commented Jun 30, 2022

This looks great, well done. It looks like some text editors added some unnecessary comments/ids, could you remove them manually please? Next we can work on running the notebooks in CI to include them in the documentation :)

@bkktimber
Copy link
Contributor Author

Sure 😃

@bkktimber
Copy link
Contributor Author

I removed most of the metadata from the markdown files and kept only notebooks' metadata at the top of each file.

I used jupytext.toml file to set jupytext config on my local. Should I include the config file in PR too?

@rlouf
Copy link
Member

rlouf commented Jul 2, 2022

I removed most of the metadata from the markdown files and kept only notebooks' metadata at the top of each file.

Looks much better!

I used jupytext.toml file to set jupytext config on my local. Should I include the config file in PR too?

If it is important for people who clone the repo to have the same experience running / keeping the notebooks in sync with the md files I would say yes.

@bkktimber
Copy link
Contributor Author

bkktimber commented Jul 2, 2022

I added markdown conversion instruction and updated documentation in docs/examples.rst

@rlouf
Copy link
Member

rlouf commented Jul 2, 2022

Great, Now we need to have the CI run the notebooks and display them with images in the documentation so people can visualize their content browsing the doc.

@bkktimber
Copy link
Contributor Author

I follow this link to add rendering configuration in docs/conf.py. Not sure is there another place I need to change?

@rlouf
Copy link
Member

rlouf commented Jul 3, 2022

I don't know. Does it work when you build the doc locally?

@rlouf rlouf linked an issue Jul 3, 2022 that may be closed by this pull request
@bkktimber
Copy link
Contributor Author

Just to drop an update. Rendering matplotlib's plots from markdown don't seem to work. I check how Matplotlib and Scipy deal with their docs. they use .py files with matplotlib.sphinxext.plot_directive.

I'll try to follow those repos. Hope I can finish this issue by this weekend.

@rlouf
Copy link
Member

rlouf commented Jul 5, 2022

Did you manage to build the docs without the images at least?

@bkktimber
Copy link
Contributor Author

yes, I did. the docs without images look fine.

@rlouf
Copy link
Member

rlouf commented Jul 6, 2022

Nice! I'll take a look around too for the figures

@rlouf
Copy link
Member

rlouf commented Jul 6, 2022

I am wondering if you can't just convert the .md files to .ipynb in CI and then use nbsphinx to execute and add to the documentation?

@bkktimber
Copy link
Contributor Author

Oh, that works too. I thought we are going to remove all .ipynb for good.

That means we keep examples in Markdown format on git and convert them into notebooks for documentation. is that correct?

@rlouf
Copy link
Member

rlouf commented Jul 6, 2022

That means we keep examples in Markdown format on git and convert them into notebooks for documentation. is that correct?

That sounds a like a good strategy to me. Notebooks are not under version control, results are displayed in the docs, everyone happy!

@rlouf
Copy link
Member

rlouf commented Jul 26, 2022

Any progress on this @bkktimber ?

@rlouf
Copy link
Member

rlouf commented Aug 17, 2022

This looks good! Two things:

  1. Is it possible to not have use_with_pymc, use_with_numpyro and use_with_tfp in the built documentation? This way we can remove a few large dependencies in requirements-docs.py
  2. I don't see anything related to building the documentation in CI, is that normal?

@bkktimber
Copy link
Contributor Author

bkktimber commented Aug 18, 2022

  1. Is it possible to not have use_with_pymc, use_with_numpyro and use_with_tfp in the built documentation? This way we can remove a few large dependencies in requirements-docs.py

I removed them in the latest commit.

  1. I don't see anything related to building the documentation in CI, is that normal?

Assuming all examples are in Markdown format before committing to the repo, all markdown - jupyter conversions are done in examples/conf.py. I also write steps to prepare example files to build documentation in examples/README

With that assumption, I use make build-docs to build the documentation. I find workflows/build_docs.yml also uses the same commands used in the Makefile. So my understanding is that if building documentation with Makefile works, building documentation in CI with build_docs.yml should work without adding extra steps. Please correct me if I'm wrong.

@rlouf
Copy link
Member

rlouf commented Aug 18, 2022

Looks good. Before merging could you rebase your commits? There should be one commit for converting to .md and another one to build them in CI I believe.

@bkktimber
Copy link
Contributor Author

Got it. I rebased and pushed.

@rlouf
Copy link
Member

rlouf commented Aug 24, 2022

All right this looks fantastic. @junpenglao wdyt?

examples/README.md Outdated Show resolved Hide resolved

## Converting Notebook Files to Text Files

Please convert your `.ipynb` to `markdown` before commit your example to this repo. You can use the command below:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Please convert your `.ipynb` to `markdown` before commit your example to this repo. You can use the command below:
If you implemented your example in a notebook you can convert your `.ipynb` file to Markdown using the command below:

examples/README.md Outdated Show resolved Hide resolved

3. Verify the generated documentation in `docs/builds`

### Execution Times
Copy link
Member

Choose a reason for hiding this comment

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

Just saw that, very useful!

@bkktimber
Copy link
Contributor Author

Thank you 😄 Should I commit your suggestions or leave them to you when the PR is merged?

@rlouf
Copy link
Member

rlouf commented Aug 25, 2022

I will apply my suggestions and rebase once @junpenglao has reviewed the changes.

junpenglao
junpenglao previously approved these changes Aug 26, 2022
Copy link
Member

@junpenglao junpenglao left a comment

Choose a reason for hiding this comment

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

some minor nit, great job!

docs/examples.rst Show resolved Hide resolved
examples/README.md Outdated Show resolved Hide resolved
junpenglao
junpenglao previously approved these changes Aug 31, 2022
@rlouf
Copy link
Member

rlouf commented Sep 1, 2022

@bkktimber It looks like at least one notebook wasn't fully converted and the markdown version is shorter than the notebook version. Could you double-check that every notebook has been fully converted?

@bkktimber
Copy link
Contributor Author

@rlouf not sure what was missing. I double-checked with the document on main and could not find any missing. I uploaded documentation built with this commit here for reference.

Could you suggest the missing part, please?

@rlouf
Copy link
Member

rlouf commented Sep 2, 2022

I was thinking about Introduction.md but it is identical to the original notebook. My bad @bkktimber! At least this PR will make it easy to go over the notebooks and correct the text. I'll rebase the commits if needed and merge, and then we'll just need to look at the docs to see if we can admire your work.

@rlouf
Copy link
Member

rlouf commented Sep 2, 2022

Merging. Great job!

@rlouf rlouf merged commit bebfb0f into blackjax-devs:main Sep 2, 2022
@bkktimber
Copy link
Contributor Author

No worry @rlouf! Let's see how it's doing 😁

@rlouf
Copy link
Member

rlouf commented Sep 3, 2022

A notebook fails in CI, I need to investigate.

@rlouf
Copy link
Member

rlouf commented Sep 22, 2022

Just a quick note to say that I've worked with the documentation recently and it's fantastic, so thank you again!

@bkktimber
Copy link
Contributor Author

It's my pleasure. Glad to know my contribution is helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants