Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Consider adding links to Google colab? #411

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

Open
lesteve opened this issue Aug 29, 2018 · 12 comments
Open

Consider adding links to Google colab? #411

lesteve opened this issue Aug 29, 2018 · 12 comments

Comments

@lesteve
Copy link
Member

lesteve commented Aug 29, 2018

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:

  • I am not sure whether it is possible to automatically install dependencies in Google Colab
  • Not sure what it provides us on top of the Binder link
@GaelVaroquaux
Copy link
Contributor

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
Copy link
Contributor

+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
Copy link
Contributor

jakevdp commented Aug 29, 2018

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
Copy link
Contributor

choldgraf commented Aug 29, 2018

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
Copy link
Contributor

jakevdp commented Aug 29, 2018

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
Copy link
Contributor

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

@emmanuelle
Copy link
Contributor

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

@choldgraf
Copy link
Contributor

@emmanuelle thanks for the tip - I actually got this fixed in this PR: jakevdp/PythonDataScienceHandbook#145

shoulda updated this issue, sorry :-)

@chaithyagr
Copy link

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
Copy link
Contributor

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
Copy link
Member Author

lesteve commented Jul 24, 2024

Ah good old days πŸ˜‰, I guess #25 was even older and was implemented recently in #877 so hope may be an option πŸ˜‰.

I guess there are two separate things here:

  • 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 ...
  • modify the notebook to install required dependencies at the beginning, for example with %pip install commands. first_notebook_cell as recommended by Lucy, seems the easiest option. In case you wanted some Colab-specific modifications that are not in the "normal" notebook which is the one you get when you click on the "Download Jupyter notebook" link (is it used somewhere else? Not sure ...), then I guess a similar strategy to JupyterLite could be implemented with notebook_modification_function see https://sphinx-gallery.github.io/stable/configuration.html#generate-jupyterlite-links-for-gallery-notebooks-experimental. 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.

Side-comments:

  • 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
  • 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.

@chaithyagr
Copy link

chaithyagr commented Jul 24, 2024

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 #25 was even older and was implemented recently in #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.

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

No branches or pull requests

7 participants