Draft Forbes Group Website (Build by Nikola). The official site is hosted at:
License: GPL3
ubuntu2004
We describe various strategies for working with CoCalc including version control, collaboration, and using Dropbox.
Note: In some places, such as my aliases, I still use the acronym SMC which refers to Sage Mathcloud – the previous name for CoCalc.
TL;DR
Setup your local computer (once) as discussed below.
Create a CoCalc project, add network access etc., and add your ssh key, and create an alias on your local computer for convenience.
SSH to your CoCalc project and then do something like this:
Setup
Knowledge: To follow these instructions you will need to understand how to work with the linux shell. If you are unfamilliar with the shell, please review the shell novice course. For a discussion of environmental variables see how to read and set environmental and shell variables.
Prior to creating a new project I do the following on my local computer:
Set the following environment variable in one of my startup file. CoCalc automatically sources
~/.bash_aliases
if it exists (this is specifeid in~/.bashrc
) so I use it.:Then in my
~/.hgrc
file I include the following:This way, you specify your mercurial username in only one spot - the
LC_HG_USERNAME
environmental variable. (This is the DRY principle.)A similar configuration should be used if you want to use
git
but variable expansion will not work with git. Instead, we need to set the user and email in the.bash_aliases
file with something like:
git config --global user.name = "$LC_GIT_USEREMAIL"
The SendEnv
instruction will then apply to all smc*
hosts and sends the LC_HG_USERNAME
environmental variable. This allows us to refer to this in the ~/.hgrc
file so that version control commands will log based on who issues them, which is useful because CoCalc does not provide user-level authentication (only project level). Thus, if a user sends this, then mercurial can use the appropriate username. (A similar setup with git should be possible). See issue #370 for more information.
Once the project has been created, I add the contents of my
~/.ssh/id_rsa.pub
to CoCalc using the web interface for SSH Keys. This allows me to login to my projects. (On other systems, this would be the equivalent of adding it to~/.ssh/authorized_keys
.)Add any resources for the project. (For example, network access simplifies installing stuff below, and using a fixed host will prevent the compute node from changing so that the alias setup in the next step will keep working. However, you must pay for these upgrades.)
Create a
~/.hgrc
file like the following:This one enables some extensions I find useful and specifies the username using the
$LC_HG_USERNAME
environmental variable sent by ssh in the previous step.Create a
~/.gitconfig
file like the following:This one provide a useful
git lg
command and specifies the username using the$LC_GIT_USERNAME
etc. environmental variable sent by ssh in the previous step.Install the
mmf_setup
package (I do this also in theanaconda3
environment):Note: this requires you to have enabled network access in step 2.
(optional) Enable this by adding the following lines to your
~/.bash_aliases file
on :This will set your
$HGRCPATH
path so that you can use some of the tools I provide in mymmf_setup
package, for example, thehg ccommit
command which runsnbstripout
to remove output from Jupyter notebooks before committing them.(optional) I find the following settings very useful for tab completion etc., so I also add the following
~/.inputrc
file on CoCalc: (The default configuration hasLC_ALL=C
so I do not need anything else, but see the comment below.)(optional) Update and configure
pip
to install packages as a user:The configuration uses my personal index which allows me to point to various revisions of my software.
Custom Environments
TL;DR:
Create an appropriate environment.yml
file:
We would like to move towards a workflow with custom conda environments. The idea is described here:
Notes:
Apparently this will download a whole bunch of stuff even though we are asking for a clone. This is a known issue: conda/constructor#145, conda#7398.
Once you have a custom environment, you can locate it and make a custom Jupyter kernel for it. First locate the environment:
Now copy another specification, then edit the kernel.json
file. Here is what I ended up with:
The name of the directory here work-py
matches the name of the kernel on my machine where I use the ipykernel
package. This allows me to use the same notebooks going back and forth without changing the kernel.
MayaVi
MayaVi is a nice rendering engine for analyzing 3D data-structures, but poses some problems for use on CoCalc. Here we describe these and how to get it working.
Create an appropriate conda environment and associated kernel as described above. For example:
Create an
environment.yml
file:We need jupyter here so we can install the appropriate CSS etc. to allow or rendering.
Activate anaconda and create the mayavi3 environment:
Create the appropriate kernel:
Find the location of current kernels:
At the time of running, this is:
/ext/anaconda-2019.03/share/jupyter
Activate the environment and install the javascript required to render the output:
This places the javascript etc. in
./.local/share/jupyter/nbextensions/mayavi
and adds an entry in~/.jupyter/nbconfig/notebook.json
:Start a new notebook with your kernel, run it in the classic notebook server ("switch to classic notebook..." under "File").
Start a virtual frame-buffer and then use MayaVi with something like the following in your notebook:
Alternatively, you can skip the context and do something like:
See xvfbwrapper for more details.
System Software
One can definitely build system software from source, linking it into ~/.local/bin/
etc. I am not sure if there is a way of using apt-get
or other package managers yet.
Synchronization
The automatic synchronization mechansim of CoCalc has some issues. The issue (#96) is that when you VCS updates the files, it can change the modification date in a way tha triggers the autosave system to revert to a previous version. The symptom is that you initially load the notebook that you want, but within seconds it reverts to an old (or even blank version).
Thus, it is somewhat dangerous to perform a VCS update on CoCalc: you risk losing local work. Note: none of the work is lost - you can navigate to the project page and look for the "Backups" button on the file browser. This will take you to read-only copies of your work which you can use to restore anything lost this way.
Presently, the only safe solution to update files from outside of the UI is to update them in a new directory.
MathJaX
RClone for Google Drive etc.
The program rclone provides a command-line interface for several applications like Dropbox and Google Drive. Here are some notes about using it:
Make sure internet access is enabled for you project.
Install it by downloading the binary and installing it in~/.local/bin/rclone
. Therclone
software is already installed on CoCalc.Add a remote by running
rclone config
. Some notes:For the "Scope" I chose "Full access all files". More secure would be "Access to files created by rclone only" but this will not work if you add files from another device.
If you want to link a specific folder, you can copy the "ID of the root folder" from the last part of the URL when you open the folder in Google Drive. It looks something like "1RAtwfvaJUk4vULw1z1t1qKWJCsJIRqCZ".
When asked for "Auto config" choose no - this is a "headless" configuration.
I choose the name
gd
for the Google Drive remote. Following the provided link and link your account.You can now explore with:
Notebook Extensions
One can use Jupyter notebook extensions (nbextensions) with only the Classic Notebook interface. As per issue 985, extensions will not be supported with the Modern Notebook interface, but their goal is to independently implement useful extensions, so file an issue if there is something you want. In this section, we discuss how to enable extensions with the Classic Interface.
Open your notebook.
At the bottom of the
File
menu chooseFile/Switch to classical notebook...
. (As per issue 1537, this will not work with Firefox.)At the bottom of the
Edit
menu chooseEdit/nbextensions config
. This will allow you to enable various extensions.
(Old Procedure: Not Needed Anymore)
Enable internet access.
Install the code:
Note: this will also install a copy of
jupyter
which is not ideal and is not the one that is run by default, but it will allow you to configure things.Symbolically link this to your user directory:
Install the extensions:
This step adds the configuration files.
Restart the server.
Reload your notebooks.
You should now see a new menu item: Edit/nbextensions config
. From this you can enable various extensions. You will need to refresh/reload each notebook when you make changes.
Note: This is not a proper installation, so some features may be broken. The Table of Contents (2) feature works, however, which is one of my main uses.)
Raw File Access
If you want to directly access files such as HTML files without the CoCalc interface, you can. This is described here.
Configuration Files
Here are the ultimate contents of the configuration files I have on my computer and on CoCalc. These may get out of date. For up-to-date versions, please see the configurations/complete_systems/cocalc folder on my confgurations project.
Your Computer
~/.bashrc
~/.ssh/config
CoCalc Project
~/.bash_alias
~/.inputrc
~/.hgrc
~/.hgignore
~/.gitconfig
~/.mrconfig
Note: Until symlinks work again, I can't really used myrepos.
Old Information (Out of Data)
The following information is recorded for historical purposes. It no longer applies to CoCalc.
Dropbox no longer works!
Dropbox dropped linux support for all file systems except ext4 which is not an option for CoCalc.
You can use Dropbox on CoCalc:
The first time you do this, it will download some files and you will need to provide a username etc. Note, as pointed out in the link, by default, dropbox wants to share everything. I am not sure of the best strategy for this, but chose to create a separate Dropbox account for the particular project I am using, then just adding the appropriate files to that account.
Once nice think about Dropbox is that it works well with symbolic links, so you can just symlink any files you want into the ~/Dropbox
folder and everything should work fine, but hold off for a moment - first exclude the appropriate folders, then make the symlinks.
If you want to run Dropbox everytime you login, then add the following to your ~/.bash_aliases
on CoCalc:
This did not link with my dropbox account. I had to manually kill the dropbox process, then run the following:
Dropbox and Version Control
Although tempting, one should not use Dropbox to share VCS files since corruption might occur. Instead, you can use Dropbox to sync the working directory (for collaborators) but use selective sync to ignore the sensitive VCS files. Here is one way to do this:
Note: This will remove the .hg
directories! (The behaviour of excluding a file with selective sync is to remove it from the local Dropbox.) Thus, my recommendation is the following:
First copy the files to the Dropbox folder using
cp -r
.Then run the previous find commands to exclude the
.hg
directories.Check this with
dropbox exclude list
.Turn off dropbox
dropbox stop
Now replace the folders with appropriate symlinks.
Finally, start dropbox again
dropbox start
.
Here is a summary for example. I am assuming that you have a version controlled project called ~/paper
that you want mirrored in your Dropbox folder:
Remember to do the same on your local computer!
Dropbox Issues
Occasionally there will be issues with dropbox. One of the issues may be when the host for the project changes (this happens for example when you add or remove member hosting for a project). To deal with this you might have to unlike or relink the computer to Dropbox:
Make sure your project has "Internet access" in Settings.
dropbox stop
on the CoCalc server.Sign into Dropbox with the account you have linked to the project. (Hint: if you can't remember the name, look in your main dropbox project where you should have shared this with the CoCalc project. It can be useful to use Incognito mode or a different browser to sign into an auxilliary account.)
Go to Settings (top right), then the Security tab.
In the Devices section, unlink the device.
Restart dropbox with
~/.dropbox-dist/dropboxd
. This should give you a link to paste into the browser you have signed into and it will relink.