Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ENH, DOC: Add support for interactive examples for NumPy withjupyterlite-sphinx#26745

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
rgommers merged 61 commits intonumpy:mainfromagriyakhetarpal:interactive-docs
Jan 28, 2025

Conversation

@agriyakhetarpal
Copy link
Contributor

@agriyakhetarpalagriyakhetarpal commentedJun 18, 2024
edited
Loading

Description

This PR adds support for WASM-powered interactive examples withJupyterLite andjupyterlite-sphinx in the NumPy documentation.

A similar enhancement was made for the documentation for SciPy (scipy/scipy#20019) and that for PyWavelets (PyWavelets/pywt#728).

How to test this

Tip

I have a GitHub Pages website deployed athttps://agriyakhetarpal.github.io/numpy/ through which these changes can be experimented with. The CircleCI deployment does not render the examples properly, however, a fix is available as reported in#26745 (comment) and will be fixed upstream injupyterlite/jupyterlite-sphinx#182.

Update, 24/07/2024: this fix is now available injupyterlite-sphinx version 0.16.2, and the CircleCI deployment should render the examples properly as well.

Key changes (so far)

  1. Configuration forjupyterlite-sphinx indoc/source/conf.py anddoc/Makefile, coupled with changes to styling indoc/source/_static/numpy.css
  2. Updates to the API documentation under files innumpy/ under the "Examples" section in the docstrings for various modules

Note

I have currently left out the following:_datasource.py,_utils_impl.py,_version.py,_array_api_info.py,ctypeslib.py, files undernumpy/_typing/, andnumpy/_core/numerictypes.py.

Tip

The "NumPy user guide" section has not been modified at this time due to the size of the PR (in terms of the number of files modified). However, it can be modified or adapted to a Jupytext notebook similar toscipy/scipy#20303 to make it work well in an interactive set-up.

Important

The NumPy documentation will have to be rebuilt and reuploaded inhttps://github.com/numpy/doc/ for these changes to show up in the official documentation.

What issue does this PR address?

Closes#25969

Additional context

melissawm and jtpio reacted with heart emojimelissawm, rgommers, jtpio, and fjosw reacted with rocket emojiSchefflera-Arboricola reacted with eyes emoji
agriyakhetarpaland others added18 commitsJune 18, 2024 02:17
Co-Authored-By: Albert Steppi <1953382+steppi@users.noreply.github.com>
@charris
Copy link
Member

This could use a release note.

agriyakhetarpal reacted with thumbs up emoji

Comment on lines 470 to 485
..try_examples::

>>>import numpyas np

>>>a= np.memmap('newfile.dat',dtype=float,mode='w+',shape=1000)
>>>a[10]=10.0
>>>a[30]=30.0
>>>del a

>>>b= np.fromfile('newfile.dat',dtype=float)
>>>print(b[10], b[30])
10.0 30.0

>>>a= np.memmap('newfile.dat',dtype=float)
>>>print(a[10], a[30])
10.0 30.0
Copy link
ContributorAuthor

@agriyakhetarpalagriyakhetarpalJun 18, 2024
edited
Loading

Choose a reason for hiding this comment

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

I haven't tested whether every example works because there are way too many, but I did test this and this is one of the examples that doesn't, and fails with the error

ValueError: mmap length is greater than file size

and reducing the shape from1000 to100 doesn't help:OSError: [Errno 43] No such device (edit: this error occurs on subsequent runs on the same cell becausenewfile.dat cannot be loaded)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I'm not sure if there is a way to enable the Pyodide file system or interact with Pyodide directly through a Pythonic interface like this.

@agriyakhetarpal
Copy link
ContributorAuthor

This could use a release note.

@charris, I addressed this in484fe56. Please let me know if a "Highlight" note would be okay or if I should switch this tonew_feature.

[skip cirrus] [skip azp]
@agriyakhetarpal
Copy link
ContributorAuthor

I forgot to skip Azure Pipelines and Cirrus in my previous commit – please don't mind the force-push, my apologies

@agriyakhetarpalagriyakhetarpal marked this pull request as ready for reviewJune 18, 2024 17:48
@agriyakhetarpal
Copy link
ContributorAuthor

agriyakhetarpal commentedJun 18, 2024
edited
Loading

I notice that for some reason the CircleCI build isn't able to load the examples, most likely becausethe files insource/contents/ weren't copied or thatjupyterlite-pyodide-kernel was missing. I shall investigate.

Edit: I think I figured it out – CircleCI is storing the notebooks ina different path, but GitHub Pages does not do so.

Please use my GitHub Pages site to test things out:https://agriyakhetarpal.github.io/numpy/reference/maskedarray.generic.html, I have another branch atagriyakhetarpal#2 and I shall keep both of them in sync based on further commits that I push here.

Copy link
Member

@melissawmmelissawm left a comment

Choose a reason for hiding this comment

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

I also don't see the try examples button locally - should I do anything differently other thanspin docs?

@agriyakhetarpal
Copy link
ContributorAuthor

I also don't see the try examples button locally - should I do anything differently other than spin docs?

@melissawm, I'm not sure – I think you'll need to refresh yourconda/mamba environment, to load the new dependencies or installrequirements/doc_requirements.txt, perhaps? I am able to see the buttons locally.

@melissawm
Copy link
Member

Nevermind - I do see it now!

[skip actions] [skip azp] [skip cirrus]
@agriyakhetarpal
Copy link
ContributorAuthor

d818f8c disablessource maps for JupyterLite, based onscikit-learn/scikit-learn#26246. This brings the size of the JupyterLite build in thedoc/build/lite/ folder from 63.3 MiB (out of the total docs size of 180.7 MiB) to 22.4 MiB (with a total docs size of 140.2 MiB), which is a 22.4% reduction in build size. While doing this has the disadvantage of making debuggingslightly harder for end users, it is favourable for the aspect of saving space, especially for GitHub Pages andhttps://github.com/numpy/doc. I've employed the same configuration forsympy/sympy#27419 as well.

Carreau and rgommers reacted with thumbs up emoji

This reverts commitef3f14b.[skip actions] [skip azp] [skip cirrus]
@agriyakhetarpal
Copy link
ContributorAuthor

Hi@rgommers, we publishedhttps://github.com/jupyterlite/jupyterlite-sphinx/releases/tag/v0.18.0 some moments ago (thanks@steppi!), and I've updated the versions ofjupyterlite-sphinx andjupyterlite-pyodide-kernel in0713994 and369e27d – we are good to proceed now, thanks!

[skip actions] [skip azp] [skip cirrus]
[skip actions] [skip azp] [skip cirrus]
@agriyakhetarpal
Copy link
ContributorAuthor

Commite7972a5 bumps tohttps://github.com/jupyterlite/pyodide-kernel/releases/tag/v0.5.1 that was released today, which brings the recenthttps://github.com/pyodide/pyodide/releases/tag/0.27.1.

(Apologies for the force push!)

Copy link
Member

@melissawmmelissawm left a comment

Choose a reason for hiding this comment

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

Hi@agriyakhetarpal ! The changes look good to me, I've successfully built this PR locally and it seems to work (although the jupyterlite blocks don't work locally).

