Jupyter Notebook on Niflheim

Jupyter Notebook documents are produced by the Jupyter Notebook App, which contain both computer code (e.g. Python) and rich text elements (paragraph, equations, figures, links, etc…). Notebook documents are both human-readable documents containing the analysis description and the results (figures, tables, etc..) as well as executable documents which can be run to perform data analysis.

On Niflheim we have installed Jupyter Notebook software modules which you can load and use:

$ module avail JupyterNotebook
-------------------------- /home/modules/modules/all ---------------------------
 JupyterNotebook/7.0.2-GCCcore-12.3.0    JupyterNotebook/7.4.7-GCCcore-14.3.0 (D)

You have to select the correct jupyter version shown above, according to which compiler has been used to compile the other software you are using (such as GPAW).

Note

If you use a Python virtual environment (venv), you need to register the virtual environment kernel with Jupyter before you can use it:

python -m ipykernel install --user --name=my_venv_name

You can now start the notebook server, connect to it from your laptop/desktop PC, and then select the kernel from your venv:

jupyter notebook --no-browser --ip=$HOSTNAME

It is very important that you shut down both your notebooks and the server when you stop using it. It is done by pressing Control-C twice in the window where the server is running.

Restrictions on the use of Jupyter Notebook

  • NOTICE: Jupyter Notebooks cannot be connected to directly from any other network at DTU or outside DTU.

  • The web-server on port 8888 can only be accessed from a PC on the DTU Physics cabled network (which includes demon).

  • The jupyter command starts a special web-server on the login nodes serving a network port number 8888 (plus/minus a small number).

Using Jupyter Notebook documents on Niflheim from DTU Physics

  1. Use SSH to login to one of the Niflheim login nodes, preferably svol.fysik.dtu.dk.

  2. Load the relevant module, for example:

    module load JupyterNotebook
    

    Users of venv should not load this module!

  3. Go to the relevant folder for your notebooks, and start Jupyter Notebook with the command:

    jupyter notebook --no-browser --ip=$HOSTNAME
    

    Jupyter Notebook will respond with around ten lines of text, at the bottom is a URL. Paste that URL into a browser on your local machine.

  4. IMPORTANT: Once you are done using your notebooks, remember to shut down the Jupyter server, see Shutting down the Jupyter server.

Using Jupyter Notebook documents from home or elsewhere on a Linux or macOS PC

Use these instructions when you are located outside DTU Physics, and your laptop/desktop is running Linux or macOS.

  1. Connect to the DTU VPN network (information about DTU VPN is on DTU Inside).

  2. Use SSH to connect to one of the Niflheim login nodes, preferably svol.fysik.dtu.dk.

  3. Load the relevant module, for example:

    module load JupyterNotebook/7.4.7-GCCcore-14.3.0
    

    Users of venv should not load this module!

  4. Go to the relevant folder for your notebooks, and start Jupyter Notebook with the command:

    jupyter notebook --no-browser
    

    Jupyter Notebook will respond with around ten lines of text, at the bottom is a URL. It will contain the text localhost:NNNN where NNNN is a port number, typically 8888 or close. You need that number in the next step.

  5. From your desktop/laptop, log in to niflheim again in a new window, using this command to set up an SSH tunnel:

    ssh -L NNNN:localhost:NNNN username@xxxx -N
    

    where:

    • xxxx is svol.fysik.dtu.dk or whatever machine you are using,

    • username is your DTU username,

    • NNNN is the port number printed by the notebook command,

    Note There will be no output from this command. To test if it is working; proceed to the next step.

  6. Open a browser, and cut-and-paste the address starting with http://localhost into your browser.

  7. IMPORTANT: Once you are done using your notebooks, remember to shut down the Jupyter server, see Shutting down the Jupyter server.

Using Jupyter Notebook documents on Niflheim from home or elsewhere on a Windows PC

Use these instructions when you are located outside DTU Physics, and your laptop/desktop is running Microsoft Windows.

  1. Connect to the DTU VPN network (information about DTU VPN is on DTU Inside).

  2. Log in to one of the Niflheim login nodes, preferably slid.fysik.dtu.dk. Use MobaXterm to log in directly to e.g. slid.fysik.dtu.dk, but when you create the login session (the Session tab), select Network Settings, then Jump Host. Fill in the Jump Host name slid.fysik.dtu.dk and your DTU user name.

  3. Load the relevant module, for example:

    module load JupyterNotebook/7.4.7-GCCcore-14.3.0
    

    Users of venv should not load this module!

  4. Go to the relevant folder for your notebooks, and start Jupyter Notebook with the command:

    jupyter notebook --no-browser --ip=$HOSTNAME
    

    Note the extra --ip option needed when connecting with MobaXterm. Jupyter Notebook will respond with around ten lines of text, at the bottom is a URL. It will contain the text localhost:NNNN or 127.0.0.1:NNNN where NNNN is a port number, typically 8888 or close. You need that number in the next step.

  5. Use MobaXterm to set up an SSH tunnel (the Tunneling tab).

    • On “My computer” enter port number printed by jupyter.

    • On “SSH server”, enter the jump host hostname, and your DTU username as SSH user. Leave the port number blank.

    • On the remote server, enter slid.fysik.dtu.dk (or whatever node you are using) as the Remote server name, and the port number printed by jupyter as the port number.

    Click save, and then start the tunnel with the small “play” icon.

  6. Open a browser, and cut-and-paste the address starting with http://localhost or http://127.0.0.1 into your browser.

  7. IMPORTANT: Once you are done using your notebooks, remember to shut down the Jupyter server, see Shutting down the Jupyter server.

Shutting down the Jupyter server

Once you are done using your notebooks, remember to shut down the Jupyter server so you do not tie up valuable resources (mainly RAM and port numbers). You shut down Jupyter by either:

  1. Pressing Control-C twice in the terminal running the jupyter command, or

  2. Clicking on the Quit button on the Jupyter Notebook overview page.

This is not the same as the Logout buttons on each notebook, which will disconnect your browser from the Jupyter Notebook server, but actually leave Jupyter Notebook running on the login nodes.