Software install

Opening and running the Jupyter Julia notebook

Course slides and lecture material

All the course slides are Jupyter notebooks; browser-based computational notebooks.

Code cells are executed by putting the cursor into the cell and hitting shift + enter. For more info see the documentation.

Exercises and homework

The first two lecture's homework assignments will be Jupyter notebooks. You can import the notebooks from Moodle into your JupyterHub space. You can execute them on the JupyterHub or download them and run them them locally if you're already set-up.

For submission, you can directly submit the folder containing all notebooks of a lecture from within the JupyterHub/Moodle integration. From the homework task on Moodle, you should be able to launch the notebooks in your JupyterHub. Once the homework completed, you should be able to see the folders you have worked on from your JupyterHub within the submission steps on Moodle. See Logistics and Homework for details.

Starting from lecture 3, exercise scripts will be mostly standalone regular Julia scripts that have to be uploaded to your private GitHub repo (shared with the teaching staff only). Details in Logistics.

JupyterHub

You can access the JupyterHub from the General section in Moodle, clicking on JupyterHub

Upon login to the server, you should see the following launcher environment, including a notebook (file) browser, ability to create a notebook, launch a Julia console (REPL), or a regular terminal.

JupyterHub

⚠️ Warning!
It is recommended to download your work as back-up before leaving the session.

Installing Julia v1.10 (or later)

Juliaup installer

Follow the instructions from the Julia Download page to install Julia v1.10 (which is using the Juliaup Julia installer under the hood).

💡 Note
For Windows users: When installing Julia 1.10 on Windows, make sure to check the "Add PATH" tick or ensure Julia is on PATH (see [help]). Julia's REPL has a built-in shell mode you can access typing ; that natively works on Unix-based systems. On Windows, you can access the Windows shell by typing Powershell within the shell mode, and exit it typing exit, as described here.

Terminal + external editor

Ensure you have a text editor with syntax highlighting support for Julia. We recommend to use VSCode, see below. However, other editors are available too such as Sublime, Emacs, Vim, Helix, etc.

From within the terminal, type

julia

to make sure that the Julia REPL (aka terminal) starts. Then you should be able to add 1+1 and verify you get the expected result. Exit with Ctrl-d.

Julia from Terminal

VS Code

If you'd enjoy a more IDE type of environment, check out VS Code. Follow the installation directions for the Julia VS Code extension.

VS Code Remote - SSH setup

VS Code's Remote-SSH extension allows you to connect and open a remote folder on any remote machine with a running SSH server. Once connected to a server, you can interact with files and folders anywhere on the remote filesystem (more).

  1. To get started, follow the install steps.

  2. Then, you can connect to a remote host, using ssh user@hostname and your password (selecting Remote-SSH: Connect to Host... from the Command Palette).

  3. Advanced options permit you to access a remote compute node from within VS Code.

💡 Note
This remote configuration supports Julia graphics to render within VS Code's plot pane. However, this "remote" visualisation option is only functional when plotting from a Julia instance launched as Julia: Start REPL from the Command Palette. Displaying a plot from a Julia instance launched from the remote terminal (which allows, e.g., to include custom options such as ENV variables or load modules) will fail. To work around this limitation, select Julia: Connect external REPL from the Command Palette and follow the prompted instructions.

Running Julia

First steps

Now that you have a running Julia install, launch Julia (e.g. by typing julia in the shell since it should be on path)

julia

Welcome in the Julia REPL (command window). There, you have 3 "modes", the standard

[user@comp ~]$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.5 (2024-08-27)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia>

the shell mode by hitting ;, where you can enter Unix commands,

shell>

and the Pkg mode (package manager) by hitting ], that will be used to add and manage packages, and environments,

(@v1.10) pkg>

You can interactively execute commands in the REPL, like adding two numbers

julia> 2+2
4

julia>

Within this class, we will mainly work with Julia scripts. You can run them using the include() function in the REPL

julia> include("my_script.jl")

Alternatively, you can also execute a Julia script from the shell

julia -03 my_script.jl

here passing the -O3 optimisation flag.

Package manager

The Pkg mode permits you to install and manage Julia packages, and control the project's environment.

Environments or Projects are an efficient way that enable portability and reproducibility. Upon activating a local environment, you generate a local Project.toml file that stores the packages and version you are using within a specific project (code-s), and a Manifest.toml file that keeps track locally of the state of the environment.

To activate an project-specific environment, navigate to your targeted project folder, launch Julia

mkdir my_cool_project
cd my_cool_project
julia

and activate it

julia> ]

(@v1.10) pkg>

(@v1.10) pkg> activate .
  Activating new environment at `~/my_cool_project/Project.toml`

(my_cool_project) pkg>

Then, let's install the Plots.jl package

(my_cool_project) pkg> add Plots

and check the status

(my_cool_project) pkg> st
      Status `~/my_cool_project/Project.toml`
  [91a5bcdd] Plots v1.22.3

as well as the .toml files

julia> ;

shell> ls
Manifest.toml Project.toml

We can now load Plots.jl and plot some random noise

julia> using Plots

julia> heatmap(rand(10,10))

Let's assume you're handed your my_cool_project to someone to reproduce your cool random plot. To do so, you can open julia from the my_cool_project folder with the --project option

cd my_cool_project
julia --project

Or you can rather activate it afterwards

cd my_cool_project
julia

and then,

julia> ]

(@v1.10) pkg> activate .
  Activating environment at `~/my_cool_project/Project.toml`

(my_cool_project) pkg>

(my_cool_project) pkg> st
      Status `~/my_cool_project/Project.toml`
  [91a5bcdd] Plots v1.22.3

Here we go, you can now share that folder with colleagues or with yourself on another machine and have a reproducible environment 🙂

Multi-threading on CPUs

On the CPU, multi-threading is made accessible via Base.Threads. To make use of threads, Julia needs to be launched with

julia --project -t auto

which will launch Julia with as many threads are there are cores on your machine (including hyper-threaded cores). Alternatively set the environment variable JULIA_NUM_THREADS, e.g. export JULIA_NUM_THREADS=2 to enable 2 threads.

Julia on GPUs

The CUDA.jl module permits to launch compute kernels on Nvidia GPUs natively from within Julia. JuliaGPU provides further reading and introductory material about GPU ecosystems within Julia.