A quantum computer, as described by the quantum gate model, can execute arbitrary quantum programs (algorithms) by applying a specific sequence of gate operations. This computing model is essentially similar to classical computing devices where those low-level operations are described by machine code instructions.
These instructions are directly mapped to a human-readable form which is often called assembly languages. In principle, every computer programs (e.g. games, simula- tion, web browsers, etc.) can and in fact must be programmed by the assembly language specific to the hardware that they are running on. The tedious process of writing com- puter programs instruction-by-instruction is thus not very practical and is best reserved for very specific use cases (e.g. low-level firmware). Most computer programmers learned to code in the so-called high-level programming languages (e.g. C/C++, Python, Java, Javascript, etc.) which are both hardware agnostic and algorithmically descriptive (as supposed to be operationally descriptive).
Hence, a quantum programming paradigm could mimic that of its classical coun- terpart, i.e. providing multi levels of abstraction from the low-level gate operations to the high-level algorithmic descriptions. This includes an assembly-language definition which closely matches (modulo trivial gate transformations) and directly executable on
5.1 Quantum Programming Language 121
quantum computer hardware. On top of that, a higher level language and the correspond- ing compiler is ultimately necessary for practical quantum programming purposes. A comprehensive solution for quantum programming language also needs to be flexible and agnostic in the sense that it can interface with both quantum hardware as well as simulators/emulators.
5.1.1 Quantum Assembly Language
The quantum assembly (QASM) language is an abstract description of operations of a general-purpose quantum computer. This includes a set of quantum instructions as well as the syntax and semantics rules. In designing our own QASM language, the Atos Quantum Assembly Language (AQASM), we take into consideration the following criteria:
• Fully quantum: Although the first generation of AQASM will only interact with a classical simulator/emulator back-end, the long-term goal is to be able to use it on a real quantum computer.
• Low-level: AQASM is designed around the quantum gate model. The basic instructions correspond to elementary quantum gates.
• Extendable: AQASM also supports user-defined quantum gates and arbitrary gate extensions by adding control or gate parameterisation.
• Standard: AQASM is the universal language for all future ATOS-developed quantum simulators to maintain interoperability.
• Complete toolchain: We also plan to develop high-level wrappers together with proper compilation programs in order to provide a high-level abstraction to devel- opers. Also, it is essential to provide parsing/translating support for other existing quantum programming languages to AQASM.
The AQASM has native support for arbitrary quantum gates (including user-defined unitary gates and gate parameterisation), expanding quantum gates (e.g. complex conjugate and adding control), and basic quantum operations (e.g. quantum Fourier transform). An example of AQASM programs is given in Fig. 5.1.
The compilation of AQASM into quantum circuit data structures is implemented in Coco/R [113], which is a widely-used framework for syntax validation and compiler
122 Chapter 5. Quantum Programming and Simulation DEFINE GATE qft2 = QFT[2] DEFINE GATE qft10 = QFT[5] BEGIN qubits 3 QFT q[0],q[1],q[2] H q[0] S q[1] T q[2] CNOT q[0],q[1] GATE ex q[1] X q[2] CNOT q[1],q[2] IQFT q[0],q[1],q[2] DAG(CTRL(RX[PI/2])) q[2],q[0] END
Fig. 5.1 An example of arbitrary quantum circuit described by the Atos quantum assem- bly language.
generation. By defining the compiler descriptions, which includes the list of keywords (tokens) as well as all the syntax and semantics rules, we can use Coco/R to generate the corresponding scanner and parser to process the AQASM inputs.
5.1.2 High-level Programming and Data Processing
The advantages of assembly languages are the strong correspondence between the language, i.e. the instructions, and the physical operations, i.e. quantum gates, on quantum hardware. Experimentalists can import such a program as in Fig. 5.1 and readily generate the control sequence for lab instruments to implement the AQASM program. Or as in the case of our simulation back-end, it can take those AQASM programs and perform the simulation accordingly.
However, the main drawback of low-level languages, e.g. AQASM, is its verbosity, which often hides the algorithmic structure and hierarchy of the program. For example, let’s take a look at an 18-qubit quantum Fourier transform program written in AQASM2 as depicted in Fig. 5.2. There are approximately 170 AQASM instructions in that program which has been abbreviated for brevity.
2This is an explicit AQASM representation of the QFT algorithm. The language does have native support for QFT and inverse QFT (IQFT) as demonstrated in Fig. 5.1.
5.1 Quantum Programming Language 123 BEGIN qubits 18 H q[0] CTRL(PH[PI/2]) q[1], q[0] H q[1] CTRL(PH[PI/4]) q[2], q[0] CTRL(PH[PI/2]) q[2], q[1] H q[2] CTRL(PH[PI/8]) q[3], q[0] CTRL(PH[PI/4]) q[3], q[1] CTRL(PH[PI/2]) q[3], q[2] H q[3] CTRL(PH[PI/16]) q[4], q[0] // Skipping ... // H q[17] END
Fig. 5.2 An example of 18-qubit QFT program written in AQASM. The body of the program has been abbreviated for clarity.
Most people will find it difficult to comprehend a program as in Fig. 5.2. More importantly, it is extremely tedious and error-prone for developers/programmers to write quantum programs in that manner. Hence, upon the complete definition of AQASM in terms of language features, semantics and syntax rules, we embarked on creating high-level wrappers for AQASM in commonly-used classical programming languages. For instance, for Python, we developed PyAQASM package3which supports looping, subroutine declarations, function calls, classical processing of intermediate data, etc. For comparison, the same 18-qubit QFT program in Fig. 5.2 can be expressed in PyAQASM using the program listed in Fig. 5.3.
The looping and parametrisation supported by PyAQASM not only shorted the program significantly but also allow novice readers to comprehend the overall structure of the algorithm. In addition, by having Python support with PyAQASM, we can integrate the programming workflow more seamlessly. For example, a web interface can be used to input the PyAQASM program; the user’s computer can then generate
3The author and other researchers of the ATOS Quantum Lab collaborated on defining the AQASM language itself. The implementation of the Coco/R-based compilation unit was developed by another researcher. The author supported the testing of the compiler and implemented the first high-level Python- based wrapper as described in this section.
124 Chapter 5. Quantum Programming and Simulation
from AQASM import *
nbqubits = 18
AQASM_prog = AQASM("QFT.aqasm", nbqubits)
for i in range(nbqubits - 1):
AQASM_prog.apply(qGate("H"), qubit(i))
for j in range(i+1):
phase = "PI/" + str(2**(i-j+1))
AQASM_prog.apply(
qGate("PH", CTRL = ’true’, PHASE = phase), [qubit(i+1), qubit(j)])
AQASM_prog.apply(qGate("H"), qubit(nbqubits - 1))
AQASM_prog.finish()
Fig. 5.3 An example of 18-qubit QFT program written in PyAQASM. PyAQASM is a Python-based wrapper for AQASM which can export the corresponding AQASM program for simulation and experiment purposes.
the AQASM and serialise it via the Internet to the simulator (e.g. a supercomputer in a remote server room) or real quantum hardware in a remote laboratory; the result data of that algorithm is returned to the user for further data analysis and visualisation.
In the next session, we will discuss the ATOS quantum simulator which is a High- Performance Computing (HPC) software program designed specifically to simulate quantum programs written in AQASM.