Load and run Julia

Note

At the Swedish HPC centers we call the applications available via the module system modules:

Objectives

  • Learn to load Julia

  • Get started with the Julia command line

  • Learn to run Julia scripts

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. All modules at UPPMAX, for instance, not directly related to bio-informatics are shown by ml avail.

Modules at many other centres are only available when one has loaded all prerequisites,

for instance the compilers (GNU, Intel, etc.).

Check for Julia versions

Principle

  • For some clusters

$ module avail julia
  • Or, at clusters that hides the modules until relevant dependencies are loaded (HPC2N & PDC)

$ module spider julia

Load a Julia module

For reproducibility, we recommend ALWAYS loading a specific module for the Julia version instead of using the default one.

Principle

  • Use the overview of existing module above!

  • Load the module!

At some clusters:

$ module load julia/1.8.5

or at cluster that includes “architecture” or “build name” in module name:

$ ml julia/1.10.2-bdist

Some clusters will require other modules to be loaded (Kebnekaise and Dardel)

  • First check how to load (see Check for Julia versions above)

$ module spider julia/1.10.2-cpeGNU-23.12

  ...
  You will need to load all module(s) on any one of the lines below before the "julia/1.10.2-cpeGNU-23.12" module is available to load.

  PDC/23.12
  • Load PDC/23.12 first and then the julia module

$ ml PDC/23.12 julia/1.10.2-cpeGNU-23.12

Run

Run Julia as a session

  • After loading the appropriate modules for Julia, you will have access to the read-eval-print-loop (REPL) command line by typing julia:

$ julia
  • In julia REPL

Modes: Julian mode

  • Julia has different modes, the one we arrive at is the so-called Julian mode, where one can execute commands.

  • The description for accessing these modes will be given in the following paragraphs.

  • Once you are done with your work in any of the modes, you can return to the Julian mode by pressing the backspace key.

Shell mode

While being on the Julian mode you can enter the shell mode by typing ;:

julia>;
shell>pwd
/current-folder-path

this will allow you to use Linux commands. Notice that the availability of these commands depend on the OS, for instance, on Windows it will depend on the terminal that you have installed and if it is visible to the Julia installation.

Package manage mode

Another mode available in Julia is the package manager mode, it can be accessed by typing ] in the Julian mode:

julia>]
(v1.8) pkg>

this will make your interaction with the package manager Pkg easier, for instance, instead of typing the complete name of Pkg commands such as Pkg.status() in the Julian mode, you can just type status in the package mode.

Help mode

The last mode is the help mode, you can enter this mode from the Julian one by typing ?, then you may type some string from which you need more information:

julia>?

help?> ans
search: ans transpose transcode contains expanduser instances MathConstants readlines
LinearIndices leading_ones leading_zeros

ans

A variable referring to the last computed value, automatically set at the interactive prompt.

Exiting

Exit with

julia> <Ctrl-D>

or

julia> exit()

The Julian modes summary

  • enter the shell mode by typing ;

  • go back to Julian mode by <backspace>

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

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

Run a Julia script

You can run a Julia script on the Linux shell as follows:

$ julia example.jl

where the script is a text file could contain these lines:

println("hello world")

Exercises

1a. Find out which versions are on your cluster from documentation

  • Find/search for that documentation!

1b. Find out which versions are on your cluster from command line

  • Use the spider or avail module commands

1c. Which method to trust?

2. Try to start julia without having loaded julia module

  • If you have a julia module loaded already, you may unload it with the unload command.

    • Tip: Type: unload julia and press <tab> until the full module name is shown, then press <enter>. (If the Julia module starts with an uppercase, use that instead!)

3. Load and start julia from the command line

4. Getting familiar with Julia REPL

  • It is important that you know how to navigate on the Julia command line. Here is where you work live with data and test aout things and you may install packages.

  • 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.

5. Load another module and run a script

  • Load the latest version and run

  • 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)
    

6. Check your understanding

  • Check your understanding and answer in the shared document

  • Can you start Julia without loading a Julia module?

    • Yes?

    • No?

  • Which character to use to toggle

    • to the package mode?

    • back to the Julia mode?

    • to the help mode?

    • to the shell mode?

Keypoints

  • Before you can run Julia scripts or work in a Julia shell, first load a Julia module with module load <julia module>

  • Start a Julia shell session with julia

  • It offers several modes that can make your workflow easier, i.e.

    • Julian

    • shell

    • package manager

    • help

  • Run scripts with julia <script.jl>