Table of Contents | ||
---|---|---|
|
Running Jupyter Notebook on Axon
...
Using the sjupyter script
Warning | ||
---|---|---|
The sjupyter command is meant to quickly run a jupyter notebook using the default anaconda environment with one command. For more complicated usage in batch files and such running the command directly from an interactive session or batch file is a better approach.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:
|
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:
...
To turn off a Jupyter notebook instance, you may use the standard SLURM job cancelling command (scancel). Note that there is a time limit of 5 days for jobs that run on the shared or burst partitions (see Slurm Overview), so any Jupyter notebook servers running on these partitions will be cancelled automatically after the time limit is exceeded.
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:
Code Block | ||||
---|---|---|---|---|
| ||||
(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
...
Launching a jupyter notebook from a slurm session requires two things, a python environment which has jupyter installed (the default anaconda environment from modules meets this requirement) and a special shell variable initialized (XDG_RUNTIME_DIR="").
...
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.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| [aa3301@axon ~
| |||||||
(base) [jsp2205@axon slurm]$ srunsjupyter --mem-pty -c 8 per-cpu=16G --gres=gpu:23 -t 0-01:00 /bin/bash [aa3301@ax08 ~]$ ml anaconda3-2019.03 [aa3301@ax08 ~]$ XDG_RUNTIME_DIR="" [aa3301@ax08 ~]$ jupyter notebook --no-browser --ip=$(hostname -I | awk '{print $1}') --port=$(shuf -i 8888-9000 -n1) [I 11:43:24.018 NotebookApp] [nb_conda_kernels] enabled, 1 kernels found [I 11:43:25.289 NotebookApp] JupyterLab extension loaded from /share/apps/anaconda3-2019.03/lib/python3.7/site-packages/jupyterlab [I 11:43:25.289 NotebookApp] JupyterLab application directory is /share/apps/anaconda3-2019.03/share/jupyter/lab [I 11:43:25.296 NotebookApp] [nb_conda] enabled [I 11:43:25.296 NotebookApp] Serving notebooks from local directory: /share/zrc/aa3301 [I 11:43:25.296 NotebookApp] The Jupyter Notebook is running at: [I 11:43:25.296 NotebookApp] http://10.198.24.59:8959/?token=9e73528834e240a01eeffe298d35a04d3d670bbd8b6b4b87 [I 11:43:25.297 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [C 11:43:25.307 NotebookApp] 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:///sharehome/zrc/aa3301jsp2205/.local/share/jupyter/runtime/nbserver-222039187906-open.html Or copy and paste one of these URLs: http://10.198.24.59:89598074/?token=9e73528834e240a01eeffe298d35a04d3d670bbd8b6b4b87 [I 11:43:48.650 NotebookApp] 302 GET /?token=9e73528834e240a01eeffe298d35a04d3d670bbd8b6b4b87 (128.59.216.48) 1.55ms |
In the example above we use commands to determine the ip and make a random port number. The notebook is accessed via the url near the bottom as instructed. In this approach the notebook will end when the job expires (we asked it to last for an hour in the first command) or when the application is quit (using CTRL + C) in the terminal.
Running a Jupyter notebook in a batch job
Jupyter notebooks can easily can be run in a batch session, the only complication being discovering the server where the notebook is running, which can be resolved by looking at the slurm output file or using a predetermined port and looking up the running server name in squeue.
Code Block | ||||
---|---|---|---|---|
| ||||
#!/bin/sh
#
# running a Jupyter Notebook in Slurm.
#
#SBATCH --job-name=jupyter-notebook # The job name.
#SBATCH -c 6 # The number of cpu cores to use.
#SBATCH --time=5:00:00 # The time the job will take to run.
#SBATCH --mem-per-cpu=1gb # The memory the job will use per cpu core.
#SBATCH --gres=gpu:1 # The number of GPUs (1) and the (optional) variety (gtx1080)
ml anaconda3-2019.03
# conda activate myenvironment
# The above command here is where you would activate your custom conda environment (note the environment must have jupyter installed see https://jupyter.org/install
XDG_RUNTIME_DIR=""
jupyter notebook --no-browser --ip=$(hostname -I | awk '{print $1}') --port=$(shuf -i 8888-9000 -n1)
# End of script |
...
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:
Code Block | ||
---|---|---|
| ||
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.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| [aa3301@axon test]$ sbatch sbatch-jupyter.sh
Submitted batch job 47255
[aa3301@axon test]$ tail -f slurm-47255.out
[I 16:33:21.425 NotebookApp] [nb_conda_kernels] enabled, 1 kernels found
[I 16:33:23.445 NotebookApp] JupyterLab extension loaded from /share/apps/anaconda3-2019.03/lib/python3.7/site-packages/jupyterlab
[I 16:33:23.445 NotebookApp] JupyterLab application directory is /share/apps/anaconda3-2019.03/share/jupyter/lab
[I 16:33:23.463 NotebookApp] [nb_conda] enabled
[I 16:33:23.464 NotebookApp] Serving notebooks from local directory: /share/zrc/aa3301/test
[I 16:33:23.464 NotebookApp] The Jupyter Notebook is running at:
[I 16:33:23.464 NotebookApp]
| |||||||
> 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=
...
Once you have successfully pasted the URL in your browser you can press CTRL + C to quit the tail, and unlike the previous version of the in the interactive session the jupyter notebook will continue running for the duration specified in the batch file, which is 5 hours in the example above.
If you finish earlier and you no longer need to use your notebook please cancel your job so others can use the resources of the cluster. You can run jobstats.py to see your running jobs and then stop them using the scancel command.
...
language | bash |
---|---|
theme | Midnight |
title | Cancelling your running job when its done. |
...
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.
Info |
---|
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. |