Julia Interfaces in the SSCC

The SSCC has Julia installed on the Linstats.

The SSCC supports three interactive interfaces for running Julia scripts on Linstat:

  • the Julia REPL, the basic interactive Julia interface, useful for project and package management or other light tasks
  • VS Code using a remote connection to Julia on Linstat, for working with code in script files
  • Jupyterlab with a Julia kernel, making it easy to combine text and code snippets in a “notebook”

To run Julia in batch mode or via Slurm, see the Guide to Research Computing.

Batch mode

If you are developing a script that you will later run in batch mode from a command prompt (for example, using Slurm), you will probably prefer VS Code.

Both VS Code and the Jupyterlab interfaces include an interactive (type-one-command-at-a-time) interface, equivalent to Julia REPL.

Your Julia configuration files (command history, package downloads, default environment, etc.) are all located in your Linux home directory, in ~/.julia. These are shared across all three interfaces.

Organize your work in “projects”

To ensure that your code will work with future Julia updates, you should work in projects

Outside the SSCC, VSCode and Jupyter are both popular interfaces (see the annual Julia Developer Survey, 2023, slide 19).

Julia REPL

The Julia REPL is the basic interactive interface. In it, you type one command at a time, and get back immediate results. This can be useful for light tasks such as package management and project set up. It appears extensively in the Julia documentation. For working with longer scripts, you will prefer VS Code or Jupyterlab.

Log on to Linstat, and at the linux prompt type

linstat> julia

The result should look like this:

> julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.9.4 (2023-11-14)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia>

You are now ready to begin typing in Julia commands, one at a time. When you are finished, type Ctrl-D or

julia> exit()

The first time you do this it will create a hidden folder, .julia in your Linux home directory. As you add packages to Julia, this builds a folder structure and creates a default environment.

Julia with VSCode

You can use VS Code from Winstat, or install VS Code on your own computer. Then install the Remote-SSH extension, connect to Linstat, and then install the Julia extension. (This is similar to setting up Julia in VS Code on your own computer, except that Linstat gives you much more computing power!)

The steps are:

  • Install VS Code on your computer or use VS Code on Winstat.
  • Install the Remote-SSH extension in VS Code.
  • (if not using Winstat) VPN to the SSCC network
  • Connect to Linstat from VS Code.
  • Install the Julia extension in VS Code.

See Julia’s Remote Development for more documentation.

VS Code is a script editor connected to a live Julia session. This enables you to save your scripts as simple text files. You can execute an entire file at once, but also submit one line of code (Ctrl-Enter) or a code “cell” (Alt-Enter, cells are delimited with “##” at the beginning of a line) at a time.

(It is also possible to use VS Code to edit Julia markdown documents or Jupyter notebooks.)

Julia with Jupyterlab

Using the Julia kernel in Jupyterlab allows you to create “notebooks” that contain code cells and text (Markdown) cells. This is particularly useful for writing technical documentation or as a pedagogical tool. It enables you to break your code up into blocks (aka “chunks” or “cells”) so that you can run it block-at-a-time, an essential feature for debugging command scripts.

An advantage of notebooks is that they contain both your code and output, interwoven. This can be helpful when reviewing (or debugging) how you got a particular result (or error). However, be aware that it is possible to run code cells out of order and save the results - the saved state of a notebook is not always reproducible!

The main disadvantage of notebooks is that they are NOT simple text files. There are, however, easy-to-use utilities for extracting command scripts as simple text files, including the nbexport function in the Julia NBInclude package and the convert_doc function in the Weave package. See the Guide to Research Computing - Programs section for more on Jupyterlab in the SSCC.

First Time Setup

Before Jupyterlab can create a notebook that runs Julia code, a kernel has to be installed that will connect Jupyter and Julia.

To install the Julia kernel for yourself (if you don’t see a Julia kernel in the Jupyter notebook “launcher”, or if none of the Julia kernels there work), you need to log on to Linstat and use the Julia REPL (see above) to install the IJulia package.

In Julia, type:

julia> using Pkg
julia> Pkg.add("IJulia")

You will see a lengthy response, while Julia installs IJulia and its dependencies. After this process has finished, you need to load IJulia. This is where the kernel for Jupyter is actually created and installed for you.

julia> using IJulia
julia> installkernel("julia")

That’s it! You can exit the Julia REPL.

julia> exit()

A quick check that this succeeded is, at the Linux prompt, type:

linstat> jupyter kernelspec list

You should see a Julia kernel listed. For instance, I get this result:

Available kernels:
  julia-1.9        /home/h/hemken/.local/share/jupyter/kernels/julia-1.9
  nbstata          /software/anaconda/share/jupyter/kernels/nbstata
  python3          /software/anaconda/share/jupyter/kernels/python3
  sas              /software/anaconda/share/jupyter/kernels/sas

Launching Jupyterlab in the SSCC

To use Julia in the Jupyterlab interface, log on to Linstat and at the Linux prompt type

linstat> sscc-jupyter

You will then copy-and-paste the URL that appears into a web browser on your computer. Jupyter sometimes takes a moment to come up after you have entered the URL.

Once the Jupyterlab interface is loaded you will have options for several languages (“kernels”) to use. Pick the Julia kernel. After a new notebook opens this too may take several moments (up to 30 seconds) to be ready.

For more documentation on Jupyterlab, see the Guide to Research Computing