How to autosave notebooks in Google colab? - google-colaboratory

I was recently working in a notebook on Google Colab and my computer ran out of battery and died. All the progress I had made was not saved anywhere!
I'm very used to having jupyter notebooks, which saves my files pretty much every time I execute a cell.
Is there a way to have an equivalent feature in Google Colab?

Autosave is already implemented in Google Colab, but there is a certain delay between the moment you execute a cell and when the save occurs.
You can try this yourself by going into File>Revision History, executing a cell, and waiting for the list to refresh.
That being said, I have also experienced loss of data in the past, which I can't explain. It might be a glitch.
As a good practice, I try to save every time I remember.
Good luck.

Autosave every 60 seconds by running this "magic command" into a new code cell :
%autosave 60
Colab will confirm it when you run the cell with printing : "Autosave changes every 60 seconds"
To display the list of all magic commands you can use the command :
%lsmagic
Additionally, you can call the Quick Reference Guide, describing all the magic commands and what they do using the command :
%quickref
Enjoy!

Related

A good way to locate colab Notebook (from code inside colab notebook)

Colab code runs on a temporarily allocated machine, thus the running environment is not aware of the notebook location on Google Drive.
I am wondering if there is an API which colab provides, which I may invoke programatically, which could tell me the location of colab notebook in Google Drive (I can manually do it by clicking on: file > Locate in drive, but I need to do this via code in Colab). This would be useful to save the data generated by my code.
Of course I can hard code this path (after mounting the gDrive), but each time, I would need to update it, and if I forget it can even overwrite the previous data. Is there a way where it could be automatically detected? It seems this solution: https://stackoverflow.com/a/71438046/1953366 is walking though every path until it matches the filename, which is not efficient and also will fail in case I have same file name at different location.
Any better solution(s)?

How do I replicate a Google Colab environment onto a GCloud instance?

Ok - total noob on the topic here so this might not even be a good idea.
I have a Google Colab notebook I use for generating images from a textual prompt, where every image takes about 30 secs.
Since I’d like to generate a several hundred I’d like to have an environment set up on GCloud where I run the same process but with a batch of - say - 800 instead of the usual 5-10, and ideally I start the process, close the connection with the machine and come back the next day to find the results.
This might well be a duplicate - because I have no idea of what to search for.
So: is it a good or bad idea and how do I do this?

Unable to save both user changes when coding during same session

How I understand it, in Colaboratory two people can write code in the same document at the same time. This doesn't seem to be working for us: we are coding in separate sections, but are still struggling to figure out to keep both of our changes. We get the notification below:
"The notebook has been changed outside of this session. Would you like to overwrite existing changes?"
or "Save Failed". Then I get two windows with my edits and his edits, but am unaware how to accept both overides.
Your guidance is much appreciated.
The information I was reading was out-of-date. Google Colaboratory removed the real-time edit functionality:
https://github.com/googlecolab/colabtools/issues/355

Why does Google Colab say I have too many sessions?

I'm trying to run two notebooks on Google Colab but could only connect one notebook at a time to the virtual machine. There's a pop-up message saying "Too many sessions. You have too many active sessions. Terminate an existing session to continue." when I click the "connect" button on the second notebook. Does anybody know why?
Screenshot:
Edit: I'm using Google Chrome on Windows 10
Edit March 3, 2020: I ended up not using Colab that day, but I came back the next day and was able to run two Colab notebooks just fine. strange. I had this issue a couple of times since I posted this question, but the error disappeared the following day.
I am used to use it with 2 active sessions. I mean, it gives that error when I try to connect for the third notebook. Today, however, I could only connect 1 notebook at a time. It does not permit the second connection. Therefore, the limit changes time to time.
I have the same problem and I found my solution in this issue. I change the Runtime Shape to Standard in the 2nd notebook, it worked for me.
Try this:
Go to Menu "Runtime" > "Manage Sessions", you should see a list of active sessions. Terminate those you don't need. Although you think you are opening only 2 notebooks, some previous sessions may still linger around if you just close the browser tab.
Note: However, when I hit the problem today, I did the above to check, and I have only 1 other session. Usually, I am able to run up to 3 separate sessions. I am not sure if google is dynamically adjusting this based on overall demand. I also suspect ever since they introduce the Pro, priorities may be given to subscribers.
Im not sure but may be collab provides services to a account one at a time..

Multiple users accessing a same ipynb

I just set up a IPython (0.13.1) Notebook server in order to use it during my introductory course on Python. The server is protected with password and is currently up and running.
Now, I need my students (about 15 people) to access the same ipynb document at the same time, play around with it and eventualy modify the code examples, while making sure anyone overwrites the uploaded version of the ipynb file.
How can I set this up?
First, take a look on teaching with ipython notebook. Try to list what type of applications you want to run on this. On the other hand, it possible to use some cloud computing resources, for example on Heroku.