Load and run Julia
Menti
What would you like to use Julia for?
What do you want to learn today?
Note
At both UPPMAX and HPC2N we call the applications available via the module system modules.
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.
Short cheat sheet
See which modules exists:
module spider
orml spider
Find module versions for a particular software:
module spider <software>
Modules depending only on what is currently loaded:
module avail
orml av
See which modules are currently loaded:
module list
orml
Load a module:
module load <module>/<version>
orml <module>/<version>
Unload a module:
module unload <module>/<version>
orml -<module>/<version>
More information about a module:
module show <module>/<version>
orml show <module>/<version>
Unload all modules except the ‘sticky’ modules:
module purge
orml purge
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
Check all available version Julia versions with:
$ module spider julia
To see how to load a specific version of Julia, including the prerequisites, do
$ module spider Julia/<version>
Example for Julia 1.8.5
$ module spider Julia/1.8.5
Output at UPPMAX as of Feb 29 2024
$ module av julia ----------------------------- /sw/mf/rackham/compilers ----------------------------- julia/1.0.5_LTS julia/1.6.1 julia/1.7.2 julia/1.9.3 (D) julia/1.1.1 julia/1.6.3 julia/1.8.5 (L) julia/1.4.2 julia/1.6.7_LTS julia/1.9.1 Where: D: Default Module Use "module spider" to find all possible modules and extensions. Use "module keyword key1 key2 ..." to search for all possible modules matching any of the "keys".
Output at HPC2N as of Feb 29 2024
$ module spider julia ------------------------------------------------------------------------------------------------ Julia: ------------------------------------------------------------------------------------------------ Description: Julia is a high-level, high-performance dynamic programming language for numerical computing Versions: Julia/1.5.3-linux-x86_64 Julia/1.7.1-linux-x86_64 Julia/1.8.5-linux-x86_64 ------------------------------------------------------------------------------------------------ For detailed information about a specific "Julia" package (including how to load the modules) use the module's full name. Note that names that have a trailing (E) are extensions provided by other modules. For example: $ module spider Julia/1.8.5-linux-x86_64 ------------------------------------------------------------------------------------------------
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
$ module load Julia/1.8.5-linux-x86_64
Note: Uppercase J
.
For short, you can also use:
$ ml Julia/1.8.5-linux-x86_64
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 modeenter 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 6Change to the
shell
mode and display the current directoryNow, go to the
package
mode and list the currently installed packagesFinally, display help information of the function
println
inhelp
mode.
Solution for centres
$ julia julia> 5 + 6 julia>; shell> pwd julia>] pkg> status julia>? help?> println
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)
Solution for HPC2N
This batch script is for Kebnekaise.
$ ml purge > /dev/null 2>&1 # recommended purge $ ml Julia/1.8.5-linux-x86_64 # Julia module $ julia serial-sum.jl Arg1 Arg2 # run the serial script
Solution for UPPMAX
This batch script is for UPPMAX. Adding the numbers 2 and 3. (FIX)
$ ml julia/1.8.5 # Julia module julia serial-sum.jl Arg1 Arg2 # run the serial script
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>