You may not have heard of Julia the language. But I’m pretty sure you have heard of python. In this article we’ll explore some of the syntax behind the Julia language and why it might be an interesting alternative to commonly used languages such as python used in data science and in quantum information and quantum computing.
There are two main advantages which we think will drive adoption of Julia. Those are speed and ease of reading syntax expressions. For example, matrix operations and linear algebra in Python or most other languages require additional libraries. Sure in python, NumPy is the go-to library for numerical operations such as linear algebra and other frameworks can handle the machine learning (assuming you don’t want to build your own) , such as Tensorflow, PyTorch or another python library such as Scikit-learn.
But what if you wanted to build your own tooling or work on more fundamental issues where an existing framework doesn’t have that inbuilt functionality. Sure you can do this in python, but what about the merits of Julia?
We’ll show you some simple routines that will hopefully inspire you to take a look at Julia. For some of the advantages of Julia over python and other languages you can look at our other article on Julia.
Julia Syntax makes Linear Algebra easy
One of the great things about Julia is that for Linear Algebra, it works right out of the box. So that means no packages to be installed. Just use it. There is also a very natural way to interact with matrices/vectors because they are first order, meaning we can just use them very easily. Let’s do some simple Linear Algebra to illustrate.
This is so intuitive, Julia does it all for you. It could not be easier. You literally define your matrices and multiply them. Simple!
a = [1 2; 3 4] b = [5 6; 7 8] c = a*b print(c)
Other Matrix Operations
Creating a transpose is also super easy. Unlike other languages (i.e. python), you can perform a matrix transpose with a single character. Super easily. Just add a ” ‘ ” after the variable. Below is a simple example.
a = [1 2; 3 4] b = [5 6; 7 8] c = a*b' print(c)
[17 23; 39 53]
Let’s do something else…
Create a density
This is really common operation in Quantum Mechanics. In Julia – it’s super easy to create, you can use the following syntax to create a density or outer product.
a = [0.5 0.5] print(a) d = a'*a print(d)
So pretty easy to do calculations with the most minimum of typing or looking up documentation trying to find the right location in the documents.
Invert a matrix
As you’d expect, this is again very easy and very natural.
a = [1 2; 3 4] print(inv(a))
Factoring a matrix can be more complicated, but, it basically can be completed with ease in Julia, and there are a whole whole host of different ways a matrix can be factored – catered for in Julia. For those who really want to delve into the details, you can read the extensive and pretty clear documentation.
Could there be a big role that Julia plays in Quantum Computation?
It is still early for Julia as a language – if anything like python which took decades to reach common parlance – Julia is still at the early stages of its development and is only 8 years old. Release version 1.0 only happened in 2018.
Certainly in academia Julia appears to be gaining traction for its ease of expressing quantum mechanical / informational concepts. Whether it will find itself useful in the quest for building a quantum computer is another matter.
To read more about some of the advantages in terms of speed of Julia, you can see another QZ article article published on the advantages of using Julia for Quantum Simulation.