Running Julia in Jupyter

  • Like for Python it is possible to run Julia in Jupyter, i.e. in a web interface with possibility of inline figures and debugging.
  • For this you need the IJulia package that you may have to install yourself.
  • An easy way to do this is to load a python or Jupyter module as well.
  • For more interactiveness you can run IJulia which is Julia in Jupyter.
  • You benefit a lot if you are using ThinLinc

Installation step

Use ThinLinc and interactive session

  • Use thinLinc
  • Allocate resources like above with salloc/interactive
  • When these steps are ready continue below!

Start Jupyter

$ ml Python/3.11.5-env-hpc1-gcc-2023b-eb
$ ml julia/1.10.2-bdist
$ julia -p 4

Note: not fully tested successfully, but this step works

$ ml PDC/23.12 julia/1.10.2-cpeGNU-23.12
$ ml cray-python/3.11.5
$ julia
$ module load julia/1.8.5
$ module load python/3.9.5
$ julia -p 4
  • Like for Python it is possible to run a Julia in a Jupyter, i.e. in a web interface with possibility of inline figures and debugging. An easy way to do this is to load the JupyterLab and Julia modules. In shell:
$ module load GCC/13.2.0  JupyterLab/4.2.0
$ module load Julia/1.8.5-linux-x86_64
$ julia

In Julia package mode:

    (@v1.11) pkg> activate jupyter-env
    (jupyter-env) julia> Pkg.build("IJulia")
    (jupyter-env) julia> using IJulia
    (jupyter-env) julia> notebook(dir=".",detached=true)
  • In some centres (UPPMAX and NSC) this will start a Firefox session with the Jupyter notebook interface.
  • The last command may not be able to start notebook, see further down how to do.

Jupyter Julia

If not, see below.

In any case, IJulia is now installed!

Starting a Jupyter session with Julia Kernel

  • You can start up Julia in Jupyter quickly, once IJulia is installed for the combinations of Julia and Python/Jupyter you want to use.
  • There are two ways
  • starting from within julia REPL (not for HPC2n or PDC)
  • starting jupyter session from terminal

From Julia REPL

  • This may not always work
julia> using IJulia
julia> notebook(dir=".",detached=true)

Tip

With notebook(dir="</path/to/work/dir/>", detached=true) the notebook will not be killed when you exit your REPL Julia session in the terminal.

Jupyter session from terminal

Principle

  1. Load Julia module (and prerequisites)
  2. Load Python or Jupyter module (and prerequisites) that is compatible with the python version used when building IJulia in the previous step

Running IJulia in Jupyter on compute nodes

  • Jupyter is rather slow graphically on the compute nodes.
  • This can be fixed by
    • starting the jupyter server on the compute node, copying the URL containing the.
    • then starting a web browser in ThinLinc and open the URL copied in previous step
  • One can even use the home computer, see here

First start an interactive session

$ ml Python/3.11.5-env-hpc1-gcc-2023b-eb
$ ml julia/1.10.2-bdist
$ jupyter-lab --ip=$HOSTNAME
  • Start the browser from the ThinLinc menu.
  • Copy-paste the address line containing the node name from the jupyter output
  • You can start the Julia kernel in the upper right corner!

Note: not fully tested successfully.

  • Since Jupyter and a web browser are missing on the compute nodes, we need to find another solution here.
  • Below are the steps that would be nice if we got working!

First start an interactive session

$ ml PDC/23.12 julia/1.10.2-cpeGNU-23.12 cray-python/3.11.5
$ jupyter-lab --ip=$HOSTNAME
  • Start the browser from the ThinLinc menu.
  • Copy-paste the address line containing the node name from the jupyter output
  • You can start the Julia kernel in the upper right corner!
$ module load julia/1.8.5
$ module load python/3.9.5
$ jupyter-lab --ip=$HOSTNAME
  • Start the browser from the ThinLinc menu.
  • Copy-paste the address line containing the node name from the jupyter output
  • You can start the Julia kernel in the upper right corner!
$ module load GCCcore/13.2.0  JupyterLab/4.2.0
$ module load Julia/1.8.5-linux-x86_64
$ jupyter-lab --ip=$HOSTNAME
  • Start the browser from the ThinLinc menu.
  • Copy-paste the address line containing the node name from the jupyter output
  • You can start the Julia kernel in the upper right corner!

Write a bash script similar to this (call it job_jupyter.sh, for instance):

#!/bin/bash
# Here you should put your own project id
#SBATCH -A hpc2n2025-062
# This example asks for 1 core
#SBATCH -n 1
# Ask for a suitable amount of time. Remember, this is the time the Jupyter notebook will be available! HHH:MM:SS.
#SBATCH --time=00:10:00
# Clear the environment from any previously loaded modules
module purge > /dev/null 2>&1
# Load the module environment suitable for the job
module load GCCcore/13.2.0  JupyterLab/4.2.0
# Load the Julia module
ml Julia/1.8.5-linux-x86_64
# Start JupyterLab
jupyter lab --no-browser --ip $(hostname)

Then, in the output file slurm-.out file, copy the url that starts with http://b-cn1403.hpc2n.umu.se:8888/lab and paste it in a Firefox browser on Kebnekaise. When the Jupyter notebook interface starts, you can choose the Julia version from the module you loaded (in this case 1.8.5).