Skip to main content

Using JupyterLab

Using Jupyter Lab

Jupyter Lab may be used via an SSH tunnel and your web browser.

  1. Create a batch script (e.g. run.sh) containing the following:
#!/bin/bash

#SBATCH --time=01:00:00 # Request 1 hour of wall time
#SBATCH --ntasks=1 # Only open 1 instance of the server
#SBATCH --cpus-per-task=4 # Use 4 cores
#SBATCH --mem=8G # Use 8GB of RAM
##SBATCH --gres=gpu:1 # Use 1 GPU
#SBATCH --output=server.output.%j # Send output stream to file named 'server.output.{jobid}'

readonly PORT=$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()')

module purge
module load JupyterLab/4.0.3-GCCcore-12.2.0

cat 1>&2 <<END
1. SSH tunnel from your workstation using the following command:

ssh -L ${PORT}:${HOSTNAME}:${PORT} -N ${USER}@arseven.stat.tamu.edu

2. Use the URL returned by Jupyter that looks similar to the following:

http://127.0.0.1:${PORT}/lab?token=b16726df7fbb0f05142df6cb40ea279c517fc86c8ee4a86c

When done using Jupyter, terminate the job by:

1. Issue the following command on the login node:

scancel -f ${SLURM_JOB_ID}
END

jupyter-lab --no-browser --ip ${HOSTNAME} --port ${PORT}
  1. Submit the job to the scheudler:
$ sbatch run.sh
Submitted batch job 233
  1. View the contents of the output file - modify the job id to match the output you receive from the above command:
$ cat server.output.233

1. SSH tunnel from your workstation using the following command:

ssh -L 32939:c01:32939 -N NetID@arseven.stat.tamu.edu

2. Use the URL returned by Jupyter that looks similar to the following:

http://127.0.0.1:32939/lab?token=b16726df7fbb0f05142df6cb40ea279c517fc86c8ee4a86c

When done using Jupyter, terminate the job by:

1. Issue the following command on the login node:

scancel -f 243

[I 2024-04-22 15:21:28.362 ServerApp] Package jupyterlab took 0.0000s to import
[I 2024-04-22 15:21:28.385 ServerApp] Package jupyter_lsp took 0.0231s to import

[TRUNCATED ...]

[C 2024-04-22 15:21:28.973 ServerApp]

To access the server, open this file in a browser:
file:///home/NetID/.local/share/jupyter/runtime/jpserver-234018-open.html
Or copy and paste one of these URLs:
http://c01:32939/lab?token=a03bfe2bb814f4322f7d6611c3326c60675dd99adad88de9
http://127.0.0.1:32939/lab?token=a03bfe2bb814f4322f7d6611c3326c60675dd99adad88de9

[TRUNCATED ...]
  1. Follow the instructions in the output. More specifically:
  2. The first step tells you to start an SSH tunnel from your workstation. To do this, open another terminal window, and copy-paste the SSH command (e.g. ssh -L 32939:c01:32939 -N NetID@arseven.stat.tamu.edu) into the other terminal. Note that after running this, the command will appear to "hang" or "do nothing" as it will not return until you use Ctrl+C or close that terminal.
  3. Open a web browser and go to the URL specifed in the output. From the example above, the following link would be used: http://127.0.0.1:32939/lab?token=a03bfe2bb814f4322f7d6611c3326c60675dd99adad88de9