-
Notifications
You must be signed in to change notification settings - Fork 0
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
DOC: Configure JupyterLite's TryExamples
directive for UNU-RNS tutorial
#5
DOC: Configure JupyterLite's TryExamples
directive for UNU-RNS tutorial
#5
Conversation
>>> from scipy.stats.sampling import TransformedDensityRejection | ||
>>> rng = TransformedDensityRejection(dist, domain=(-1, 1), random_state=urng) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these import statements will be required in these code snippets to make sure that the button works and the examples run without issues for users. I'm not sure if there is a better or cleaner way to do this, because it will create repeated imports (though running them won't be a problem because imports are cached)
Hi, @melissawm! I'm not sure if this is right and addresses all of the concerns we have, but it is an almost complete fix. The only example which hasn't been converted yet on this page is the histogram plot that gets displayed under the ```{code-cell}
---
mystnb: directive, and I'm not sure if it can be converted to a JupyterLite-enabled example at this time because of the alt-text being rendered in the image. However, adding the following: ```{eval-rst}
.. try_examples::
.. plot::
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy.stats import norm
>>> from scipy.stats.sampling import TransformedDensityRejection
>>> from math import exp
>>>
<!-- the rest of the plotting example here -->
``` i.e., not converting to pure Markdown seems to work and displays the plot as needed, but I'm unaware if MyST-NB then chooses to ignore this example or runs it, because there are no additional warnings with this approach and the documentation proceeds to pass – with the JupyterLite example working as well. Another thing we could try is using the |
@ev-br had a good suggestion at the community meeting just now: what if instead of turning jupyter-lite on for each code block, we turned it on for the full notebook? Would that work? (I know we still wouldn't have the outputs necessarily, but I think that would be easier and we would also not need to repeat the import statements between code-blocks, right?) |
I had assumed it would be turned on for the whole notebook. I'd prefer that. |
I'm not sure if we can turn it on for the full notebook – there is a NotebookLite directive that we can use, but it works for notebook files (
Edit: I remembered from the above PR that this PR is merging to:
my second point sounds (a bit) like this method – it is a hybrid option that can provide executed notebooks (the execution would get handled by MyST-NB as is) and therefore outputs of code cells, the Edit 2: oops, Jupytext isn't bidirectional I think – it can convert |
@agriyakhetarpal fortunately that already happens! When MyST-nb runs through and executes the md files, there is an intermediate step that generates ipynb files that can later be linked to (see for example this page, https://jupyterbook.org/en/stable/file-types/notebooks.html - one of the buttons at the top right of the page allows you to download the page as an ipynb.) This can be done - however recovering this link from the sphinx context is very tightly coupled with the jupyterbook theme and I was trying to avoid doing that for now because it's not necessarily in scope for the work that I'm doing. If you have a different solution though, maybe we can try? Thanks for the help! |
Thanks for the additional info, @melissawm! If it's tricky to extract the links, I think we'll still have as a solution the However, if converting other notebooks to this format is the long-term plan, maybe we can keep these notebooks saved after execution, such as with the use of |
I think it may be simpler than that - let me try and take a look again. Thank you again so much - the help is really appreciated! |
Ok, here's a proposal, and let me know if this is reasonable. As a compromise, we would be happy with having a button on the notebook that says "Open this file as a notebook on JupyterLite". When clicking this button, we could open this notebook in a new tab with the existing SciPy JupyterLite kernel. I am not sure how to accomplish this with the jupyterlite-sphinx extension or if this is even the right approach, but I did manage to get an embedded jupyterlite instance with the https://melissawm.github.io/scipy/tutorial/stats/sampling.html There are two problems remaining:
what I get is a jupyterlite window with many many files shown; if you scroll all the way to the bottom of the file list you can indeed find sampling.md. If you right click on it and select "Open as Jupytext Notebook" there is a 404 error: Is this reasonable? I'd be happy to jump on a call and talk about it if it helps. Thanks! |
If this means that the tutorial would initially render as static text, then clicking the button would open the whole tutorial in a new tab as a notebook, this sounds great. |
That's the idea, yes. I think this would be the best of both worlds, as we could keep the outputs correctly rendered in the main page and then, for those looking for the interactivity, this would be a deliberate choice. They would also be able to download the notebook from this new tab. |
I will merge this and keep working on the main PR according to our discussion @agriyakhetarpal - thanks again! |
Reference issue
See scipy#20303 for more information
What does this implement/fix?
This PR addresses the following changes:
jupyterlite-pyodide-kernel
as a dependency to debug changes to Examples enabled withjupyterlite-sphinx
,sampling.md
file with{eval-rst}
to letjupyterlite-sphinx
correctly interpret them and parse code snippets from them, andAdditional information
N/A