Articles on Quantum Computing Quantum Resources

Could Julia replace Python and be transformational in Quantum Computing?

January 17, 2020

Looking around at language development and you’d be forgiven for thinking that just about everything can be programmed in the python programming language. In some ways this is peak python. In the last 20 years alone (python is older) python has gone from what I would describe as a scripting language to a fully fledged programming language taught in schools and universities. Python is the new BASIC, and even now children as young as two and three are exposed to this language. BASIC was a very popular language in the 1970’s as it ran on many micro computers which were just entering the home for the first time.

BASIC (Beginners’ All-purpose Symbolic Instruction Code)

The programming language went through explosive growth due to the era of the home computer during the 1980’s.

With the rise of Machine Learning and AI like applications, python has found itself as the swiss-army knife of computing. It’s native data structures lend themselves to many of the data challenges that many data scientists face. Natively python supports data structures such as lists and dictionaries which in other languages such as C are much more difficult to implement. And that fact makes the job of data science much more straightforward such that programmers and data scientists can deal with the challenges of modelling rather than creating bespoke data structures (anyone for a doubly linked list?)

Python appears to be the new BASIC programming language of the 21st century

Quantum Zeitgeist

The rise of Python has been phenomenal and just about every Quantum framework uses python in some way. For example many of the main frameworks such as IBM Q Experience which uses the open source Qiskit utilised python as its “control language”. Of course much of the complexity of the Quantum Operations are abstracted away, but not that it matters as this functionality is easily access from within python. The language Python becomes the glue that allows components to operate together and even direct a Quantum Computer.

The rise of Python. 2019 Stackoverflow study on the growth of languages. Notice that Julia doesn’t even appear.

Quantum Frameworks use Python

If ever you want a motivation to learn Python, just look at the number of Quantum frameworks that employ python. Qiskit is not the only framework to use the language. Consider that PennyLane (from Xanadu), CIRQ (QC Ware, Google) all use Python. CIRQ is an open source Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.

Simulation vs Quantum Hardware

We should make something very clear here. Only speed-up or quantum advantage can be realised if and only if there is some hardware available that takes advantage of quantum physics. This might make the programming language somewhat of a moot point.

In the simulation world (where researchers build algorithms to take advantage of a potential future speedup but are not run on Quantum hardware) algorithms may benefit from swapping to an appropriate language, because of “classical” speed-up. Then there is a possibility of choosing a programming language that is not only fast but lends itself well to dealing with the type of problem faced by Quantum scientists, typically linear algebra.

Frameworks and software from Quantum vendors allow users to swap between simulation and running on actual Quantum Hardware. That means that behind the scenes the purpose of the control language that the user writes is to generate the simulation or talk to the Quantum hardware.

The point being made here, is whether a language such as Julia has a place in Quantum Simulations and the effective control of an actual Quantum Computer. Because there are potential speed advantages and development advantages (easy syntax for example) to using Julia for simulations. The open question is whether the language will be as flexible as Python as a control language, when all that matters is to call some kind of functionality.

Has innovation ended with Python?

Not every framework under the sun uses python. Microsoft is different on this is and created its very own language suited to the Quantum environment. They called it, surprise, Q#, they certainly like the # (sharp) moniker which they used for their C# language.

As a multi-decade user of python, and a python lover, there are a few aspects that may come back to bite the language (excuse the snake analogy).

No inbuilt linear algebra

These drawbacks are the lack of native math operations, especially matrix operations (before you shout about NumPy), the fact is that it is not technically native within the language itself – it must be “imported” and it can be rather clunky and a little counter intuitive. But at least it is there, free and “ready-ish” to use. NumPy is written in C and is optimised (even though python itself is not that fast compared to a program written in C and compiled). However NumPy still allows fairly rapid computation of matrix operations for example but is is a match for newer scientific languages like Julia?

Speed bumps in executing Python

Another aspect to consider for language selection is speed. Python being interpreted as a language somewhat limits its speed and as we’ll see that one of the possible future challenges of Python (and yes you can actually compile python to make it faster). However the figures show the speed differences between the Julia and Python language with speed of Julia approaching that of native C, which is quite an achievement.

Julia language against other languages. You can see the marked difference in speed between Python and Julia with Julia beating almost everything bar the C language.

Matrix Operations in Python and Julia

Delving a bit deeper, we show the difference in syntax between using Python and Julia for a simple matrix multiplication. Here we try to illustrate some of the advantages to the Julia syntax.

# Python
import numpy as np 
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6], [7, 8]])
c = np.matmul(a, b)

Results in the matrix a, being multiplied by b. Nothing difficult. But you can see we had to load in the numpy library and call the matmul method in order to make the computation.

[[19 22]
 [43 50]]

Now let us look at the Julia syntax how we go about doing exactly the same. The first aspect to notice is that the matrices are first order. That means we can operate on them much like we do simply with numbers in python.

a = [1 2; 3 4]
b = [5 6; 7 8]
c = a*b

and the result

[19 22; 43 50]

Look no need to invoke any methods or import any libraries. We just multiply and if we wanted to actually do a matrix transpose, we can do that just as easily with a simple dash (‘). Let’s do that for fun below.

a = [1 2; 3 4]
b = [5 6; 7 8]
c = a*b'
[17 23; 39 53]

Did you spot that? Super easy to do. It doesn’t require anymore typing (in python we need to call a method/function). This is not meant as a full tutorial (there are plenty on the web) but as very brief intro so you can get more of a flavour how you might use features of the Julia language.

Quantum Julia Projects

The 8 year old language is proving popular for scientific applications

There are Quantum projects that are based on Julia – not many, but we think it is still early days for the Julia language despite some of its benefits with ease of use and speed advantages.

QuantumOptics is one open source project for simulating open quantum systems. Published in 2018, the archive is here. But you can read more from the QuantumOptics github project. However this is not a library for operating a Quantum Computer and is domain specific.

But if you want to perform simulations you can. One challenge is if you design for such as system and want to run on hardware how to port this over. The author believes that Rigetti are interested in exploring Julia but as yet not a language that the end user can utilize within their Forest Framework.

Perhaps more familiar to projects that many researchers are familiar to is Yao, which aims to be an Extensible, Efficient Quantum Algorithm Design for Humans which has some of the speed advantages of Julia without some of the headaches. Of course there is not widespread support yet for such frameworks.

Of course why Python works so well for the Quantum frameworks is that the end user doesn’t need to do the heavy lifting of all the calculations – these are abstracted away and python becomes the glue or the control language. That said Julia might have a place in replacing what are becoming quite complex stacks of multiple languages.

Should I learn the Julia language?

Many scientists will actually find Julia more intuitive and some sense easier than python. However python still is on an ascendancy and is the language of choice for many Quantum frameworks – and that is likely to be the case for a while. However it does not hurt to imagine a Julia future and the language might find a way into more Quantum applications.

You can learn more about the Julia language from the official site.

Take home message

Sadly we cannot delve into every framework out there, but do let us know if anyone has come up with a native Julia language framework that allows both Quantum Simulation and Quantum Computation on hardware.