Instructor Notes
Audience
Competent programmer in another language like Python, R, or Matlab.
Goal
Julia is designed to solve the two-language problem. Languages like Python and R are easy to get started with, but don’t offer the efficiency of compiled languages like C++, Rust or Fortran. Often the easier scripting languages offer a front-end for code implemented in one of the compiled languages. This means that, to implement a solution that is both efficient and user friendly, you need to write your package in two languages. This comes with several problems:
- The front-end talks to the back-end through a native interface (C-ABI) which is often unsafe and can cause bugs.
- Developers need to be competent in two languages as well as the interface between them.
- Native libraries can be hard to compile due to a stack of dependencies.
- Existing packages are hard to extend, i.e. the learning gradient from incidental user to developer is too steep considering the non-professional nature of most scientific applications.
- Interaction between different packages is often limited to the slower scripting language.
Julia solves these problems by offering a language that is both easy to get started with, and can achieve native performance. Furthermore, Julia has an excellent packaging system that solves many of the reproducibility problems associated with other languages. Although it is possible to write programs in Julia that perform similar (and sometimes even better) as in native languages (C, Fortran), actually getting to these levels of performance is not trivial.
This workshop aims to get research software engineers from their first steps in Julia to become aware of all the major techniques and pitfalls when it comes to writing performant Julia.
Setup
Participants will have to install Julia by following the instruction
on the Julia webpage,
downloads section. They should be provided an environment with a
Project.toml
so they can precompile any dependencies before
the workshop starts. In most cases this should suffice, though we have
encountered university-managed Windows laptops in the wild that gave
problems.
Workflow
We’re teaching using VS Code as the main environment. If you prefer,
you might also use Pluto, but interactive Makie
plots don’t
work so well in Pluto (you’d use PlutoUI
instead), and the
@profview
macro needs an extra dependency to work from
Pluto.
Sillabus
The following sillabus assumes 6 hours of effective teaching per day.
Day 1: Introduction to Julia
- Using Pluto
- Basics of Julia: 3h
- basic operations, flow control and functions
-
Unitful
quantities - types and multiple dispatch
- arrays and broadcasting
- Plotting using
Makie
: 1h- Lorenz attractor
- Package development with
Pkg
: 1h - Best practices: testing and documentation: 1h
BestieTemplate
Day 2: Efficient with Julia
- Measuring speed with
BenchmarkTools
: 1h- closures to reduce allocations
- static types to reduce dynamic look-up
- Types: 1h
- parametric types
- generic types
- value types
- Type stability: 1h
-
JET
andCthulu
-
- Parallel programming: 1h
- Channels
- Threads and Tasks
- Transducers
- GPUs
- Computing Julia fractals: 2h
1-day alternative
- Using Pluto
- Basics of Julia: 3h
- basic operations, flow control and functions
-
Unitful
quantities - types and multiple dispatch
- arrays and broadcasting
- Measuring speed with
BenchmarkTools
: 2h- closures to reduce allocations
- static types to reduce dynamic look-up
- Best practices with
BestieTemplate
: 1h
Oddities
Many of the code blocks have a comment stating some sort of id.
These are used to collect code blocks into executable units for automated testing and rendering of output figures, using Entangled. You can certainly ignore them while teaching.
Getting Started
Teaching strategy
Julia is easy to get into because it centers around a few easy to
understand core concepts: functions, multiple-dispatch, array
polymorphism. It is easy to get needlessly stranded into complications
that hinder the pacing of this lesson. For example: when explaining
for
loops you may spend ten minutes explaining all the
finesse of break
and continue
, but most people
will either know or don’t care. There are several ways to fill these
gaps in the material:
- Explain these concepts when they naturally arise in an example or exercise.
- Point to their existence in a call-out, but refer interested readers to the relevant section in the Julia manual, to study in their own time.
- Give them as part of an exercise: let participants read a section of the manual before solving the exercise. This should empower them to look for the manual when solving their own problems.
This way, you can move on in a natural pacing, only showing the core concepts relevant to the Julia language, and get to interesting (and motivating) challenges earlier in the lesson.
You may want to explain this general strategy to participants before starting on the main content. This will build both patience and trust with your audience.
Introduction to Julia
Instructor Note
Much of the content of the lesson relies on “Show, don’t tell”. This introduction feels far from complete, but that’s Ok. It is just enough to teach the forms of function definitions, and some peculiarities that might trip-up people that are used to a different language.
Types and Dispatch
Instructor Note
Parametric types will only be introduced when the occasion arises.