Setting a JupyterHub for the lab

JupyterHub is a fantastic platform for getting students up and running with Jupyter notebooks without the hassle of installations and maintenance on individual machines. In our lab, we use The Littlest JupyterHub (TLJH) since we have only a few users. It can be set up on cloud instances or servers you own. Check out the installation guide for more details. We use our own server, so I’ll walk you through the process assuming you have an Ubuntu-based server with remote SSH access and admin rights.

Installation Process

First, let’s upgrade the server and install some essential packages:

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install python3 python3-dev git curl xorg

If Apache is enabled, it needs to be disabled since it conflicts with the built-in Traefik reverse proxy used by JupyterHub:

sudo systemctl status apache2
sudo systemctl disable apache2
sudo apt remove apache2

Next, we’ll install Anaconda. Head over to Anaconda’s archive to get the latest version and update the link accordingly:

cd /tmp
curl -O https://repo.anaconda.com/archive/Anaconda3-2023.07-Linux-x86_64.sh
bash Anaconda3-2023.07-Linux-x86_64.sh
cd ~
source ~/.bashrc
conda info

If needed, create a sudo account for JupyterHub admin access:

adduser apetros
usermod -aG sudo apetros

Now, let’s install JupyterHub using TLJH:

curl -L https://tljh.jupyter.org/bootstrap.py | sudo -E python3 - --admin apetros_new

We can fine-tune server parameters to manage resources for students effectively. For example:

sudo tljh-config set limits.memory 6G
sudo tljh-config set limits.cpu 1
sudo tljh-config set user_environment.default_app jupyterlab
sudo tljh-config set services.cull.every 600
sudo tljh-config set services.cull.timeout 1800
sudo tljh-config reload

To set up HTTPS, replace _your-email_ and _your-domain_ with your own details:

sudo tljh-config set https.enabled true
sudo tljh-config set https.letsencrypt.email your_email
sudo tljh-config add-item https.letsencrypt.domains your_domain
sudo tljh-config reload proxy

Post-Installation Setup

Once JupyterHub is up and running, install the necessary packages for your courses. In my courses, I use:

  • Pandas: For energy analytics.
  • Pyomo, IPOPT, CoinCBC: For optimization problems.
  • Pandapower: For power-flow and short-circuit analysis.
  • PyPSA, PyRAMSES: For power system dynamics.

Install these packages as follows:

sudo -E conda install -c conda-forge scipy numpy pandas numba matplotlib pyomo ipopt glpk coincbc pypsa networkx cartopy
sudo -E pip install pandapower
sudo -E conda install -c apetros pyramses

Setting Up PyRAMSES

PyRAMSES requires Intel Redistributable libraries (more information). To install these, add the Intel repository and update:

# download the key to system keyring

wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB |
gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null

# add signed entry to apt sources and configure the APT client to use Intel repository:
echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list

Then update and install:

sudo apt-get update
sudo apt-get install intel-oneapi-runtime-libs

Create a Python file to add the runtime library paths for all JupyterHub users:

sudo nano /opt/tljh/config/jupyterhub_config.d/path.py

Add the following:

c.Spawner.environment = {
    'LD_LIBRARY_PATH': '/opt/intel/oneapi/redist/lib'
}

Save and reload the hub:

sudo tljh-config reload
sudo tljh-config reload proxy

This should resolve the dependencies for PyRAMSES. You can click here to clone the repository with the Nordic system to get started.

Petros Aristidou
Petros Aristidou
Assistant Professor