N-Wouda / ALNS

Adaptive large neighbourhood search (and more!) in Python.
https://alns.readthedocs.io/en/latest/
MIT License
442 stars 123 forks source link

Run example notebooks on Google Colab or Binder #122

Closed leonlan closed 1 year ago

leonlan commented 1 year ago

We should also allow running the notebooks on Google Colab or Binder, directly from the documentation. This will make it much easier for people to start using our code.

Originally posted by @N-Wouda in https://github.com/N-Wouda/ALNS/issues/105#issuecomment-1320879772

N-Wouda commented 1 year ago

Binder's really slow to start up. I get annoyed every time I have to use it. Colab's better, but harder to run because we'd need to have a cell somewhere that installs alns (but only when running on Colab).

leonlan commented 1 year ago

Google Colab notebooks can be made by replacing github.com/ with colab.research.google.com/github/:

https://colab.research.google.com/github/N-Wouda/ALNS/blob/master/docs/source/examples/cutting_stock_problem.ipynb

Some things we need to address to make this notebook run:

leonlan commented 1 year ago

To check if we're in Google Colab: https://stackoverflow.com/a/53586419/13184241

try:
  import google.colab
  IN_COLAB = True
except:
  IN_COLAB = False

Manual upload files (assuming we're in colab)

import os

from google.colab import files

if not os.path.isfile(<file-name>):
    uploaded = files.upload()

Hardcode url and make http request:

url = "https://raw.githubusercontent.com/N-Wouda/ALNS/master/docs/source/examples/640.csp"
data = urllib.request.urlopen(url).readlines()
N-Wouda commented 1 year ago

I didn't do this in #120 because there's no good way to make this work in Colab (most of the other projects I looked at used Binder for this reason). In the end I figured it'd be easy enough for users to manually copy the notebook from the repo (the link to it is at the top of each example), put it on Colab, and download the necessary data. Or just download the repo and have a go at it locally.

leonlan commented 1 year ago

I didn't do this in #120 because there's no good way to make this work in Colab (most of the other projects I looked at used Binder for this reason). In the end I figured it'd be easy enough for users to manually copy the notebook from the repo (the link to it is at the top of each example), put it on Colab, and download the necessary data. Or just download the repo and have a go at it locally.

I think we only need these two changes to each notebook to make it work:

I agree that it should not be very hard to get this run locally. Not sure if it's worth the effort.

leonlan commented 1 year ago

I'm closing this issue. It's not worth the extra effort from our side to make these notebooks run on Colab.