Numerical Computing in Julia: A Hands-On Tutorial
This is the first post in a series of introductory material about Julia, focusing on its use in Science and Engineering.
Julia is an is a general-purpose, open-source, dynamic, and high-performance language. By leveraging a clever design around a just in time (JIT) compiler, Julia manages to combine the speed of languages like C or Fortran, with the ease of use of Matlab or Python.
Some Features of Julia
Julia has many interesting features, but here is a small sample of what I think is most basic characteristics that make Julia attractive for Science and Engineering.
- JIT Compiled. Write code that looks interpreted, and yet it gets to run as just as fast as compiled code. No need to vectorize code for performance, devectorized code is fast.
- Optionally Typed. Do some rapid prototyping with maximum flexibility, and then optimize for performance.
- Nice Mathematical Syntax. Builds upon and goes much further than classical mathematical languages like Fortran, Matlab, and Mathematica.
- General purpose. Get code from the package manager to perform all sort of tasks, from reading multiple types of databases, to data visualization, or running an HTTP server.
How to learn Julia
In this hands-on tutorial series, we will be following a project-based learning approach.
In particular, we won’t be introducing much more syntax than what is required to solve the different problems we will be tackling.
As a quick reference, it might be worth to check out the Matlab-Python-Julia Cheatsheet, and the Julia Express 16-page reference guide.
For a thorough explanation of the Julia language, you can always check out the Full Documentation.
Where to find help?
Julia is still a relatively new language, so you might not find as much information online as in other languages. For this reason, if you can’t find some answers online, don’t hesitate to address the Julia Forum, where people are very friendly and welcoming.
One of the salient characteristics of Julia is its excellent package distribution system, and the open-source community built around it.
Packages can be easily installed from the REPL. Lets install, for example, the Linear Algebra package. Simply do:
import Pkg; Pkg.add("LinearAlgebra")
For using the packages in our projects, we need to include them with a using statement:
Searching packages online
Besides from searching Google or asking in the Forums for Julia packages, there are two very useful official resources that keep track and can help you find packages:
Is Julia Really as Fast as Advertised?
Coming from a compiled-language background, I have to acknowledge that I was skeptical about this at first. So I set out to write my own benchmark, suited for my personal use case. As it turns out, I found out that after some tweaking of both the compiled code and the Julia code, that indeed Julia can be just as fast as highly-optimized Fortran code. And it can do so with 3 times less lines of code.
You can read my post about this benchmark here. The benchmark has two parts: considering some basic out-of-the-box implementation and see which is faster, and then going for highly-optimized codes and evaluate how much effort we needed to create such codes.
Long story short, my conclusion is that not only the trade-off between programmer effort and code efficiency is what makes Julia shine, but the fact that we can get serious about optimizing the speed of our codes, and make Julia really high-performance, for a fraction of the effort we would need in older compiled languages such as C or Fortran.
Is the Julia Language Free?
The Julia language was originally developed by a group of researchers at MIT, and released as open-source and under a permissive license. Julia also has a thriving open-source community responsible for the creation of thousands of packages. As such, most of Julia is and will remain free to use.
Eventually, some of the Julia founding members formed JuliaComputing, a venture backed company, to continue the development of the Julia language. The business model of JuliaComputing is offering paid support and commercial Julia packages – like a Bloomberg API for financial modelling, or a software suite for pharmaceutical companies.
Do you want to give Julia a try? Are you already programming in Julia and want to read along? This is a growing series of tutorial posts, so stay tuned for additional material!