The CircleCI version of the "Try it" works fine, but when I click "Open in new tab" I see this:

Captura de imagem_20250121_141043

Is this expected? (Maybe it's because it's in CI)

@agriyakhetarpal
Copy link
ContributorAuthor

agriyakhetarpal commentedJan 21, 2025
edited
Loading

Hi@melissawm, thanks for the review! I don't think I can reproduce it with CircleCI. Could you please retry with incognito mode, or with a different internet connection or mobile data if you can? This is what I get:

JupyterLite notebook interface that displays an example from the NumPy documentation, more specifically, np.ma.HardMask, running in a kernel provided by the Pyodide project

For reference, I tried this link:https://output.circle-artifacts.com/output/job/4b11fff4-e43b-4010-af4e-de2e84deed66/artifacts/0/doc/build/html/lite/notebooks/index.html?path=88efbc39_8e7b_4e21_86c0_519bb66f4f6a.ipynb

Based on your screenshot, I guess you're using Firefox. I tried with it as well, both with incognito mode and without, and the JupyterLite UI loads perfectly.

although the jupyterlite blocks don't work locally

They should work locally as well. Could you please share any errors or output that you might be seeing?

@melissawm
Copy link
Member

I think they had a partial outage eariler today so that may have been just bad luck. I'll wait for the check to finish here and test again.

agriyakhetarpal reacted with thumbs up emoji

Copy link
Member

@melissawmmelissawm left a comment

Choose a reason for hiding this comment

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

Now it works fine! Thanks@agriyakhetarpal

agriyakhetarpal reacted with hooray emoji
Copy link
Member

@rgommersrgommers left a comment

Choose a reason for hiding this comment

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

This looks pretty clean, nice work@agriyakhetarpal! Time to give this a go. Thanks to@melissawm and everyone else who contributed as well.

@agriyakhetarpal could you update us on the next steps here? I think it includes upgrading to NumPy 2.2 in Pyodide and enabling use of nightlies, and probably also enabling functionality on the User Guide? Anything else?

melissawm and agriyakhetarpal reacted with heart emoji
@rgommersrgommers merged commit62b43b9 intonumpy:mainJan 28, 2025
4 checks passed
@rgommersrgommers added this to the2.3.0 release milestoneJan 28, 2025
@agriyakhetarpalagriyakhetarpal deleted the interactive-docs branchJanuary 28, 2025 21:45
@agriyakhetarpal
Copy link
ContributorAuthor

agriyakhetarpal commentedJan 28, 2025
edited
Loading

@agriyakhetarpal could you update us on the next steps here? I think it includes upgrading to NumPy 2.2 in Pyodide and enabling use of nightlies, and probably also enabling functionality on the User Guide? Anything else?

Thanks,@rgommers! The following steps here are indeed those, and also, we need to add some docs to resolvegh-27310, similar to@melissawm's SciPy PR (scipy/scipy#22385, which I'll be reviewing and we can adopt similar messaging for NumPy when done).

@rgommers
Copy link
Member

Thanks Agriya. Docs would be a nice next step here indeed, leveraging the work Melissa did for SciPy (the setups and considerations are almost identical). It'd also be fine with me to have a shorter explanation and link to the SciPy docs on the topic for more details.

Upgrading to NumPy 2.2 in Pyodide was last blocked due to [...]

This would be good to prioritize. It seems like there was a way forward (or two possibly) there, by reverting making symbols private for example.

Re User Guide: agreed with waiting for better tracebacks and doing 1-2 pages first.

agriyakhetarpal reacted with thumbs up emoji

@charris
Copy link
Member

@agriyakhetarpaltry_examples.json is giving a parsing error when I try updating circleci to Python 3.13. It looks like perfectly good json, so I wonder where the problem is. Maybe the environment? Any ideas?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@rgommersrgommersrgommers approved these changes

@melissawmmelissawmmelissawm approved these changes

@CarreauCarreauAwaiting requested review from Carreau

Assignees

No one assigned

Projects

None yet

Milestone

2.3.0 release

Development

Successfully merging this pull request may close these issues.

DOC: Add interactive examples with jupyterlite-sphinx

8 participants

@agriyakhetarpal@charris@melissawm@lesteve@Carreau@rgommers@ngoldbaum@steppi

[8]ページ先頭

©2009-2025 Movatter.jp