Jupyter

Jupyter

a free, modular, web-based IDE across all programming languages (mainly: Python, Julia, and R)

Official Documention

https://jupyterlab.readthedocs.io/en/stable/

Installing JupyterLab

Currently, we provide no ready-to-use Jupyter installation. However, you can easily build your own Jupyter using Mamba from our recommended MiniForge Python distribution. If you have already finished the steps from https://user.nhr.zib.de/wiki/spaces/PUB/pages/529104948/MiniForge+Python#Installing-MiniForge you can simply create your own Jupyter environment - the following packages are a good starting point:

mamba create --name jupyter_env python=3.12 numpy matplotlib jupyterlab ipykernel ipympl # Python=3.11 > version # numpy > basic math library (linear Algebra, Analysis) # jupyterlab > Jupyter browser IDE # ipykernel > interactive Python kernel for Jupyter # matplotlib > for generating plots # ipympl > interactive Matplotlib plots

Accessing your remote JupyterLab Server via SSH

To interactively work with JupyterLab (successor of Jupyter notebook) in your local browser take the following steps:

  1. Generate your random four-digit port number locally (one-time only):

    mkdir -p ~/.jupyter echo "$((1000 + RANDOM % 9000))" > ~/.jupyter/rnd_port_number ssh YOUR_USERNAME@LOGIN_NODE:"mkdir -p ~/.jupyter" scp ~/.jupyter/rnd_port_number YOUR_USERNAME@LOGIN_NODE:"~/.jupyter/"
  2. Log in to our system, allocate your private compute node and log in to it with port forwarding:
    (Note, the compute node “test” allocation runs for 1 hour max. The first, left port number 8.8.8.8 is your local one, which you access later from your browser. The other port numbers create a communication channel to the remote server running on our system. In case your created port number is not unique from all other users, create a new random one.)

    ssh -L 8888:127.0.0.1:$(cat ~/.jupyter/rnd_port_number) YOUR_USERNAME@LOGIN_NODE salloc -p cpu-clx:test ssh -L 127.0.0.1:$(cat ~/.jupyter/rnd_port_number):127.0.0.1:$(cat ~/.jupyter/rnd_port_number) $SLURM_NODELIST
  3. Load your environment that has the Jupyter package installed (https://user.nhr.zib.de/wiki/spaces/PUB/pages/529825822/Jupyter#Installing-Jupyter):

    mamba activate jupyter_env
  4. Ensure that your personal Python environment is detectable by Jupyter as a kernel (one-time only):

    python -m ipykernel install --user --name jupyter_env --display-name "Personal Jupyter Env."
  5. If you would like to set up / reset a password (alternative to the one-time, randomly generated tokens) to access your server, you can run

    jupyter notebook password
  6. We recommend to setup ~/.jupyter/jupyter_lab_config.pyto permanently configure your IDE (one-time only):

    jupyter lab --generate-config echo "c.NotebookApp.open_browser = False" >> ~/.jupyter/jupyter_lab_config.py echo "c.ServerApp.port = $(cat ~/.jupyter/rnd_port_number)" >> ~/.jupyter/jupyter_lab_config.py
  7. Now, in an interactive session (on a compute node), start your personal JupyterLab server:

    jupyter lab

(After your work ist done, press Control-C and y to shut down the server.)

 

  • Alternatively to step 7, you can start your JupyterLab server via a SLURM job
    (instead of an interactive job, see step 2 above):

    sbatch jupyter_server.sh
  • Here, an example SLURM job start script is:

    cat jupyter_server.sh #!/bin/bash #SBATCH -t 12:00:00 #SBATCH -p standard96 #SBATCH --nodes=1 #SBATCH --ntasks-per-node=96 #SBATCH --output="slurm.log.%j" #SBATCH --job-name=jupyter_server mamba activate jupyter_env jupyter lab --ip $(hostname -f)
  • Once your SLURM job starts, check its node name. Instead of the “-L“ flags of step 2, you need to open a second shell on your local machine and start ssh tunnel forwarding to that specific compute node (via our login nodes):

    ssh -N -L 8888:YOUR_COMPUTE_NODE:$(cat ~/.jupyter/rnd_port_number) YOUR_USERNAME@LOGIN_NODE

Keep this tunnel job running. Do not close its shell. These (gray) steps are not needed if you run JupyterLab interactively.

 

Finally, in a browser on your local machine, navigate to http://localhost:8888

If there is no password from step 5, enter the generated token of the JupyterLab job output:

Screenshot 2025-12-02 at 21.26.52.png

If your internet connection is disrupted, you can reconnect to your lab server by running step 4 again when your connection becomes stable.
Once connected, you can create, run, and modify Jupyter notebooks running on the compute node directly from your local machine. In the upper right, you can select your (default) kernel: "Personal Jupyter Env.". You can also modify the IDE, for example: Settings > Theme > "JupyterLab Dark".

Generally, we recommend managing Python packages only with mamba (https://user.nhr.zib.de/wiki/spaces/PUB/pages/529104948/MiniForge+Python#Creating-a-new-Environment) and not mix it with pip install due to conflicting packages. As an exception, only in case you need to install further packages from inside the running notebook, you may use:

%pip install your-package

The magic “%“ sign ensures that the package is installed inside your active environment. It re-uses the package directories of the active environment (hence, no package duplicates). In case of package conflicts, use mamba outside Jupyter and then restart the Jupyter kernel.
Please note, for security reasons, our compute nodes have no internet access: To install any package, you need to run the JupyterLab server directly on a login node (skip the node allocation and second ssh jump of step 2). At the same time, remember not to run compute or memory intensive notebooks on the login: First, install your environment on the login; then restart the server on the compute node for big productions jobs.

Jupyter 'Sine & Cosine' Script Example: Jupyter-IDE cell

%matplotlib widget import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2*np.pi, 400) plt.clf() # clear the current figure plt.plot(x, np.sin(x), label='sin(x)') plt.plot(x, np.cos(x), label='cos(x)') plt.legend() plt.xlabel('x') plt.title('Sine and Cosine') plt.show()

To evaluate this cell press Shift-Enter and you will see:

Figure 1.png

Jupyter 'Sine & Cosine' Script Example: saved *.ipynb file 

{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "df8d3d10-f7b0-46a6-b2c5-0acc7a6c9ff0", "metadata": {}, "outputs": [], "source": [ "%matplotlib widget\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "x = np.linspace(0, 2*np.pi, 400)\n", "plt.clf() # clear the current figure\n", "plt.plot(x, np.sin(x), label='sin(x)')\n", "plt.plot(x, np.cos(x), label='cos(x)')\n", "plt.legend()\n", "plt.xlabel('x')\n", "plt.title('Sine and Cosine')\n", "plt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Personal Jupyter Env.", "language": "python", "name": "jupyter_env" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.12" } }, "nbformat": 4, "nbformat_minor": 5 }