@def title = "WS23 Julia ULG" @def tags = ["syntax", "code"]
This workshop was originally designed to cover a few modules in the first semester of the University Continuing Education Programme Data Science – From Mathematical Foundations to Applications and intended for roughly 20 hour workshop-style in-class instructions.
In case you want to refer to this lecture material, use the following BibTex snippet:
@misc{gregor_ehrensperger_2023_8251750,
author = {Gregor Ehrensperger and
Johannes Sappl and
Stephan Antholzer},
title = {WS22/23 ULG Data Science - Julia},
month = aug,
year = 2023,
publisher = {Zenodo},
version = {1.2},
doi = {10.5281/zenodo.8251750},
url = {https://doi.org/10.5281/zenodo.8251750}
}
Parts of the following lecture material were taken from the on-site Julia workshop Introduction to Scientific Coding with Julia which was written by Gregor Ehrensperger, Peter Kandolf, and Jonas Kusch and held in Obergurgl in July '22:
- Section Start is mostly taken from Start - Introduction to Scientific Coding with Julia.
- The foundation of the section Introduction is taken from Introduction - Introduction to Scientific Coding with Julia and Measuring Performance - Introduction to Scientific Coding with Julia.
- Parts of Data Management are taken from Data Science - Introduction to Scientific Coding with Julia.
- Parts of Reporting are taken from Pluto Notebook - Introduction to Scientific Coding with Julia.
Julia is a free and open source scientific programming language with a vast ecosystem of libraries that aim towards scientific computing. Visit julialang.org for the download, documentation, learning materials and much more. Julia manages to allow the best of two worlds, high-level interpreter and low-level compiler language. It offers the high performance of compiled languages like C or Fortran by still bringing in the simplicity of dynamic languages like Python or R. Julia recently entered its teens and for this occasion a blog post was published with the title Why We Use Julia, 10 Years Later as a follow up to the Why We Created Julia. Both entries are a good read and give you an insight into the language and its creators.
In this lecture we are going to take a look at Julia by starting with the basics and working our way up to advanced topics like data science and multiprocessor programming.
For this lecture you neither have to know details about Julia nor be a programming expert. We will introduce new programming and Julia concepts along the way with demonstrative examples. For this purpose you will find code blocks that you can copy if necessary (top right corner copy
). Furthermore, if we think something is very important we will highlight it with a box:
@@important Pay extra attention to the content here. @@
We also have various environments with different color coding that usually are collapsed to not hinder the reading process:
- Examples are green \example{Examples are also quite nice because they make sure you have an idea what is happening.}
- Exercises are blue \exercise{Exercises are here for you to work on, no worries not at home or in your off hours but with us in the lecture.}
That is about all we wanted to let you know, so let us get into it.
@@important We ask you to install Julia, Visual Studio Code (optional) and the Julia extension for Visual Studio Code (optional) before the lecture so we can start right away. If you have difficulties please let us know and we will update the contents of this page accordingly. @@
@@important This lecture was prepared with Julia v1.8.4 @@
Follow the setup in this section to install everything that is required to get started.
To install Julia on your system please download the latest stable binary from Setup Download and follow the instructions on Setup Julia for the installation.
Under the above link you will also find instructions on how to uninstall Julia, even though we are quite sure you will not want to do it ;).
Alternatively you can also use juliaup to install and use Julia. This handy little gadget allows for automatic updates as well as easy parallel installation of and switching between different Julia versions.
Some distributions allow for Julia to be installed via the package manager or software center. Note that very often this is an old version so this method is not recommended.
A very convenient way to manage your Julia installation is juliaup. To install this tool, simply call the following command from your terminal:
curl -fsSL https://install.julialang.org | sh
Once installed, simply reopen your terminal and call juliaup add 1.8.4
to add the very version used for this course. In case you installed Julia just for this course, you could then set
juliaup default 1.8.4
to pin your default version to 1.8.4
whenever you start julia
. Alternatively you can launch this specific version by calling julia +1.8.4
.
Installing Visual Studio Code is optional since one can use any editor for programming in Julia but Visual Studio Code (+plugin) is the most common "Julia IDE". For example JuliaEditorSupport has plugins for some alternative editors.
Follow the instructions on https://code.visualstudio.com/ to install Visual Studio Code.
Visual Studio Code, also commonly referred to as VS Code, is a fully-fledged interactive development environment (IDE), complete with code highlighting, autocomplete, debugger, Git integration and much more. In order to make VS Code fully compatible with Julia we need to install the Julia extension.
Follow the instructions on VS Code Julia extension to install and configure the extension. You can find the basic instructions from above here as well.
\exercise{Please run the minimal working example from here to see whether you have set up everything correctly.}
If you run into difficulties with VS Code in connection with Julia, the documentation of the Julia extension is an excellent source for help.
There is no better resource than https://www.julia-vscode.org to explain how to program in Julia with VS Code. The website also provides an interactive view of some of the following concepts.
- On the left you have the navigational panel where you can switch between context of the viewer. Specifically you will need the Explorer and Julia.
- Right next to it you get additional information with regards to the current context. For example you will see files, when you are in Explorer or you see your Workspace, Documentation, and Plot Navigation in the Julia context.
- When opening a Julia file (ending in
.jl
) (double click in the Explorer - single click only gives you a quick view and the file will not stay open if you click another file) you have syntax highlighting and autocomplete right away. - To run a Julia program, click the small arrow on the top left or
Ctrl+F5
if you prefer keyboard shortcuts. Both will run the code in the Julia REPL. You will see the output on the bottom.
With these short basics and https://www.julia-vscode.org you are good to go for the lecture. You can also find a list of keybindings once you are more familiar with the IDE and never want to get your hands off the keyboard.
In VS Code you can always type CTRL + SHIFT + P
to get access to the prompt and execute commands within VS Code.