Load and run Julia

Menti

  • What would you like to use Julia for?

  • What do you want to learn today?

Note

Objectives

  • Show how to load Julia

  • show how to start and use the Julia command line

  • Show how to run Julia scripts and

Instructor note

  • Lecture and demo 15 min

  • Exercise 15 min

  • Total time 30 min

As for Python, Julia can be started after a Julia module is loaded. The module activates paths to a specific version of the julia interpreter and its libraries and packages.

Warning

Note that the module systems at UPPMAX and HPC2N are slightly different. While all modules at UPPMAX not directly related to bio-informatics are shown by ml avail, modules at HPC2N are hidden until one has loaded a prerequisite like the compiler GCC.

  • For reproducibility reasons, you should always load a specific version of a module instead of just the default version (often the latest)

Check for Julia versions

Check all available Julia versions with:

$ module avail julia

Load a Julia module

For reproducibility, we recommend ALWAYS loading a specific module instead of using the default version!

For this course, we recommend using Julia 1.8.5.

Type-Along

Go back and check which Julia modules were available. To load version 1.8.5, do:

$ module load julia/1.8.5

Note: Lowercase j. For short, you can also use:

$ ml julia/1.8.5

Run

Run Julia script

You can run a Julia script in the shell like this:

$ julia example.jl

More information will follow later in the course on running Julia from within a batch job.

Run Julia as a session

The Julian modes

  • enter the shell mode by typing ;

  • go back to Julian mode by <backspace>

  • enter the package manager mode by typing ] in the Julian mode

  • enter the help mode by typing ? in the Julian mode

Type-Along

$ julia

The Julia prompt (julian mode) looks like this:

julia>

Exit with

julia> <Ctrl-D>

or

julia> exit()

Exercises

1. Getting familiar with Julia REPL

It is important in this course that you know how to navigate on the Julia command line. This exercise will help you to become more familiar with the REPL. Do the following steps:

  • Start a Julia session. In the Julian mode, compute the sum the numbers 5 and 6

  • Change to the shell mode and display the current directory

  • Now, go to the package mode and list the currently installed packages

  • Finally, display help information of the function println in help mode.

2. Loading modules and running scripts

Load the Julia version 1.8.5 and run the following serial script (serial-sum.jl) which accepts two integer arguments as input:

x = parse( Int32, ARGS[1] )
y = parse( Int32, ARGS[2] )
summ = x + y
println("The sum of the two numbers is ", summ)

Menti

  • Can you start Julia without loading a Julia module?

  • How do you activate Julia packages in the Julia REPL?

  • How do you toggle to the package mode?

Keypoints

  • Before you can run Julia scripts or work in a Julia shell, first load a Julia module.

  • Start a Julia shell session with julia

  • Run scripts with julia <script.jl>