Texas A&M UniversityWork In Progress

Run JupyterLab interactively on the Arseven HPC cluster via SSH tunnel and local web browser.

Using JupyterLab

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

1. Create a batch script

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 (uncomment if needed)
#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}

2. Submit the job to the scheduler

$ sbatch run.sh
Submitted batch job 233

3. View 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
...

[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

4. Follow the instructions in the output

  1. Start an SSH tunnel from your workstation. 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.

    After running this, the command will appear to "hang" or "do nothing" — it will not return until you use Ctrl+C or close that terminal. This is normal.

  2. Open a web browser and go to the URL specified in the output. From the example above, the following link would be used: http://127.0.0.1:32939/lab?token=a03bfe2bb814f4322f7d6611c3326c60675dd99adad88de9