Difference between revisions of "Jupyter on Euler and Leonhard Open"

From ScientificComputing
Jump to: navigation, search
(Introduction)
(23 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
==Introduction==
 
==Introduction==
Since Jupyter notebooks are becoming more widely used among the scientific community, the HPC group developed a script that you can run on your local computer. This shell script then starts a Jupyter notebook in a batch job on Euler/Leonhard Open (depending on which cluster you choose) and connects your local browser with it.
+
Jupyter notebooks and Jupyter Lab are becoming more widely used among the scientific community at ETH. We therefore developed a script that you can run on your local computer to start Jupyter notebooks or Jupyter lab on Euler. The shell script starts a Jupyter in a batch job on Euler and connects your local browser with it.
  
At the moment, '''the script can be used with Linux and Mac computers'''. '''There is no support for Windows computers'''. Maybe Windows user can try to run the script using Windows subsystem for Linux (WSL), but this has not been tested yet.
+
The script runs on Linux, macOS and Windows (using WSL/WSL2 or git bash).
  
 
Please note, that with this script we are addressing beginners that start to use Jupyter notebooks on the cluster. It is not addressing advanced users that need a wide range of additional features going beyond simple Jupyter notebooks. Advanced users can take the script and adapt it, such that it can be used with other Python versions (centrally installed, or local installations) and add support for GPU, adding new kernels etc.
 
Please note, that with this script we are addressing beginners that start to use Jupyter notebooks on the cluster. It is not addressing advanced users that need a wide range of additional features going beyond simple Jupyter notebooks. Advanced users can take the script and adapt it, such that it can be used with other Python versions (centrally installed, or local installations) and add support for GPU, adding new kernels etc.
  
Please note, that the script uses the old software stack on Euler and can in its current state not be used with tools from the new software stack.
+
==Installation==
 +
Download the repository with the commnad
 +
git clone https://gitlab.ethz.ch/sfux/Jupyter-on-Euler-or-Leonhard-Open
 +
Mac OS X:
 +
git clone https://gitlab.ethz.ch/sfux/Jupyter-on-Euler-or-Leonhard-Open.git
 +
After downloading the script from gitlab.ethz.ch, you need to change its permissions to make it executable
 +
cd Jupyter-on-Euler-or-Leonhard-Open/
 +
chmod 755 start_jupyter_nb.sh
  
==Updates==
+
===Prerequisites===
* 01 Oct 2019 &mdash; Today the script has been updated, such that the jupyter notebooks have next to the Python 3.6 kernel also a bash and an R kernel (3.6.0 on Euler, 3.5.1 on Leonhard Open) available. If you use an older version of the script and you would like to use the newly added kernels, then you need to update your script from the gitlab repository with the command <tt>git pull origin master</tt>
 
 
 
samfux@bullvalene:~/Jupyter-on-Euler-or-Leonhard-Open$ git pull origin master
 
warning: redirecting to https://gitlab.ethz.ch/sfux/Jupyter-on-Euler-or-Leonhard-Open.git/
 
From https://gitlab.ethz.ch/sfux/Jupyter-on-Euler-or-Leonhard-Open
 
  * branch            master    -> FETCH_HEAD
 
Already up to date.
 
samfux@bullvalene:~/Jupyter-on-Euler-or-Leonhard-Open$
 
 
 
==Getting the script==
 
The script is available on the Gitlab instance of ETH Zurich:
 
 
 
https://gitlab.ethz.ch/sfux/Jupyter-on-Euler-or-Leonhard-Open
 
 
 
==Prerequisites==
 
 
In order to use this script, users need to make sure, that they have set up SSH keys for passwordless access to the cluster:
 
In order to use this script, users need to make sure, that they have set up SSH keys for passwordless access to the cluster:
  
 
  https://scicomp.ethz.ch/wiki/Accessing_the_clusters#SSH_keys
 
  https://scicomp.ethz.ch/wiki/Accessing_the_clusters#SSH_keys
  
Please note that the example on the wiki refers to the Euler cluster and for Leonhard Open, then hostname needs to be changed from
+
Please make sure that xdg-open is installed. This package is used to automatically start your default browser. You can install it with the following command:
 
 
euler.ethz.ch
 
to
 
 
 
login.leonhard.ethz.ch
 
 
 
please make sure that xdg-open is installed. This package is used to automatically start your default browser. You can install it with the following command:
 
  
 
CentOS:
 
CentOS:
Line 47: Line 32:
 
Further more, the script requires that there is a Python installation available, which is usually included in the Linux distribution or Mac OS.
 
Further more, the script requires that there is a Python installation available, which is usually included in the Linux distribution or Mac OS.
  
==Installation==
+
===Security token vs. password setup===
 +
Please note that a part of the script (parsing of the ports) requires that you use jupyter notebooks with the security tokens. If you configure a password instead, such that you can use the jupyter notebook without the security token, then the script will not work anymore (it cannot parse the port on the remote compute node) without adapting it.
 +
 
 +
===Download and setup===
 +
The script is available on the Gitlab instance of ETH Zurich:
 +
 
 +
https://gitlab.ethz.ch/sfux/Jupyter-on-Euler-or-Leonhard-Open
 +
 
 
Download the repository with the command
 
Download the repository with the command
  
 
  git clone https://gitlab.ethz.ch/sfux/Jupyter-on-Euler-or-Leonhard-Open
 
  git clone https://gitlab.ethz.ch/sfux/Jupyter-on-Euler-or-Leonhard-Open
 +
 +
Mac OS X:
 +
 +
git clone https://gitlab.ethz.ch/sfux/Jupyter-on-Euler-or-Leonhard-Open.git
  
 
After downloading the script from gitlab.ethz.ch, you need to change its permissions to make it executable
 
After downloading the script from gitlab.ethz.ch, you need to change its permissions to make it executable
Line 56: Line 52:
 
  chmod 755 start_jupyter_nb.sh
 
  chmod 755 start_jupyter_nb.sh
  
==Running the script==
+
===Software stack===
The start_jupyer_nb.sh script needs to be executed on your local computer:
+
Please note that currently the old software stack is still set a default (this will change). The script is using the new software stack (unless you explicitly request the old software stack with the option -s old (or --softwarestack old). Therefore please make sure that you set the new software stack as permanent default by using the command
 +
 
 +
set_software_stack.sh new
 +
 
 +
You can find more information about this script on our wiki:
 +
 
 +
https://scicomp.ethz.ch/wiki/Setting_permanent_default_for_software_stack_upon_login
 +
 
 +
===Creating SSH keys for the Jupyter script with a Windows computer (using git-bash)===
 +
With git-bash, you can use the same command as for Linux/Mac to create your SSH keys:
 +
 
 +
* Start git-bash
 +
* Run the command ssh-keygen to create the SSH key pair
 +
ssh-keygen -t ed25519 -f $HOME/.ssh/id_ed25519_euler
 +
* Enter a passphrase to protect your SSH keys
 +
* Use the ssh-copy-id command to copy your '''public''' (never your private) key to Euler
 +
ssh-copy-id -i ~/.ssh/id_ed25519_euler.pub '''username'''@euler.ethz.ch
 +
* (here you need to replace '''username''' with your ETH username)
 +
* Enter your password
 +
 
 +
After creating the keys, we strongly recommend to create an SSH config file in $HOME/.ssh
 +
 
 +
* Change to your .ssh directory
 +
cd $HOME/.ssh
 +
* Create an SSH config file to specify the path to your SSH key
 +
echo -e "Host euler\nHostName euler.ethz.ch\nUser '''username'''\nIdentityFile ~/.ssh/id_ed25519_euler" > config
 +
* (here you need to replace '''username''' with your ETH username)
  
./start_jupyter_nb.sh CLUSTER ETH_USERNAME NUM_CORES RUN_TIME MEM_PER_CORE
+
At this stage, passwordless login to Euler should work. You can test this with the command
  
{| class="wikitable
+
ssh username@euler.ethz.ch
!Parameter
 
!Description
 
|-
 
|CLUSTER
 
|Name of the cluster (Euler or LeoOpen)
 
|-
 
|ETH_USERNAME
 
|ETH username for which the notebook should be started
 
|-
 
|NUM_CORES
 
|Number of cores to be used on the cluster (maximum: 36)
 
|-
 
|RUN_TIME
 
|Run time limit for the jupyter notebook on the cluster (HH:MM)
 
|-
 
|MEM_PER_CORE
 
|Memory limit in MB per core
 
|}
 
  
Example:
+
* (here you need to replace '''username''' with your ETH username)
  
./start_jupyter_nb.sh Euler sfux 4 01:20 2048
+
But now you still have to enter your passphrase. In order to not have to type your passphrase all the time, you can use an SSH agent, which is already included in git-bash
  
[[File:Jupyter_on_Euler_and_Leonhard_Open.png|thumb|none|800px|Example for running a Jupyter notebook on the Euler cluster]]
+
* Start git-bash
 +
* Start the SSH agent for the current terminal
 +
ssh-agent /bin/bash
 +
* Add your SSH key to the SSH agent
 +
ssh-add ~/.ssh/id_ed25519_euler
 +
* Enter your passphrase
  
==Running multiple notebooks in a single Jupyter instance==
+
As long as this terminal is open, you can access Euler with
If you run Jupyter on the Leonhard cluster, using GPUs (the default version of the uses a python_cpu module, which does not support GPU usage. You would need to change the Python version in the script to enable GPU usage), then you need to make sure a notebook is correctly terminated before you can start another one.
+
ssh username@euler.ethz.ch
 +
(here you need to replace '''username''' with your ETH username)
 +
without having to type a password or passphrase. As soon as you exit the terminal, then the SSH agent will be stopped.
  
If you don't properly close the first notebook and run a second one, then the previous notebook will still occupy some GPU memory and have processes running, which will throw some errors, when executing the second notebook.
+
Now you are ready to clone the Jupyter script and to execute it in the terminal with the SSH agent. Please note that you only need to create the SSH once, but you need to setup the SSH agent every time you would like to run the Jupyter script.
  
Therefore please make sure that you stop running kernels in the "running" tab in the browser, before starting a new notebook.
+
===Using SSH keys with non-default names===
 +
Since the reopening of Euler and Leonhard Open after the cyber attack in May 2020, we recommend to the cluster users to use SSH keys. We recommend to use different keys for Euler and Leonhard Open, with according names
  
==Terminate the Jupyter session==
+
$HOME/.ssh/id_ed25519_euler
Please note that when you finish working with the jupyter notebook, you need to click on the "Quit" or "Logout" button in your Browser. "Quit" will stop the batch job running on Euler, "Logout" will just log you out from the session but not stop the batch job (in this case you need to login to the cluster, identify the job with bjobs and then kill it with the bkill command, using the jobid as parameter). Afterwards you also need to clean up the SSH tunnel that is running in the background.
 
  
Example:
+
In order to use this keys with the jupyter script, then there are two options. You can configure your ssh client to use this option automatically by adding the following lines in the <tt>$HOME/.ssh/config</tt> file on your local computer:
 +
 +
Host euler.ethz.ch
 +
IdentityFile ~/.ssh/id_ed25519_euler
  
samfux@bullvalene:~/Jupyter-on-Euler-or-Leonhard-Open$ ps -u | grep -m1 -- "-L" | grep -- "-N"
+
Both options work and are equivalent.
samfux    8729  0.0  0.0  59404  6636 pts/5    S    13:46  0:00 ssh sfux@euler.ethz.ch -L 51339:10.205.4.122:8888 -N
 
samfux@bullvalene:~/jupyter-on-Euler-or-Leonhard-Open$ kill 8729
 
  
==Installing additional Python and R packages locally==
+
===Installing additional Python packages locally===
When starting a Jupyter notebook with this script, then it will use a central Python and R installation:
+
When starting a Jupyter notebook with this script, then it will use a central Python installation:
  
* Euler: python/3.6.1, r/3.6.0
+
* New software stack: module load gcc/6.3.0 python/3.8.5
* Leonhard Open: python_cpu/3.6.4, r/3.5.1
+
* Old software stack: module load new gcc/4.8.2 python/3.6.1
  
 
Therefore you can only use packages that are centrally installed out-of-the-box. But you have the option to install additional packages locally in your home directory, which can afterwards be used.
 
Therefore you can only use packages that are centrally installed out-of-the-box. But you have the option to install additional packages locally in your home directory, which can afterwards be used.
Line 119: Line 131:
 
  https://scicomp.ethz.ch/wiki/Python#Installing_a_Python_package.2C_using_PIP
 
  https://scicomp.ethz.ch/wiki/Python#Installing_a_Python_package.2C_using_PIP
  
The command to locally install an R package:
+
==Running the script==
 +
 
 +
The start_jupyer_nb.sh script needs to be executed on your local computer. Please find below the list of options that can be used with the script:
 +
 
 +
$ ./start_jupyter_nb.sh -h
 +
./start_jupyter_nb.sh: Script to start jupyter notebook/lab on Euler from a local computer
 +
Usage: start_jupyter_nb.sh [options]
 +
 +
Options:
 +
 +
        -u | --username      USERNAME        ETH username for SSH connection to Euler
 +
        -n | --numcores      NUM_CPU          Number of CPU cores to be used on the cluster
 +
        -W | --runtime        RUN_TIME        Run time limit for jupyter notebook/lab in hours and minutes HH:MM
 +
        -m | --memory        MEM_PER_CORE    Memory limit in MB per core
 +
 +
Optional arguments:
 +
 +
        -c | --config        CONFIG_FILE      Configuration file for specifying options
 +
        -e | --environment    ENV              Python virtual environment
 +
        -g | --numgpu        NUM_GPU          Number of GPUs to be used on the cluster
 +
        -h | --help                            Display help for this script and quit
 +
        -i | --interval      INTERVAL        Time interval for checking if the job on the cluster already started
 +
        -k | --key            SSH_KEY_PATH    Path to SSH key with non-standard name
 +
        -l | --lab                            Start jupyter lab instead of a jupyter notebook
 +
        -s | --softwarestack  SOFTWARE_STACK  Software stack to be used (old, new)
 +
        -v | --version                        Display version of the script and exit
 +
        -w | --workdir        WORKING_DIR      Working directory for the jupyter notebook/lab
 +
 +
Examlples:
 +
 +
        ./start_jupyter_nb.sh -u sfux -n 4 -W 04:00 -m 2048 -w /cluster/scratch/sfux
 +
 +
        ./start_jupyter_nb.sh --username sfux --numcores 2 --runtime 01:30 --memory 2048 --softwarestack new
 +
 +
        ./start_jupyter_nb.sh -c $HOME/.jnb_config
 +
 +
Format of configuration file:
 +
 +
JNB_USERNAME=""            # ETH username for SSH connection to Euler
 +
JNB_NUM_CPU=1              # Number of CPU cores to be used on the cluster
 +
JNB_NUM_GPU=0              # Number of GPUs to be used on the cluster
 +
JNB_RUN_TIME="01:00"        # Run time limit for jupyter notebook/lab in hours and minutes HH:MM
 +
JNB_MEM_PER_CPU_CORE=1024  # Memory limit in MB per core
 +
JNB_WAITING_INTERVAL=60    # Time interval to check if the job on the cluster already started
 +
JNB_SSH_KEY_PATH=""        # Path to SSH key with non-standard name
 +
JNB_SOFTWARE_STACK="new"    # Software stack to be used (old, new)
 +
JNB_WORKING_DIR=""          # Working directory for jupyter notebook/lab
 +
JNB_ENV=""                  # Path to virtual environment
 +
JNB_JLAB=""                # "lab" -> start jupyter lab; "" -> start jupyter notebook
 +
 
 +
[[File:jupyter_on_Euler.png|thumb|none|800px|Example for running a Jupyter notebook on the Euler cluster]]
 +
 
 +
===Reconnect to a Jupyter notebook===
 +
When running the script, it creates a local file called reconnect_info in the installation directory, which contains all information regarding the used ports, the remote IP address, the command for the SSH tunnel and the URL for the browser. This information should be sufficient to reconnect to a Jupyter notebook if connection was lost.
 +
 
 +
===Terminate the Jupyter session===
 +
Please note that when you finish working with the jupyter notebook, you need to click on the "Quit" or "Logout" button in your Browser. "Quit" will stop the batch job running on Euler, "Logout" will just log you out from the session but not stop the batch job (in this case you need to login to the cluster, identify the job with bjobs and then kill it with the bkill command, using the jobid as parameter). Afterwards you also need to clean up the SSH tunnel that is running in the background.
 +
 
 +
Example:
 +
 
 +
samfux@bullvalene:~/Jupyter-on-Euler-or-Leonhard-Open$ ps -u | grep -m1 -- "-L" | grep -- "-N"
 +
samfux    8729  0.0  0.0  59404  6636 pts/5    S    13:46  0:00 ssh sfux@euler.ethz.ch -L 51339:10.205.4.122:8888 -N
 +
samfux@bullvalene:~/jupyter-on-Euler-or-Leonhard-Open$ kill 8729
 +
 
 +
==Troubleshooting==
 +
===Logs===
 +
If the script does not work, then we recommend to check the logs. There is on one hand the file <tt>$HOME/jnbinfo</tt> which contains logs, and on the other hand there is the lsf.o* logfile of the job that was running the jupyter notebook.
 +
 
 +
===Mismatch of software stacks===
 +
In many cases it turns out that there are issues when the software stack used in the script does not match the default software stack that you have set. You can check which software stack is set as default by running the command
 +
 
 +
set_software_stack.sh -i
 +
 
 +
The script has an option (-s/--softwarestack) for which you can specify either "old" or "new". Please either adapt the software stack that you are requesting for the script or change the default setting for the software stack that you use on the cluster.
  
install.packages("package_name")
+
===Conflict with locally installed Python packages===
 +
When the jnbinfo contains a Python error with a backtrace, then it could be that some of the Python packages that you installed locally in <tt>$HOME/.local</tt> are conflicting with the centrally provided Jupyter installation.
  
Then follow the instructions provided on our wiki:
+
==Jupyter in VSCode==
 +
Another possibility to work with jupyter notebooks on Euler is to run them in VSCode (https://code.visualstudio.com/docs/datascience/jupyter-notebooks). You can run VSCode (actually code-server) on Euler using the script:
  
  https://scicomp.ethz.ch/wiki/R#Extensions
+
  https://scicomp.ethz.ch/wiki/VSCode

Revision as of 06:34, 11 August 2022

Introduction

Jupyter notebooks and Jupyter Lab are becoming more widely used among the scientific community at ETH. We therefore developed a script that you can run on your local computer to start Jupyter notebooks or Jupyter lab on Euler. The shell script starts a Jupyter in a batch job on Euler and connects your local browser with it.

The script runs on Linux, macOS and Windows (using WSL/WSL2 or git bash).

Please note, that with this script we are addressing beginners that start to use Jupyter notebooks on the cluster. It is not addressing advanced users that need a wide range of additional features going beyond simple Jupyter notebooks. Advanced users can take the script and adapt it, such that it can be used with other Python versions (centrally installed, or local installations) and add support for GPU, adding new kernels etc.

Installation

Download the repository with the commnad

git clone https://gitlab.ethz.ch/sfux/Jupyter-on-Euler-or-Leonhard-Open

Mac OS X:

git clone https://gitlab.ethz.ch/sfux/Jupyter-on-Euler-or-Leonhard-Open.git

After downloading the script from gitlab.ethz.ch, you need to change its permissions to make it executable cd Jupyter-on-Euler-or-Leonhard-Open/ chmod 755 start_jupyter_nb.sh

Prerequisites

In order to use this script, users need to make sure, that they have set up SSH keys for passwordless access to the cluster:

https://scicomp.ethz.ch/wiki/Accessing_the_clusters#SSH_keys

Please make sure that xdg-open is installed. This package is used to automatically start your default browser. You can install it with the following command:

CentOS:

yum install xdg-utils

Ubuntu:

apt-get install xdg-utils

Further more, the script requires that there is a Python installation available, which is usually included in the Linux distribution or Mac OS.

Security token vs. password setup

Please note that a part of the script (parsing of the ports) requires that you use jupyter notebooks with the security tokens. If you configure a password instead, such that you can use the jupyter notebook without the security token, then the script will not work anymore (it cannot parse the port on the remote compute node) without adapting it.

Download and setup

The script is available on the Gitlab instance of ETH Zurich:

https://gitlab.ethz.ch/sfux/Jupyter-on-Euler-or-Leonhard-Open

Download the repository with the command

git clone https://gitlab.ethz.ch/sfux/Jupyter-on-Euler-or-Leonhard-Open

Mac OS X:

git clone https://gitlab.ethz.ch/sfux/Jupyter-on-Euler-or-Leonhard-Open.git

After downloading the script from gitlab.ethz.ch, you need to change its permissions to make it executable

chmod 755 start_jupyter_nb.sh

Software stack

Please note that currently the old software stack is still set a default (this will change). The script is using the new software stack (unless you explicitly request the old software stack with the option -s old (or --softwarestack old). Therefore please make sure that you set the new software stack as permanent default by using the command

set_software_stack.sh new

You can find more information about this script on our wiki:

https://scicomp.ethz.ch/wiki/Setting_permanent_default_for_software_stack_upon_login

Creating SSH keys for the Jupyter script with a Windows computer (using git-bash)

With git-bash, you can use the same command as for Linux/Mac to create your SSH keys:

  • Start git-bash
  • Run the command ssh-keygen to create the SSH key pair
ssh-keygen -t ed25519 -f $HOME/.ssh/id_ed25519_euler
  • Enter a passphrase to protect your SSH keys
  • Use the ssh-copy-id command to copy your public (never your private) key to Euler
ssh-copy-id -i ~/.ssh/id_ed25519_euler.pub username@euler.ethz.ch
  • (here you need to replace username with your ETH username)
  • Enter your password

After creating the keys, we strongly recommend to create an SSH config file in $HOME/.ssh

  • Change to your .ssh directory
cd $HOME/.ssh
  • Create an SSH config file to specify the path to your SSH key
echo -e "Host euler\nHostName euler.ethz.ch\nUser username\nIdentityFile ~/.ssh/id_ed25519_euler" > config 
  • (here you need to replace username with your ETH username)

At this stage, passwordless login to Euler should work. You can test this with the command

ssh username@euler.ethz.ch
  • (here you need to replace username with your ETH username)

But now you still have to enter your passphrase. In order to not have to type your passphrase all the time, you can use an SSH agent, which is already included in git-bash

  • Start git-bash
  • Start the SSH agent for the current terminal
ssh-agent /bin/bash
  • Add your SSH key to the SSH agent
ssh-add ~/.ssh/id_ed25519_euler
  • Enter your passphrase

As long as this terminal is open, you can access Euler with

ssh username@euler.ethz.ch

(here you need to replace username with your ETH username) without having to type a password or passphrase. As soon as you exit the terminal, then the SSH agent will be stopped.

Now you are ready to clone the Jupyter script and to execute it in the terminal with the SSH agent. Please note that you only need to create the SSH once, but you need to setup the SSH agent every time you would like to run the Jupyter script.

Using SSH keys with non-default names

Since the reopening of Euler and Leonhard Open after the cyber attack in May 2020, we recommend to the cluster users to use SSH keys. We recommend to use different keys for Euler and Leonhard Open, with according names

$HOME/.ssh/id_ed25519_euler

In order to use this keys with the jupyter script, then there are two options. You can configure your ssh client to use this option automatically by adding the following lines in the $HOME/.ssh/config file on your local computer:

Host euler.ethz.ch
IdentityFile ~/.ssh/id_ed25519_euler

Both options work and are equivalent.

Installing additional Python packages locally

When starting a Jupyter notebook with this script, then it will use a central Python installation:

  • New software stack: module load gcc/6.3.0 python/3.8.5
  • Old software stack: module load new gcc/4.8.2 python/3.6.1

Therefore you can only use packages that are centrally installed out-of-the-box. But you have the option to install additional packages locally in your home directory, which can afterwards be used.

For installing a Python package from inside a Jupyter notebook, you would need to run the following command:

!pip install --user package_name

This will install package_name into $HOME/.local, as described on our wiki page about Python:

https://scicomp.ethz.ch/wiki/Python#Installing_a_Python_package.2C_using_PIP

Running the script

The start_jupyer_nb.sh script needs to be executed on your local computer. Please find below the list of options that can be used with the script:

$ ./start_jupyter_nb.sh -h
./start_jupyter_nb.sh: Script to start jupyter notebook/lab on Euler from a local computer
Usage: start_jupyter_nb.sh [options]

Options:

        -u | --username       USERNAME         ETH username for SSH connection to Euler
        -n | --numcores       NUM_CPU          Number of CPU cores to be used on the cluster
        -W | --runtime        RUN_TIME         Run time limit for jupyter notebook/lab in hours and minutes HH:MM
        -m | --memory         MEM_PER_CORE     Memory limit in MB per core

Optional arguments:

        -c | --config         CONFIG_FILE      Configuration file for specifying options
        -e | --environment    ENV              Python virtual environment
        -g | --numgpu         NUM_GPU          Number of GPUs to be used on the cluster
        -h | --help                            Display help for this script and quit
        -i | --interval       INTERVAL         Time interval for checking if the job on the cluster already started
        -k | --key            SSH_KEY_PATH     Path to SSH key with non-standard name
        -l | --lab                             Start jupyter lab instead of a jupyter notebook
        -s | --softwarestack  SOFTWARE_STACK   Software stack to be used (old, new)
        -v | --version                         Display version of the script and exit
        -w | --workdir        WORKING_DIR      Working directory for the jupyter notebook/lab

Examlples:

        ./start_jupyter_nb.sh -u sfux -n 4 -W 04:00 -m 2048 -w /cluster/scratch/sfux

        ./start_jupyter_nb.sh --username sfux --numcores 2 --runtime 01:30 --memory 2048 --softwarestack new

        ./start_jupyter_nb.sh -c $HOME/.jnb_config

Format of configuration file:

JNB_USERNAME=""             # ETH username for SSH connection to Euler
JNB_NUM_CPU=1               # Number of CPU cores to be used on the cluster
JNB_NUM_GPU=0               # Number of GPUs to be used on the cluster
JNB_RUN_TIME="01:00"        # Run time limit for jupyter notebook/lab in hours and minutes HH:MM
JNB_MEM_PER_CPU_CORE=1024   # Memory limit in MB per core
JNB_WAITING_INTERVAL=60     # Time interval to check if the job on the cluster already started
JNB_SSH_KEY_PATH=""         # Path to SSH key with non-standard name
JNB_SOFTWARE_STACK="new"    # Software stack to be used (old, new)
JNB_WORKING_DIR=""          # Working directory for jupyter notebook/lab
JNB_ENV=""                  # Path to virtual environment
JNB_JLAB=""                 # "lab" -> start jupyter lab; "" -> start jupyter notebook
Example for running a Jupyter notebook on the Euler cluster

Reconnect to a Jupyter notebook

When running the script, it creates a local file called reconnect_info in the installation directory, which contains all information regarding the used ports, the remote IP address, the command for the SSH tunnel and the URL for the browser. This information should be sufficient to reconnect to a Jupyter notebook if connection was lost.

Terminate the Jupyter session

Please note that when you finish working with the jupyter notebook, you need to click on the "Quit" or "Logout" button in your Browser. "Quit" will stop the batch job running on Euler, "Logout" will just log you out from the session but not stop the batch job (in this case you need to login to the cluster, identify the job with bjobs and then kill it with the bkill command, using the jobid as parameter). Afterwards you also need to clean up the SSH tunnel that is running in the background.

Example:

samfux@bullvalene:~/Jupyter-on-Euler-or-Leonhard-Open$ ps -u | grep -m1 -- "-L" | grep -- "-N"
samfux    8729  0.0  0.0  59404  6636 pts/5    S    13:46   0:00 ssh sfux@euler.ethz.ch -L 51339:10.205.4.122:8888 -N
samfux@bullvalene:~/jupyter-on-Euler-or-Leonhard-Open$ kill 8729

Troubleshooting

Logs

If the script does not work, then we recommend to check the logs. There is on one hand the file $HOME/jnbinfo which contains logs, and on the other hand there is the lsf.o* logfile of the job that was running the jupyter notebook.

Mismatch of software stacks

In many cases it turns out that there are issues when the software stack used in the script does not match the default software stack that you have set. You can check which software stack is set as default by running the command

set_software_stack.sh -i

The script has an option (-s/--softwarestack) for which you can specify either "old" or "new". Please either adapt the software stack that you are requesting for the script or change the default setting for the software stack that you use on the cluster.

Conflict with locally installed Python packages

When the jnbinfo contains a Python error with a backtrace, then it could be that some of the Python packages that you installed locally in $HOME/.local are conflicting with the centrally provided Jupyter installation.

Jupyter in VSCode

Another possibility to work with jupyter notebooks on Euler is to run them in VSCode (https://code.visualstudio.com/docs/datascience/jupyter-notebooks). You can run VSCode (actually code-server) on Euler using the script:

https://scicomp.ethz.ch/wiki/VSCode