Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 15 Next »

Running Jupyter Notebook on Axon

Using the sjupyter script

The sjupyter command requires that you activate your conda environment before use if you intend to use libraries within a conda environment.  It also requires that you have Jupyter Notebook 5.7 or greater installed within your Conda environment.  You can ensure that this is the case by running the following command after your conda environment is activated:

conda install notebook>=5.7.8

Axon has a command (sjupyter) that will start up a Jupyter notebook server automatically and give you the URL to connect. To use this command, first connect to the login node (e.g. ssh axon.rc.zi.columbia.edu), then navigate to the directory you want to start your notebook in, and finally run sjupyter.  For instance, if you wanted to run a Jupyter notebook within a directory named my-great-analysis that existed within your home directory, you might run the following commands:

Jupyter helper script
jsp2205@Johns-MacBook-Pro [12:01:49]> ssh axon.rc.zi.columbia.edu
(base) [jsp2205@axon ~]$ cd ~/my-great-analysis
(base) [jsp2205@axon my-great-analysis]$ sjupyter
Waiting for the Jupyter Notebook SLURM job to start...
.
Jupyter Notebook is starting...
............................
Jupyter Notebook has started
    To access the notebook, open this file in a browser:
        file:///home/jsp2205/.local/share/jupyter/runtime/nbserver-86057-open.html
    Or copy and paste one of these URLs:
        http://10.198.24.59:8614/?token=9c53efc98ab7757cb102b875bfee4c5da858f801ae90b906
To turn off Jupyter notebook, run "scancel 45737".
To reprint the URL for the Jupyter notebook, run "/usr/local/bin/sjupyter --get-notebook-url=45737".

The notebook will stay running for the duration of the job so you can reconnect to it if needed using the URL.  If you forget the URL, you can reprint the URL by using the --get-netbook-url option along with the SLURM job id as follows:

(base) [jsp2205@axon ~]$ sjupyter --get-notebook-url=45737
    To access the notebook, open this file in a browser:
        file:///home/jsp2205/.local/share/jupyter/runtime/nbserver-86057-open.html
    Or copy and paste one of these URLs:
        http://10.198.24.59:8614/?token=9c53efc98ab7757cb102b875bfee4c5da858f801ae90b906

To turn off a Jupyter notebook instance, you may use the standard SLURM job cancelling command (scancel).

sjupyter can also be run with any of the standard sbatch flags, so if you want to specify exactly what resources should be available to the Jupyter notebook instance, you may do so by appending sbatch options to the command you run.  For instance, the command below requests that 3 GPUs and 16 GB of memory per CPU be available to the Jupyter notebook:

(base) [jsp2205@axon slurm]$ sjupyter --mem-per-cpu=16G --gres=gpu:3
Waiting for the Jupyter Notebook SLURM job to start...
.
Jupyter Notebook is starting...
..............................
Jupyter Notebook has started
    To access the notebook, open this file in a browser:
        file:///home/jsp2205/.local/share/jupyter/runtime/nbserver-187906-open.html
    Or copy and paste one of these URLs:
        http://10.198.24.59:8074/?token=298fbd14329110b21ecb0d2765858fa836cd6694edabb502
To turn off Jupyter notebook, run "scancel 45747".
To reprint the URL for the Jupyter notebook, run "/usr/local/bin/sjupyter --get-notebook-url=45747".


Running a Jupyter notebook via an SSH tunnel

If you're connecting to Axon without using the VPN you won't be able to reach the Jupyter notebook on the compute node to access it. To get around this you can redirect the traffic from the compute node through the login node to your remote machine via an ssh tunnel.

Launch a Jupyter notebook using sjupyter
(base) [jsp2205@axon slurm]$ sjupyter --mem-per-cpu=16G --gres=gpu:3
Waiting for the Jupyter Notebook SLURM job to start...
.
Jupyter Notebook is starting...
..............................
Jupyter Notebook has started
    To access the notebook, open this file in a browser:
        file:///home/jsp2205/.local/share/jupyter/runtime/nbserver-187906-open.html
    Or copy and paste one of these URLs:
        http://10.198.24.59:8074/?token=298fbd14329110b21ecb0d2765858fa836cd6694edabb502
To turn off Jupyter notebook, run "scancel 45747".
To reprint the URL for the Jupyter notebook, run "/usr/local/bin/sjupyter --get-notebook-url=45747".

Once you have started the Jupyter notebook you will need to make note of the IP and port number of the URL listed in the last line above. In this case the server IP is 10.198.24.59 and the port number is 8074.

When you have this you can open a tunnel from your machine to the the server by running the following command from a terminal on your machine:

ssh -N -L 8080:<notebook ip>:<notebook port> -p 55 <uni>@axon-remote.rc.zi.columbia.edu

In the example below we are running this command where the notebook ip is 10.198.24.59, notebook port is 8074 and the uni is jsp2205.

Starting an ssh tunnel from your local machine
> ssh -N -L 8080:10.198.24.59:8074 -p 55 jsp2205@axon-remote.rc.zi.columbia.edu

The SSH command will seem to hang, but don't worry!  What's actually happening is SSH is running in the background making sure that data is forwarded from Axon to your local computer.

Now take the URL from the sjupyter output (e.g., http://10.198.24.59:8074/?token=298fbd14329110b21ecb0d2765858fa836cd6694edabb502) and replace the IP address and port with localhost:8080 (e.g., http://localhost:8080/?token=298fbd14329110b21ecb0d2765858fa836cd6694edabb502).  You should now have access to jupyter in the same manner as if you were on-campus or using the VPN.

The bash terminal with the tunnel ssh command needs to stay open as long as you're using Jupyter notebook. It may look idle, but it is keeping the tunnel open.

  • No labels