sphinx-gallery / sphinx-gallery

Sphinx extension for automatic generation of an example gallery
https://sphinx-gallery.github.io
BSD 3-Clause "New" or "Revised" License
414 stars 200 forks source link

Consider adding links to Google colab? #411

Open lesteve opened 6 years ago

lesteve commented 6 years ago

Just a thought (IIRC I saw that in a semi-recent tweet by Jake van der Plas) if you a notebook on github e.g.: https://github.com/sphinx-gallery/sphinx-gallery.github.io/blob/master/notebooks/auto_examples/sin_func/plot_sin.ipynb

You can prepend https://colab.research.google.com/github and get a Google Colab link: https://colab.research.google.com/github/sphinx-gallery/sphinx-gallery.github.io/blob/master/notebooks/auto_examples/sin_func/plot_sin.ipynb

Potential problems:

GaelVaroquaux commented 6 years ago

If we can get around the dependencies issue, it would be awesome. I find it is good to provide several alternatives for computation.

Ping @jakevdp, who works on the collab team, I believe, who can maybe help us with the dependencies.

choldgraf commented 6 years ago

+1 for making it possible

my only hesitation is that the collab isn't open source and only works on google, but I agree many people would find this useful!

jakevdp commented 6 years ago

As far as I know there's no way to automatically install dependencies in Colab at the moment... you basically get a Python 2 or Python 3 kernel, pre-loaded with the provided environment (which contains the core Python data science stack).

For supporting custom environments, Binder is a good option.

I've put badges for both on my book repo, if you want to compare both in practice: https://github.com/jakevdp/PythonDataScienceHandbook

choldgraf commented 6 years ago

note that I don't believe that @jakevdp 's Binder link works currently until either https://github.com/jakevdp/PythonDataScienceHandbook/pull/144/files or https://github.com/jakevdp/PythonDataScienceHandbook/pull/117/files is merged. The current requirements.txt wont work for anybody (and thus won't work for Binder either) because it uses dependencies between numpy and scikit-image that clash with each other if I recall correctly.

I think it works in Collab because it doesn't let you define your own environment...I suppose this is the package environment version of the bias/variance tradeoff :-)

jakevdp commented 6 years ago

Yeah, I'm not sure what to do about that because some of the examples in the book don't work correctly with the newer version of skimage...

choldgraf commented 6 years ago

hmmm, I think if you used Python 3.5 that'd work fine...maybe we could specify this with an environment.yml file?

emmanuelle commented 5 years ago

@jakevdp would the problem be solved with scikit-image 0.14?

choldgraf commented 5 years ago

@emmanuelle thanks for the tip - I actually got this fixed in this PR: https://github.com/jakevdp/PythonDataScienceHandbook/pull/145

shoulda updated this issue, sorry :-)

chaithyagr commented 1 month ago

It's been some time, I'm not sure if its relevant, but perhaps adding some cells for installing all the additional requirements at the start of the notebook could be helpful to create a new notebook specific for collab right? I see this is sorta done already in scikit-learn although for jupyterlite. Is this a viable option? This could be very useful for us at mri-nufft, where we have codes in 2D that can run on CPU, but 3D codes need a GPU to have viable run times in examples.

lucyleeow commented 1 month ago

but perhaps adding some cells for installing all the additional requirements at the start of the notebook

Does https://sphinx-gallery.github.io/stable/configuration.html#own-notebook-cell solve this problem?

lesteve commented 1 month ago

Ah good old days :wink:, I guess https://github.com/sphinx-gallery/sphinx-gallery/issues/25 was even older and was implemented recently in #877 so hope may be an option :wink:.

I guess there are two separate things here:

Side-comments:

chaithyagr commented 1 month ago

Does https://sphinx-gallery.github.io/stable/configuration.html#own-notebook-cell solve this problem?

Indeed this is what I was hoping to use it.

I guess https://github.com/sphinx-gallery/sphinx-gallery/issues/25 was even older and was implemented recently in https://github.com/sphinx-gallery/sphinx-gallery/pull/877 so hope may be an option 😉.

Well it was very useful anyways!

add a Colab link similarly to the Binder and JupyterLite link. This would likely be a welcome addition although I am not involved in sphinx-gallery maintenance these days ...

I can come up with a PR for it.

This seems more complicated and then there is the question of having two notebooks in sphinx-gallery build folder and thus the website or the repo github.io, is it really worth it? Some notebooks may be the exact same content.

Well, I think just an initial cell with %pip install <libraries listed> could be enough so I dont think we might need copies. (I am not yet sure how collab works though, perhaps every modification needs to be a different file?). Let me play around a bit and perhaps come back here.

I think I have also seen stuff like adding rst in the example Python file to have a badge pointing to the notebook. If you have only a few examples that may be a perfectly fine solution

Thats a great intermediate solution for now!

PyTorch uses sphinx-gallery as far as I know (for example see conf.py) and they add a Colab link to their example but probably with some clever sphinx logic outside of sphinx-gallery.

I guess it is a bit easier for them as pytorch is already installed in collab. So they only need the badge.