You are on page 1of 15

A Practical Quantum Instruction Set Architecture

Robert S. Smith, Michael J. Curtis, William J. Zeng


Rigetti Computing
775 Heinz Ave.
Berkeley, California 94710
Email: {robert, spike, will}@rigetti.com

IV Quil Examples 9
AbstractWe introduce an abstract machine archi- IV-A Quantum Fourier Transform . . . . . 9
arXiv:1608.03355v2 [quant-ph] 17 Feb 2017

tecture for classical/quantum computationsincluding


compilationalong with a quantum instruction lan- IV-B Variational Quantum Eigensolver . . 9
guage called Quil for explicitly writing these computa-
tions. With this formalism, we discuss concrete imple- IV-B1 Static Implementation . . . 9
mentations of the machine and non-trivial algorithms IV-B2 Dynamic Implementation . 10
targeting them. The introduction of this machine dove-
tails with ongoing development of quantum computing
technology, and makes possible portable descriptions V Forest: A Quantum Programming Toolkit 10
of recent classical/quantum algorithms. Keywords
quantum computing, software architecture V-A Overview . . . . . . . . . . . . . . . . 10
V-B Applications and Tools . . . . . . . . 11
Contents
V-C Quil Manipulation . . . . . . . . . . . 11
I Introduction 1 V-D Compilation . . . . . . . . . . . . . . 11
V-E Instruction Parallelism . . . . . . . . 12
II The Quantum Abstract Machine 2
V-F Rigetti Quantum Virtual Machine . . 12
II-A Qubit Semantics . . . . . . . . . . . . 2
II-B Quantum Gate Semantics . . . . . . . 3 VI Conclusion 13
II-C Measurement Semantics . . . . . . . . 4
VII Acknowledgements 13
III Quil: a Quantum Instruction Language 5
III-A Classical Addresses and Qubits . . . . 5 Appendix 13
III-B Numerical Interpretation of Classical A The Standard Gate Set . . . . . . . . 13
Memory Segments . . . . . . . . . . . 5
B Prior Work . . . . . . . . . . . . . . . 13
III-C Static and Parametric Gates . . . . . 5
B1 Embedded Domain-
III-D Gate Definitions . . . . . . . . . . . . 6 Specific Languages . . . . . 13
III-E Circuits . . . . . . . . . . . . . . . . . 6 B2 High-Level QPLs . . . . . . 13
III-F Measurement . . . . . . . . . . . . . . 6
B3 Low-Level Quantum Inter-
III-G Program Control . . . . . . . . . . . . 7 mediate Representations . . 14
III-H Zeroing the Quantum State . . . . . . 7
I. Introduction
III-I Classical/Quantum Synchronization . 7
The underlying hardware for quantum computing has
III-J Classical Instructions . . . . . . . . . 7 advanced rapidly in recent years. Superconducting chips
III-J1 Classical Unary Instructions 8 with 49 qubits have been demonstrated with the perfor-
mance required to run quantum simulation algorithms [1,
III-J2 Classical Binary Instructions 8 2, 3], quantum machine learning [4], and quantum error
III-K The No-Operation Instruction . . . . 8 correction benchmarks [5, 6, 7].
III-L File Inclusion Semantics . . . . . . . 8 Hybrid classical/quantum algorithmsincluding vari-
ational quantum eigensolvers [8, 9, 10], correlated mate-
III-M Pragma Support . . . . . . . . . . . . 8
rial simulations [11], and approximate optimization [12]
III-N The Standard Gates . . . . . . . . . . 9 have much promise in reducing the overhead required

Copyright
c 2016 Rigetti & Co., Inc.v2.0.20170217
The state of the QAM is specified by the following

Classical Data
elements:
Classical Computation Quantum Computation
A fixed but arbitrary number of qubits Nq indexed
from 0 to Nq 1. The k th qubit is written Qk . The
state of these qubits is written |i and is initialized
Fig. 1. A classical/quantum feedback loop. to |00 . . . 0i. The semantics of the qubits are described
in Section II-A.
A classical memory C of Nc bits, initialized to zero
for valuable applications. In machine learning and quan- and indexed from 0 to Nc 1. The k th bit is written
tum simulation, particularly for catalysts [13] and high- C[k].
temperature superconductivity [9], scalable quantum com- A fixed but arbitrary list of static gates G, and a fixed
puters promise performance unrivaled by classical super- but arbitrary list of parametric gates G0 . These terms
computers. are defined in Section III-C.
A fixed but arbitrary sequence of Quil instructions P .
The promise of hardware and applications must be These instructions will be described in Section III.
matched with advances in programming architectures. The An integer program counter 0 |P | indicating
demands of practical algorithm design, as well as the position of the next instruction to execute when 6=
shift to hybrid classical/quantum algorithms, necessitate |P | or a halted program when = |P |.
an update to the quantum Turing machine model [14].
We need new frameworks for quantum program compila- The 6-tuple (|i , C, G, G0 , P, ) summarizes the state of
tion [15, 16, 17, 18, 19] and emulation [20, 21]. For more the QAM.
details on prior work and its relationship to the topics
introduced here, we refer the reader to Appendix B. The QAM may be implemented either classically or on
quantum hardware. A classical implementation is called a
These classical/quantum algorithms require a classical Quantum Virtual Machine (QVM). We describe one
computer and quantum computer to communicate and such implementation in Section V-F. An implementation
work cooperatively, as in Figure 1. Within the presented on quantum hardware is called a Quantum Processing
framework, classical information is fed back via a defined Unit (QPU).
memory model, which can be implemented efficiently in
both hardware and software. The semantics of the quantum state and operations
on it are described in the language of tensor products of
In this paper, we describe an abstract machine which Hilbert spaces and linear maps between them. The follow-
serves as a model for hybrid classical/quantum computa- ing subsections give these semantics in meticulous detail.
tion. Alongside this, we describe an instruction language Readers with intuition about these topics are encouraged
for this machine called Quil and its suitability for program to skip to Section III for a description of Quil.
analysis and compilation. Together these form a quantum
instruction set architecture (ISA). Lastly, we give
various examples of algorithms in Quil, and discuss an A. Qubit Semantics
executable implementation.
A finite-dimensional Hilbert space over the complex
numbers C is denoted by H . The state space of a qubit is
II. The Quantum Abstract Machine a two-dimensional Hilbert space over C and is denoted by
B. Each of these Hilbert spaces is equipped with a chosen
Turing machines provide a vehicle for studying impor- orthonormal basis and indexing map on that basis. An
tant concepts in computer science such as complexity and indexing map is a bijective function that maps elements
computational equivalence. While theoretically important, of a finite set to the set of non-negative integers below
they do not provide a foundation for the construction ||, denoted [||]. For a Hilbert space spanned by {|ui , |vi}
of practical computing machines. Instead, specialized ab- with an indexing map defined by |ui 7 0 and |vi 7 1, we
stract machines are designed to accomplish real-world write |0i := |ui and |1i := |vi.
tasks, like arithmetic, efficiently while maintaining Turing
completeness. These machines are often specified in the In the context of the QAM, each qubit Qk in isolation
form of an instruction set architecture. Quantum Turing has a state space Bk spanned by an orthonormal basis
machines lie in the same vein as its classical counterpart, {|0ik , |1ik } called the computational basis. Since qubits
and we follow a similar approach in the creation of a can entangle, the state space of the system of all qubits is
practical quantum analog. not a direct product of each constituent space, but rather
a rightward tensor product
The Quantum Abstract Machine (QAM) is an ab-
stract representation of a general-purpose quantum com- Nq 1
O
puting device. It includes support for manipulating both |i H := BNq k1 . (1)
classical and quantum state. The QAM executes programs k=0
represented in a quantum instruction language called Quil,
which has well-defined semantics in the context of the The meaning of the tensor product is as follows. Let |pii be
QAM. the pth basis vector of Hi according to its indexing map.
The tensor product of two Hilbert spaces is then The controlled-X or controlled-not gate with control
n X o qubit Qj and target qubit Qk is defined as
Hi Hj := Cp,q |pii |qij : C Cdim Hi dim Hj .
1 0 0 0

p[dim Hi ]
| {z }
basis element
q[dim Hj ] 0 1 0 0
(2) CNOT := : Bj Bk Bj Bk .
0 0 0 1
The resulting basis elements are ordered by way of the 0 0 1 0
lexicographic indexing map
This gate is common for constructing entanglement in a
|pii |qij 7 q + p dim Hj . (3) quantum system.
Having the basis elements of the Hilbert space Hi domi- It turns out that many different sets of these one-
nate the indexing map is a convention due to the standard and two-qubit gates are sufficient for universal quantum
definition of the Kronecker product, in which for matrices computation, i.e., a discrete set of gates can be used
A and B, A B is a block matrix (A B)i,j = Ai,j B. to approximate any unitary matrix to arbitrary accu-
This convention, while standard, somewhat muddles the racy [22, 23]. In fact almost any two-qubit quantum gate
semantics below with busy-looking variable indexes which can be shown to be universal [24]. Delving into different
count down, not up. universal gate sets is beyond the scope of this work and
A basis element of H we refer the reader to [23] as a general reference.

|bNq 1 iNq 1 |b1 i1 |b0 i0 We now wish to provide a constructive method for
interpreting operators on a portion of a Hilbert space as
can be written shorthand in bit string notation operators on the Hilbert space itself. In the simplest case,
we have a one-qubit gate U acting on qubit Qk , which
|bNq 1 . . . b1 b0 i . induces an operator U on H by tensor-multiplying with
the identity map a total of Nq 1 times:
This has the particularly useful property that the bit string
corresponds to the binary representation of the index of = IN 1 U I1 I0 .
U (4)
q
that basis element. For clarity, however, we will not use
|{z}
th
(Nq k 1) position (zero-based)
this notation elsewhere in this paper.
Example 1. A two-qubit system in the Hilbert space B2 We refer to this process as lifting and reserve the tilde
B1 has the lexicographic indexing map defined by over the operator name to indicate such.
Example 3. Consider a system of four qubits and con-
|0i2 |0i1 7 0, |0i2 |1i1 7 1, sider a Hadamard gate acting on Q2 . Lifting this operator
|1i2 |0i1 7 2, |1i2 |1i1 7 3. according to (4) gives
The standard Bell state in this system is represented by the = I3 H I1 I0 .
H
element in the tensor space with the matrix
 
1 1 0 A two-qubit gate acting on adjacent Hilbert spaces is
C= .
2 0 1 just as simple. An operator U : Bk Bk1 Bk Bk1
is lifted as
Eqs. (1) and (2) imply that dim H = 2Nq , and as such, = IN 1 U I1 I0 .
U (5)
|i can be represented as a complex vector of that length. |
q
{z }
Nq 1 factors, U at position Nq k 1

B. Quantum Gate Semantics However, when the Hilbert spaces are not adjacent, lift-
The quantum state of the system evolves by applying a ing involves a bit more bookkeeping because there is no
sequence of operators called quantum gates. Most gener- obvious place to tensor-multiply the identity maps of the
ally, these are complex unitary matrices of size 2Nq 2Nq , Hilbert spaces indexed between j and k. We can resolve
written succinctly as U(2Nq ). However, quantum gates this by suitably rearranging the space. We need two tools:
are typically abbreviated as one- or two-qubit unitary a method to reorganize an operators action on a tensor
matrices, and go through a process of tensoring up before product of Hilbert spaces and isomorphisms between these
application to the quantum state. Hilbert spaces. The general principle to be employed is
to find some operator : H H which acts as a
Example 2. The Hadamard gate on Qk is defined as permutation operator on H , and to compute 1 U 0 ,
  where U 0 is isomorphic to U . Simply speaking, is a
1 1 1 temporary re-indexing of basis vectors and U 0 is just a
H := : Bk Bk .
2 1 1 trivial reinterpretation of U .
This is unitary because HH = Ik is the identity map on To reorganize, we use the fact that any permutation can
Bk . be decomposed into adjacent transpositions. For swapping
two qubits, consider the gate We end this section with an example of a universal
QAM.
1 0 0 0

0 0 1 0 Example 4. Define all possible liftings of U within H as
SWAPj,k := : Bj Bk Bj Bk . (6)
0 1 0 0
0 0 0 1 L(U ) := {U lifted for all qubit permutations}.
This is a permutation matrix which maps the basis ele- Define the gates S := ( 10 0i ) and T := 10 ei/4
0

. A QAM
ments according to with2
|0ij |1ik
7 |1ij |0ik
G = L(H) L(S) L(T) L(CNOT) and G0 = {}
|1ij |0ik 7 |0ij |1ik ,
and mapping the others identically. For adjacent transpo- can compute to arbitrary accuracy the action of any Nq -
sitions in the full Hilbert space, this can be trivially lifted: qubit gate, possibly with P exponential in length. See [23,
4.5] for details.
i := SWAPi,i+1 lifted by way of (5). (7)
We will use a sequence of these operators to arrange for C. Measurement Semantics
Bj and Bk to be adjacent by moving one of them next
to the other. There are two cases we need to be concerned Measurement is a surjective-only operation and is non-
about: j > k and j < k. deterministic. In the space of a single qubit Qk , there
are two outcomes to a measurement. The outcomes are
For the j > k case, we want to map the state of Bk to determined by lifting and applyingup to a scalar factor
Bj1 . This is accomplished with the operator1 either of the measurement operators3
j2
M0k := |0ik h0|k and M1k := |1ik h1|k
Y
j,k := j+ki2 ,
i=k
to the quantum state. These can be interpreted as projec-
where the product right-multiplies and is empty when k tions onto either of the basis elements of the Hilbert space.
j 1. More generally, in any finite Hilbert space H , we have the
For the j < k case, we want to map the state of Bj to set of measurement operators
Bk1 , and then swap Bk1 with Bk . We can do this with
M (H ) := |vi hv| : |vi basis H .

the operator succinctly:
0 In the QAM, when a qubit is measured, a particular
j,k := k1 k,j .
measurement operator is selected and applied according
Note the order of j and k in the factor. to the probability
Lastly, for the purpose of correctness, we need to
construct a trivial isomorphism P () := P (
is applied during meas.) = h| |i .
(10)
f : Bj Bk Bj Bj1 , (8) Upon selection of an operator, the quantum state trans-
forms according to
which is defined as the bijection between basis vectors with
the same index. 1
|i |i .
(11)
Now we may consider two-qubit gates in their full P ()
generality. Let U : Bj Bk Bj Bk be the gate under
This irreversible operation is called collapse of the wave-
consideration. Perform a change of coordinates on U to
function.
define
V := f U f 1 : Bj Bj1 Bj Bj1 , In quantum mechanics, measurement is much more
general than the description given above. In fact, any
and lift V to V : H H by way of (5). Then the lifted Hermitian operator can correspond to measurement. Such
U can be constructed as follows: operators are called observables, and the quantum state
(
1 of a system can be seen as a superposition of vectors in the
j,k V j,k if j > k, and observables eigenbasis. The eigenvalues of the observable
U= 0 1 0 (9)
(j,k ) V j,k if j < k. are the outcomes of the measurement, and the correspond-
ing eigenvectors are what the quantum state collapses to.
Since the operators are essentially compositions of invo- For additional details on measurement and its quantum
lutive SWAP gates, their inverses are just reversals. mechanical interpretation, we refer the interested reader
With care, the essence of this method generalizes to [23] and [25].
accordingly for gates acting on an arbitrary number of
qubits. 2 When the context is clear, G is sometimes abbreviated to just be
the set of unlifted gates, but it should be understood that its actually
1 This is an example of the effects of following the Kronecker every lifted combination. See Section III-C.
convention. This product is really just i in reverse. 3 In Dirac notation, hv| lies in the dual space of |vi.
III. Quil: a Quantum Instruction Language refers to a double-precision complex number a + ib where
a is the 64-bit interpretation of [x-(x + 63)], the first
Quil is an instruction-based language for represent- half of the segment, and b is the 64-bit interpretation of
ing quantum computations with classical feedback and [(x + 64)-(x + 127)], the second half of the segment. The
control. In its textual formatas presented belowit is use of these numbers can be found in Section III-C and
line-based and assembly-like. It can be written directly some practical consequences of their use can be found in
for the purpose of quantum programming, used as an Section IV-B2.
intermediate format within classical programs, or used as
a compilation target for quantum programming languages.
C. Static and Parametric Gates
Most importantly, however, Quil defines what can be done
with the QAM. Quil has support for: There are two gate-related concepts in the QAM: static
and parametric gates. A static gate is an operator in
Applying arbitrary quantum gates, U(2Nq ), and a parametric gate is a function4 Cn
Defining quantum gates as optionally parameterized U(2Nq ), where the n complex numbers are called param-
complex matrices, eters. The implication is that operators in G and G0 are
Defining quantum circuits as sequences of other always lifted to the Hilbert space of the QAM. This is a
gates and circuits, which can be bit- and qubit- formalism, however, and Quil abstracts away the necessity
parameterized, to be mindful of lifting gates.
Expanding quantum circuits,
Measuring qubits and recording the measurements In Quil, every gate is defined separately from its invoca-
into classical memory, tion. Each unlifted gate is identified by a symbolic name5 ,
Synchronizing execution of classical and quantum al- and is invoked with a fixed number of qubit arguments.
gorithms, The invocation of a static (resp. parametric) gate whose
Branching unconditionally or conditionally on the lifting is not a part of the QAMs G (resp. G0 ) is undefined.
value of bits in classical memory, and A static two-qubit gate named NAME acting on Q2 and
Including files as modular Quil libraries such as the Q5 , which is an operator lifted from B2 B5 , is written in
standard gate library (see Appendix A). Quil as the name of the gate followed by the qubit indexes
By virtue of being instruction-based, Quil code effects it acts on, as in
transitions of the QAM as a state machine. In the next
subsections, we will describe the various elements of Quil, NAME 2 5
using the syntax and conventions outlined in Section II. Example 5. The Bell state on qubits Q0 and Q1 can be
constructed with the following Quil code:
A. Classical Addresses and Qubits
H 0
The central atomic objects on which various operations CNOT 0 1
act are qubits, classical bits designated by an address, and
classical memory segments. A parametric three-qubit gate named PNAME with a
Qubit A qubit is referred to by its integer index. For single parameter ei/7 acting on Q1 , Q0 , and Q4 , which
example, Q5 is referred to by 5. is an operator lifted from B1 B0 B4 , is written in Quil
Classical memory address A classical memory ad- as
dress is referred to by an integer index in square
brackets. For example, the address 7 pointing to the PNAME(0.9009688679-0.4338837391i) 1 0 4
bit C[7] is referred to as [7].
Classical memory segment A classical memory seg- When a parametric gate is provided with a constant
ment is a contiguous range of addresses from a to parameter, one could either consider the resulting gate on
b inclusive with a b. These are written in square the specified qubits to be a part of G, or the parametric
brackets as well, with a hyphen separating the ranges gate itself on said qubits to be a part of G0 .
endpoints. For example, the bits between 0 and 63 are Parametric gates can take a dynamic parameter,
addressed by [0-63] and represent the concatenation as specified by a classical memory segment. Suppose a
of bits parameter is stored in [8-71]. Then we can invoke the
C[63]C[62] . . . C[1]C[0], aforementioned gate with that parameter via
written in the usual MSB-to-LSB order.
PNAME([8-71]) 1 0 4
B. Numerical Interpretation of Classical Memory Seg- In some cases, using dynamic parameters can be expensive
ments or infeasible, as discussed in Section IV-B2. Gates which
Classical memory segments can be interpreted as a use dynamic parameters are elements of G0 .
numerical value for the purpose of controlling parametric 4 Calling a parametric gate a gate is somewhat of a misnomer.
gates. In particular, a 64-bit classical memory segment The quantum gate is actually the image of a point in Cn .
refers to an IEEE-754 double-precision floating point num- 5 To be precise, the symbolic name actually represents the equiva-
ber [26]. A 128-bit classical memory segment [x-(x+127)] lence class of operators under all trivial isomorphisms, as in (8).
D. Gate Definitions With this, Example 5 is replicated by just a single line:
Static gates are defined by their real or complex matrix
BELL 0 1
entries in the basis described in Section II-A. Matrix en-
tries can be written literally with scientific E-notation (e.g.,
Similar to parametric gates, DEFCIRCUIT can optionally
real -1.2e2 or complex 0.3-4.1e-4i = 0.3 0.00041i), or
specify a list of parameters, specified as a comma-separated
built up from constant arithmetic expressions. These are:
list in parentheses following the circuit name, as the fol-
Simple arithmetic: addition +, subtraction/negation -, lowing example shows.
multiplication *, division /, exponentiation , Example 9. Using the x-y-z convention, an extrinsic
Constants: pi (= pi), i (= 1.0i), and Euler rotation by (, , ) of the state of qubit q on the
Functions: sin, cos, sqrt, exp, cis6 . Bloch sphere is codified by the following circuit:
The gate is declared using the DEFGATE directive followed
by comma-separated lists of matrix entries indented by DEFCIRCUIT EULER(%alpha, %beta, %gamma) q:
exactly four spaces. Matrices that are not unitary (up to RX(%alpha) q
noise or precision) have undefined7 execution semantics. RY(%beta) q
RZ(%gamma) q
Example 6. The Hadamard gate can be defined by
Within circuits, labels are renamed uniquely per expan-
DEFGATE HADAMARD: sion. As a consequence, it is possible to expand the same
1/sqrt(2), 1/sqrt(2) circuit multiple times, but it is not possible to jump into
1/sqrt(2), -1/sqrt(2) a circuit.

This gate is included in the collection of standard gates, but Circuits are intended to be used more as macros than
under the name H. as specifications for general quantum circuits. Indeed,
DEFCIRCUIT is very limited in its expressiveness, only
performing argument and parameter substitution. It is
Parametric gates are the same, except for the allowance
included mainly to help with the debugging and human
of formal parameters, which are names prepended with a
readability of Quil code. More advanced constructs are
% symbol. Comma-separated formal parameters are listed
intended to be written on top of Quil, as in Section V-B.
in parentheses following the gate name, as is usual.
Example 7. The rotation gate Rx can be defined by F. Measurement

DEFGATE RX(%theta): Measurement provides the side effects of quantum


cos(%theta/2), -i*sin(%theta/2) programming, and is an essential part of most prac-
-i*sin(%theta/2), cos(%theta/2) tical quantum algorithms (e.g., phase estimation and
teleportation). Quil provides two forms of measurement:
measurement-for-effect, and measurement-for-record.
This gate is also included in the collection of standard gates.
Measurement-for-effect is a measurement performed on
Defining several gates or circuits with the same name a single qubit used solely for changing the state of the
is undefined. quantum system. This is done with a MEASURE instruction
of a single argument. Performing a measurement on Q5 is
E. Circuits written as
Sometimes it is convenient to name and parameterize MEASURE 5
a particular sequence of Quil instructions for use as a
subroutine to other quantum programs. This can be done More useful, however, is measurement-for-record.
with the DEFCIRCUIT directive. Similar to the DEFGATE Measurement-for-record is a measurement performed
directive, the body of a circuit definition must be indented and recorded in classical memory. This form of the
exactly four spaces. Critically, it specifies a list of formal MEASURE instruction takes two arguments, the qubit and
arguments which can be substituted with either classical the classical memory address. To measure Q7 and deposit
addresses or qubits. the result at address 8 is written
Example 8. In example 5, we constructed a Bell state on
Q0 and Q1 . We can generalize this for arbitrary qubits Qm MEASURE 7 [8]
and Qn by defining a circuit.
The semantics of the measurement operation are described
DEFCIRCUIT BELL Qm Qn: in Section II-C.
H Qm Example 10. Producing a random number between 0 and
CNOT Qm Qn 3 inclusive can be accomplished with the following program:
6 cis
:= cos + i sin = exp i
7 Software processing Quil is encouraged to warn or error on such H 0
matrices. H 1
MEASURE 0 [0] Example 12. Consider the following two DEFCIRCUIT
MEASURE 1 [1] declarations and their instantiations. Note the comments
on correct and incorrect usages of JUMP.
The memory segment [0-1] is now representative of the
number in binary. DEFCIRCUIT FOO:
LABEL @FOO_A
G. Program Control JUMP @GLOBAL # valid, global label
JUMP @FOO_A # valid, local to FOO
Program control is determined by the state of the JUMP @BAR_A # invalid
program counter. The program counter determines if the
program has halted, and if not, it determines the location DEFCIRCUIT BAR:
of the next instruction to be executed. Every instruction, LABEL @BAR_A
except for the following, has the effect of incrementing . JUMP @FOO_A # invalid
The exceptions are:
Conditional and unconditional jumps. LABEL @GLOBAL
The halt instruction HALT which terminates execution FOO
and assigns |P |. BAR
The last instruction in the program, whichafter its JUMP @FOO_A # invalid
executionimplicitly terminates execution as if by JUMP @BAR_A # invalid
HALT.
Locations within the instruction sequence are denoted by H. Zeroing the Quantum State
labels, which are names that are prepended with an @
symbol, like @start. The declaration of a new label within The quantum state of the QAM can be reset to the
the instruction sequence is called a jump target, and is zero state with the RESET instruction. This has the effect
written with the LABEL directive. of setting
Nq 1
O
Unconditional jumps are executed by the JUMP instruc- |i |0iNq k1 .
tion which sets to the index of a given jump target. k=0

Conditional jumps are executed by the JUMP-WHEN There are no provisions to clear the state of a single qubit,
(resp. JUMP-UNLESS) instruction, which set to the index but we can do this by taking advantage of projective
of a given jump target if the bit at a classical memory measurement.
address is 1 (resp. 0), and to + 1 otherwise. This is a
Example 13. We can clear a qubit using a single bit of
critical and differentiating element of Quil; it allows fast
classical scratch space.
classical feedback.
Example 11. Consider the following C-like pseudocode of DEFCIRCUIT CLEAR q scratch_bit:
an if-statement branching on the bit contained at address MEASURE q scratch_bit
x: JUMP-UNLESS @end scratch_bit
X q
if (*x) { LABEL @end
// instrA...
} else { I. Classical/Quantum Synchronization
// instrB...
} Some classical/quantum programs can be constructed
in a way such that at a certain point of a quantum
This can be translated into Quil in the following way: program, execution must be suspended until some classical
computations are performed and corresponding classical
JUMP-WHEN @THEN [x] state is modified. This is accomplished using the WAIT
# instrB... instruction, a synchronization primitive which signals to
JUMP @END the classical computer that computation will not continue
LABEL @THEN until some condition is satisfied. WAIT takes no arguments.
# instrA... The mechanism by which WAIT works is deliberately
LABEL @END unspecified. Some example mechanisms include monitors
and interrupts, depending on the QAM implementation.
Lines starting with the # character are comments and are An example use of WAIT can be found in Section IV-B2.
ignored.
J. Classical Instructions
Labels that are declared within the body of a
DEFCIRCUIT are unique to that circuit. While it is possible Quil is intended to be a language to manipulate quan-
to jump out of a DEFCIRCUIT to a globally declared label, tum state using quantum operations and classical control.
it is not possible to jump inside of one. Classical computation on the classical state should be
done as much as possible with a classical computer, and force a break in instruction parallelization, described in
using Quils classical/quantum synchronization to mediate Section V-E.
the hand-off of classical data between the classical and
quantum processors. However, a few instructions for ma- L. File Inclusion Semantics
nipulating the classical state are provided for convenience,
with emphasis on making control flow easier. File inclusion is done via the INCLUDE directive. For
example, the library of standard gatesdescribed in Ap-
1) Classical Unary Instructions: The classical unary pendix Acan be included with
instructions are instructions that take a single classical
address as an argument and modify the bit at that address INCLUDE "stdgates.quil"
accordingly. In each of the following, let a be the address
provided as the sole argument. The three instructions are: File inclusion is not simple token substitution as it is in
languages like the C preprocessor. Instead, the included
Constant False FALSE, which has the effect C[a] 0;
file is parsed into a set of circuit definitions, gate defini-
Constant True TRUE, which has the effect C[a] 1; and
tions, and instruction code. Instruction code is substituted
Negation NOT, which has the effect C[a] 1 C[a].
verbatim, but definitions will be recorded as if they were
2) Classical Binary Instructions: The classical binary originally placed at the top of the file.
instructions are instructions that take two classical ad- Generally, best practice is to include files containing
dresses as arguments, and modify the bits at those ad- only contain gate or circuit definitions (in which case the
dresses accordingly. In all of the following, let a be the file is called a library), or only executable code, and not
first address and b be the second address provided as both. However, this is not enforced.
arguments. The four instructions are:
Conjunction AND, which has the effect C[b] C[a]C[b]; M. Pragma Support
Disjunction OR, which has the effect Programs that process Quil code may want to take
C[b] 1 (1 C[a])(1 C[b]); advantage of extra information provided by the program-
mer. This is especially true when targeting QPUs where
Copy MOVE, which has the effect C[b] C[a]; and additional information about the machines characteristics
Exchange EXCHANGE, which has the effect of swapping the affect how the program will be processed. Quil supports a
bits at a and b: C[a] C[b]. PRAGMA directive to include extra information in a program
which does not otherwise affect execution semantics. The
Example 14. Exclusive disjunction r a + b mod 2 can
syntax of PRAGMA is as follows:
be implemented with the following circuit:
PRAGMA <identifier>+ <string>?
DEFCIRCUIT XOR a b r:
# Uses (a | b) & (a | b)
MOVE b r where + indicates one or more instances and ? indicates
OR a r # r = a | b zero or one instance.
JUMP-UNLESS @end r # short-circuit Example 15. The QAM does not have any notion of
MOVE b r instruction parallelism, but programs are generally par-
NOT a allelized before execution on a QPU. (See Section V-E.)
NOT r Programs processing Quil may wish to enforce boundaries
OR a r # r = a | b across which parallelization may not occur. An implemen-
NOT a # undo change to a tation may opt to support a parallelization barrier pragma.
LABEL @end Despite the fact that the X-gates below are commuting, an
implementation may opt to treat the instructions sequen-
Note that r has to be distinct from a and b. tially.

K. The No-Operation Instruction X 0


PRAGMA parallelization_barrier
The no-operation, no-op, or NOP instruction does X 1
not affect the state of the QAM except in the way de-
scribed in Section III-G, i.e., by incrementing the program
Note that this does not change the semantics of Quil vis-`
a-
counter. This instruction may appear useless, especially on
vis the QAM.
a machine with no notion of alignment or dynamic jumps.
However, it has purpose when the QAM is used as the Example 16. On modern superconducting qubit architec-
foundation for hardware emulation. For example, consider tures, applications of different gates take different times.
a QAM with some associated gate noise model. If one This can affect how instructions get scheduled for execution.
were to use an identity gate in place of a no-op, then the Programs processing Quil may wish to allow the physical
identity gate would be interpreted as noisy while the no-op time it takes to perform a gate to be defined with a pragma,
would not. Moreover, the no-op has no qubit dependencies, like so:
which would otherwise affect program analysis. Rigetti
Computing has used the no-op instruction as a way to PRAGMA gate_time H "50 ns"
PRAGMA gate_time CNOT "150 ns" for i in range(1, n):
H 0 q = l + n - i
CNOT 0 1 alpha = pi / 2 ** (n - i)
:: CPHASE(alpha) l q
N. The Standard Gates :: H l
Quil provides a collection of standard one-, two-, The bit reversal routine can be implemented straightfor-
and three-qubit gates, which are fully defined in Ap- wardly as exactly bNq /2c SWAP gates.
pendix A. The standard gates can be used by including
stdgates.quil. def revbin(Nq):
for i in range(Nq / 2):
IV. Quil Examples :: SWAP i (Nq - i - 1)
A. Quantum Fourier Transform
All of this is put together in a final QFT routine.
In the context of the QAMs quantum state |i H ,
the quantum Fourier transform (QFT) [23, 5.1] is a def QFT(Nq):
unitary operator F : H H defined by the matrix QFT(0, Nq)
1 revbin(Nq)
Fj,k := jk , 0 j, k < dim H = 2Nq (12)
2Nq
B. Variational Quantum Eigensolver
with := exp(2i/2Nq ) the complex primitive root of
unity. It can be shown that this operator acts on the basis The variational quantum eigensolver (VQE) [8, 9, 10]
vectors (up to permutation) via the map is a classical/quantum algorithm for finding eigenvalues of
a Hamiltonian H variationally. The quantum subroutine
Nq 1 Nq 1
O 1 O has two fundamental steps.
|bk0 ik0 7 [|0ik + (k) |1ik ] , (13)
k=0 2Nq k=0
~
1) Prepare the quantum state |()i, often called the
k0 :=Nq k1 ansatz.
k
Y ~ | H | ()
2) Measure the expectation value h () ~ i.
exp 2ibNq j1 /2j+1 .

where (k) =
j=0
The classical portion of the computation is an optimization
loop.
Here, b is the bit string representation of the basis vectors,
as in Section II-A. 1) Use a classical non-linear optimizer to minimize the
~
expectation value by varying ansatz parameters .
The first thing to notice is that the basis elements get
2) Iterate until convergence.
reversed in this factorization. This is easily fixed via a
product of SWAP gates. In the context of classical fast We refer to given references for details on the algorithm.
Fourier transforms [27], this is called bit reversal.
Practically, the quantum subroutine of VQE amounts
The second and more
N important thing to notice is that to preparing a state based off of a set of parameters ~ and
each factor of the can be seen as an operation on performing a series of measurements in the appropriate
the qubit Qk . The factors of (k) indicate the operations basis. Using the QAM, these measurements will end up
are two-qubit controlled-phase or CPHASE gates with Qk in classical memory. Doing this iteratively followed by a
as the target, and each previous qubit as the control. In small amount of postprocessing, one may compute a real
the degenerate one-qubit case, this is a Hadamard gate. expectation value for the classical optimizer to use.
Further details on this algorithm can be found in [23].
This algorithm can be implemented in at least two
The core QFT logic can be implemented as a straight- distinct styles which impose different requirements on a
forward recursive function QFT. We write it as one which quantum computer. These two styles can serve as proto-
transforms qubits Qk for l k < r. The base case is the typical examples for programming a QAM with Quil.
action on a single qubita Hadamard. In the general case,
we do a sequence of CPHASE gates targeted on the current 1) Static Implementation: One simple implementation
qubit Ql and controlled by all qubits before it, topped off of VQE is to generate a new Quil listing for every iteration
by a Hadamard. In the Python-like pseudocode below, we ~ Before calling out to the quantum subroutine, a new
of .
generate Quil code for this algorithm. We prepend lines of Quil program is generated for the next desired ~ and loaded
Quil code to be generated with two colons ::. onto the quantum computer for immediate execution. For
a parameter = 0.00724 . . ., one such program might look
def QFT(l, r): like
n = r - l # num qubits
if n == 1: # base case # State prep
:: H l ...
else: # general case CNOT 5 6
QFT(l + 1, r) CNOT 6 7
RZ(0.00724195969993) 7
CNOT 6 7
...
# Measurements
MEASURE 0 [0]
MEASURE 1 [1]
...

This technique poses no issue from the perspective of


coherence time, but adds a time penalty to each iteration
of the classical optimizer.
A static implementation of VQE was written using
Rigetti Computings pyQuil library and the Rigetti QVM,
both of which are mentioned in Sections V-B and V-F
respectively.
2) Dynamic Implementation: Perhaps the most encap-
sulated implementation of VQE would be to use dynamic
parameters. Without loss of generality, lets assume a
single parameter . We can define a circuit which takes
our single parameter and prepares |i. Fig. 2. Outline of Forest, Rigetti Computings quantum program-
ming toolkit, described in Section V.
DEFCIRCUIT PREP_STATE(%theta):
...
H 3 optimization and poses particular issues for current quan-
H 5 tum computing architectures which have limited natural
... gate sets and limited high-speed dynamic tune-up of new
CNOT 3 5 gates or their approximations.
CNOT 5 6
RZ(%theta) 6
... V. Forest: A Quantum Programming Toolkit
Next, we define a memory layout for classical/quantum A. Overview
communication:
Quantum computers, and specifically QAM-conforming
[0]: Flag to indicate convergence completion. QPUs, are not yet widely available. Despite this, software
[1-64]: Dynamic parameter . can make use of the the QAM and Quil to (a) study
[100], [101], . . . : Measurements corresponding to practical quantum algorithmic performance in a spirit
Q0 , Q1 , . . . . similar to MMIX [28], (b) prepare a suite of software
Finally, we can define our VQE circuit. which will be able to be run on QPUs, and (c) provide
a uniform interface to physical and virtualized QAMs.
DEFCIRCUIT VQE: Rigetti Computing has built a toolkit called Forest for
LABEL @REDO accomplishing these tasks.
RESET The hierarchy of software roughly falls into four layers,
PREP_STATE([1-64]) # Dynamic Parameter as in figure 2. Descending in abstraction, we have
MEASURE 0 [100]
MEASURE 1 [101]
Applications & Tools Software written to accomplish
...
real-world tasks (e.g., study electronic structure prob-
WAIT
lems), and software to assist quantum programming.
JUMP-UNLESS @REDO [0]
Quil The language described in this document and asso-
ciated software for processing Quil. It acts as an inter-
This program has the advantage that the quantum mediate representation of general quantum programs.
portion of the algorithm is completely encapsulated. It is Compiler Software to convert arbitrary Quil to simpler
not necessary to dynamically reload Quil code for each Quil (or some other representation) for execution on
newly varied parameter. a QPU or QVM.
The main disadvantage of this approach is its im- Execution Units A QPU, a QVM, or a hardware emu-
plementation difficulty in hardware. This is because of lator. Software written at this level will typically in-
the diminished potential for program analysis to occur corporate noise models intrinsic to a particular QPU.
before execution. The actual gates that get applied will
not be known until the runtime of the algorithm (hence We will briefly describe each of these components of the
the dynamic name). This may limit opportunities for toolkit in the following sections.
B. Applications and Tools decomposed into control flow graphs (CFGs) [32] whose
nodes are basic blocks of straight-line Quil instructions, as
Quil is an assembly-like language that is intended to
is typical in compiler theory. Arrows between basic blocks
be both human readable and writable. However, more
indicate transfers of control. For example, consider the
expressive power comes from being able to manipulate
following Quil program:
Quil programs programmatically. Rigetti Computing has
developed a Python library called pyQuil [29] which allows
the construction of Quil programs by treating them as first- LABEL @START
class objects. Using pyQuil along with scientific libraries H 0
such SciPy [30], Rigetti Computing has implemented non- MEASURE 0 [0]
trivial algorithms such as VQE using the abstractions of JUMP-WHEN @END [0]
the QAM. H 0
H 1
C. Quil Manipulation CNOT 1 0
JUMP @START
Quil, as a language in its own right, is amenable LABEL @END
to processing and computation independent of any par- Y 0
ticular (real or virtual) machine for execution. Rigetti MEASURE 0 [0]
Computing has written a reusable static analyzer and MEASURE 1 [1]
parser application for Quil, that allows Quil to easily
be interchanged between programs. For example, Rigetti Roughly speaking, each segment of straight-line control
Computings quil-json program converts Quil into a makes up a basic block. Figure 3 depicts the control flow
structured JSON [31] format: graph of this program, with jump instructions elided.

$ cat bell.quil
H 0
CNOT 0 1 *ENTRY-BLK-793*
$ quil-json bell.quil
{
"type": "parsed_program", *START795*
"executable_program": [ H 0
MEASURE 0 [0]
{
"type": "unresolved_application",
"operator": "H", *BLK-796* *END798*
"arguments": [["qubit", 0]], H 0 Y 0
H 1 MEASURE 0 [0]
"parameters": null CNOT 1 0 MEASURE 1 [1]
},
{
"type": "unresolved_application", *EXIT-BLK-794*
"operator": "CNOT",
"arguments": [["qubit", 0],
["qubit", 1]],
"parameters": null Fig. 3. The control flow graph of a Quil program.
}
] Many of these basic blocks will be composed of gates
} and measurements, which themselves can be symbolically
and algebraically manipulated. Gates can go through
Note the two instances of unresolved application. approximation to reduce a general set of gates to a
These were generated because of a simple static analysis sequence of gates native to the particular architecture, and
determining that these gates were not otherwise defined then routing so that these simpler gates are arranged
in the Quil file. (This could be ameliorated by including to act on neighboring qubits in a physical architecture.
stdgates.quil.) Another example of a transformation on basic blocks is
parallelization, talked about in the next section.
D. Compilation
Both approximation and routing can be formalized
In the context of quantum computation, compilation as transformations between QAMs. In this first example,
is the process of converting a sequence of gates into an we show how we can formally describe a transformation
approximately equivalent sequence of gates executable on between a QAM to another one with a smaller but com-
a quantum computer with a particular qubit topology. This putationally equivalent gate set.
requires two separate kinds of processing: gate approxima-
tion and routing. Example 17 (Compiling). Let M = (|i , C, GM , G0 , P, )
be a one-qubit QAM with
Since Quil is specified as a symbolic language, it is
amenable to symbolic analysis. Quil programs can be GM = {H, Rx (), Rz ()}
for some fixed R, and let M0 be a QAM with In general, parallelization cannot occur over jumps, resets,
waits, and measurements and dynamic gate applications
GM0 = {H, Rz ()}. with overlapping address ranges. We suggest that NOP is
Because Rx = HRz H, we can define a compilation function used as a way to force a parallelization break.
M 7 M0 specifically transforming8 P according to If a control flow graph is constructed as in Section V-D,
 then parallelization can be done over each basic block. A
(H, Rz (), H) if = Rx (),
f () = parallelized basic block is called a parallelization sched-
() otherwise. ule. See Figure 4 for an example of quantum parallelization
within a CFG.
In this next example, we show how qubit connectivity
can be encoded in a QAM, and how one can route instruc-
tions to give the illusion of a fully connected topology.
*ENTRY-BLK-799*
Example 18 (Routing). Let M = (|i , C, GM , G0 , P, )
be a three-qubit QAM with
GM = L(H) L(CNOT) L(SWAP), *START801*
{
H 0
where L was defined in Example 4. Consider a three-qubit }
QPU with the qubits arranged in a line {
MEASURE 0 [0]
}
Q0 Q1 Q2
so that two-qubit gates can only be applied on adjacent
*BLK-802* *END804*
qubits. Then this QPU can be modeled by another three- { {
qubit QAM M0 with the lifted gates H 0 Y 0
H 1 MEASURE 1 [1]
(
H0 , H1 , H2 ,
) } }
{ {
GM0 = CNOT01 , CNOT10 , CNOT12 , CNOT21 , . CNOT 1 0 MEASURE 0 [0]
SWAP01 , SWAP12 } }

Because of the qubit topology, there are no gates that act


on B2 B0 . However, we can reason about transforming *EXIT-BLK-800*
between M and M0 in either direction. We can transform
from M to M0 by way of a transformation f similar to that
in the last example, namely
Fig. 4. The parallelized version of Figure 3. Instruction sequences
(SWAP01 , SWAP12 , SWAP01 ) if = SWAP02 , which can be executed in parallel are surrounded in curly braces {}.

(SWAP01 , CNOT12 , SWAP01 ) if = CNOT02 ,

f () =

(SWAP01 , CNOT21 , SWAP01 ) if = CNOT20 ,

() otherwise. F. Rigetti Quantum Virtual Machine

Similarly, we can transform from M0 to M by adding three Rigetti Computing has implemented a QVM in ANSI
additional gates to GM0 , namely those implied by f . Common Lisp [34] called the Rigetti QVM. It is a high-
performance9 , programmable simulator for the QAM and
emulator for noisy quantum computers. The Rigetti QVM
Many other classes of useful transformations on QAMs
exposes two interfaces for executing quantum programs:
exist, such as G-preserving algebraic simplifications of P ,
execution of Quil files directly with POSIX-style shared
an analog of peephole optimization in compiler theory [33].
memory (local execution), and execution of Quil from
HTTP server requests (remote execution).
E. Instruction Parallelism
Local execution is useful for high-speed testing of
Instruction parallelism, the ability to apply com- small-to-medium sized instances of classical/quantum al-
muting operations to a quantum state in parallel, is one gorithms. It also provides convenient ways of debugging
of the many benefits of quantum computation. Quil code quantum programs, such as allowing direct inspection of
as written is linear and serial, but can be interpreted the quantum state at any point in the execution process, as
as an instruction-parallel program. In particular, many well as limited quantum hardware emulation with tunable
subsequences of Quil instructions may be executed in noise models.
parallel. Such sequences include:
Remote execution is used for distributed, cloud access
Commuting gate applications and measurements, and to QVM instances. HTTP libraries exist in nearly all
Measurements with non-overlapping memory ad- modern programming languages, and allow programs in
dresses.
9 The Rigetti QVM has optimized vectorized and parallelized nu-
8 Inthe parlance of functional programming, f is applied to P via merics, and has no theoretical limit for the number of qubits it can
a concatmap operation. simulate. It has been demonstrated to simulate 36 qubits.
these languages to make connections. Rigetti Computing Swap Gates
has built in to pyQuil the ability to send the first-class 1 0 0 0
Quil program objects to a local or secured remote Rigetti PSWAP() = 0 0 ei 0
QVM instance using the Forest API. 0 ei 0 0
0 0 0 1
SWAP = PSWAP(0)
VI. Conclusion ISWAP = PSWAP(/2)
We have introduced a practical abstract machine for 1 0 0 0 0 0 0 0
01000000
reasoning about and executing quantum programs. Fur- 0 0 1 0 0 0 0 0
thermore, we have described a notation for such programs CSWAP = 00 00 00 10 01 00 00 00
00000010
on this machine, which is amenable to analysis, compila- 00000100
tion, and execution. Finally, we have described a pragmatic 00000001

toolkit for quantum program construction and execution


built atop these ideas. B. Prior Work
There exists much literature on abstract models, syn-
VII. Acknowledgements taxes, and semantics of quantum computing. Most of
The authors would like to thank their colleagues at them are in the form of quantum programming languages
Rigetti Computing for their support, especially Nick Ru- (QPLs) and simulators, which achieve various levels of ex-
bin. We are also grateful to Erik Davis, Jarrod McClean, pressiveness. Languages roughly fall into three categories:
Bill Millar, and Eric Peterson for their helpful discussions
and valuable suggestions provided throughout the devel- embedded domain-specific languages,
opment of this work. high-level quantum programming languages, and
low-level quantum intermediate representations.
Appendix In addition, work has been done on designing larger tool
A. The Standard Gate Set chains for quantum programming [18, 19, 36].
The following static and parametric gates are defined In the following subsections, we provide a non-
in stdgates.quil. Many of these gates are standard gates exhaustive account of some previous work within the above
used in theoretical quantum computation [23], and some categories, and describe how they relate to the design of
of them find their origin in the theory of superconducting our quantum ISA.
qubits [35].
1) Embedded Domain-Specific Languages: An embed-
Pauli Gates ded domain-specific language (EDSL) is a language
to express concepts and problems from within another
0 i
 1 0

I = ( 10 01 ) X = ( 01 10 ) Y= i 0 Z= 0 1 programming language. Within the context of quantum
Hadamard Gate programming, two prominent examples are Quipper [16],
which is embedded in Haskell [37], and LIQU i|i [15],
1 1 1

H= 2 1 1 which is embedded in F# [38]. Representation of quantum
programs (and, in particular, the subclass of quantum
Phase Gates programs called quantum circuits) is expressed with data
PHASE() = 1 0

S = PHASE(/2) T = PHASE(/4) structures in the host language. Feedback of classical
0 ei
information is achieved through an interface with the host
Controlled-Phase Gates language.
CPHASE00() = diag(ei , 1, 1, 1) Quantum programs written in an EDSL are not directly
CPHASE01() = diag(1, e , 1, 1) i executable on a quantum computer, due to the require-
ment of being present in the host languages runtime.
CPHASE10() = diag(1, 1, ei , 1) However, since quantum programs are represented as first-
CPHASE() = diag(1, 1, 1, ei ) class objects, these objects are amenable to processing and
compilation to a quantum computers natively executable
Cartesian Rotation Gates instruction set. Quil is one such target for compilation.
cos i sin
 
RX() = i sin2 cos 2 2) High-Level QPLs: High-level QPLs are the quantum
 2 2 analog of languages like C [39] in the imperative case or
cos sin
RY() = sin 2 cos 2 ML [40] in the functional case. They provide a plethora of
2 2
classical and quantum data types, as well as control flow
 i/2 
RZ() = e 0
i/2
0 e constructs. In the case of functional quantum languages,
Controlled-X Gates the lambda calculus for quantum computation with classi-
1 0 0 0 0 0 0 0 cal control by Selinger and Valiron can act as a theoretical
1 0 0 0 01000000 basis for their semantics of such a language10 [42].
0100 0 0 1 0 0 0 0 0
CNOT = 0001 CCNOT = 00 00 00 10 01 00 00 00 10 This is similar to how the classical untyped lambda calculus
0010 00000100
00000001 formed the basis for LISP in 1958 [41].
00000010
One prominent example of a high-level QPL is Bern- nov, Universal quantum simulation with prethresh-

hard Omers QCL [43]. It is a C-like language with clas- old superconducting qubits: Single-excitation sub-
sical control and quantum data. Among the many that space method, Physical Review A, vol. 91, no. 6, p.
exist, two importantand indeed somewhat dualdata 062309, 2015.
types are int and qureg. The following example shows [3] R. Barends, A. Shabani, L. Lamata, J. Kelly, A. Mez-
a Hadamard initialization on eight qubits, and measuring zacapo, U. Las Heras, R. Babbush, A. Fowler,
the first four of those qubits into an integer variable. B. Campbell, Y. Chen et al., Digitized adiabatic
quantum computing with a superconducting circuit,
// Allocate classical and quantum data Nature, vol. 534, no. 7606, pp. 222226, 2016.
qureg q[8]; [4] D. Riste, M. P. da Silva, C. A. Ryan, A. W. Cross,
int m; J. A. Smolin, J. M. Gambetta, J. M. Chow, and B. R.
// Hadamard initialize Johnson, Demonstration of quantum advantage in
H(q); machine learning, arXiv preprint arXiv:1512.06069,
// Measure four qubits into m 2015.
measure q[0..3], m; [5] J. M. Chow, S. J. Srinivasan, E. Magesan, A. Corcoles,
// Print m, which will be anywhere from 0 to 15. D. W. Abraham, J. M. Gambetta, and M. Steffen,
print m; Characterizing a four-qubit planar lattice for arbi-
trary error detection, in SPIE Sensing Technology+

Omer defines the semantics of this language in detail in Applications. International Society for Optics and
his PhD thesis, and presents an implementation of a QCL Photonics, 2015, pp. 95 001G95 001G.
interpreter written in C++ [44]. However, a compilation or [6] J. Kelly, R. Barends, A. Fowler, A. Megrant, E. Jef-
execution strategy on quantum hardware is not presented. frey, T. White, D. Sank, J. Mutus, B. Campbell,
Similar to EDSLs, QPLs such as QCL can be compiled Y. Chen et al., State preservation by repetitive er-
into a lower-level quantum instruction set such as Quil. ror detection in a superconducting quantum circuit,
Nature, vol. 519, no. 7541, pp. 6669, 2015.
3) Low-Level Quantum Intermediate Representations: [7] D. Rist`e, S. Poletto, M.-Z. Huang, A. Bruno,
In the context of compiler theory, an intermediate rep- V. Vesterinen, O.-P. Saira, and L. DiCarlo, Detect-
resentation (IR) is some representation of a language ing bit-flip errors in a logical qubit using stabilizer
which is amenable to further processing. IR can be higher measurements, Nature communications, vol. 6, 2015.
level (as with abstract syntax trees), or lower level (as [8] A. Peruzzo, J. McClean, P. Shadbolt, M.-H. Yung,
with linear bytecodes). Low-level IRs often act as compila- X.-Q. Zhou, P. J. Love, A. Aspuru-Guzik, and J. L.
tion targets for classical programming languages, and are OBrien, A variational eigenvalue solver on a pho-
used for analysis and program optimization. For example, tonic quantum processor, Nature communications,
LLVM IR [45] is used as an intermediate compilation target vol. 5, 2014.
for the Clang C compiler [46]. [9] D. Wecker, M. B. Hastings, and M. Troyer, Progress
The most well-known example of a low-level quantum towards practical quantum variational algorithms,
IR is QASM [47]. This was originally a language to describe Physical Review A, vol. 92, no. 4, p. 042303, 2015.
the quantum circuits for LATEX output in [23], and hence, [10] J. R. McClean, J. Romero, R. Babbush, and
not an IR in that form. However, the syntax was adapted A. Aspuru-Guzik, The theory of variational hy-
for executable use in [48]. QASM, however, does not have brid quantum-classical algorithms, New Journal of
any notion of classical control within the language, acting Physics, vol. 18, no. 2, p. 023023, 2016.
solely as a quantum circuit description language. [11] B. Bauer, D. Wecker, A. J. Millis, M. B. Hast-
ings, and M. Troyer, Hybrid quantum-classical
Quil is considered a low-level quantum IR with classical approach to correlated materials, arXiv preprint
control. arXiv:1510.03859, 2015.
[12] E. Farhi, J. Goldstone, and S. Gutmann, A quantum
References approximate optimization algorithm, arXiv preprint
arXiv:1411.4028, 2014.
[1] P. J. J. OMalley, R. Babbush, I. D. Kivlichan, [13] M. Reiher, N. Wiebe, K. M. Svore, D. Wecker, and
J. Romero, J. R. McClean, R. Barends, J. Kelly, M. Troyer, Elucidating reaction mechanisms
P. Roushan, A. Tranter, N. Ding, B. Campbell, on quantum computers, arXiv preprint
Y. Chen, Z. Chen, B. Chiaro, A. Dunsworth, arXiv:1605.03590, 2016.
A. G. Fowler, E. Jeffrey, E. Lucero, A. Megrant, [14] D. Deutsch, Quantum Theory, the ChurchTuring
J. Y. Mutus, M. Neeley, C. Neill, C. Quintana, Principle and the Universal Quantum Computer,
D. Sank, A. Vainsencher, J. Wenner, T. C. White, Proceedings of the Royal Society of London A: Mathe-
P. V. Coveney, P. J. Love, H. Neven, A. Aspuru- matical, Physical and Engineering Sciences, vol. 400,
Guzik, and J. M. Martinis, Scalable quantum no. 1818, pp. 97117, 1985.
simulation of molecular energies, Phys. Rev. X, [15] D. Wecker and K. M. Svore, LIQUi|i: A Software
vol. 6, p. 031007, Jul 2016. [Online]. Available: Design Architecture and Domain-Specific Language
http://link.aps.org/doi/10.1103/PhysRevX.6.031007 for Quantum Computing, 2014. [Online]. Available:
[2] M. R. Geller, J. M. Martinis, A. T. Sornborger, P. C. arXiv:1402.4467v1
Stancil, E. J. Pritchett, H. You, and A. Galiautdi- [16] A. S. Green, P. L. Lumsdaine, N. J. Ross, P. Selinger,
and B. Valiron, Quipper: A scalable quantum Commun. ACM, vol. 8, no. 7, pp. 443444,
programming language, SIGPLAN Not., vol. 48, Jul. 1965. [Online]. Available: http://doi.acm.org/
no. 6, pp. 333342, Jun. 2013. [Online]. Available: 10.1145/364995.365000
http://doi.acm.org/10.1145/2499370.2462177 [34] American National Standards Institute and Informa-
[17] T. H aner, D. S. Steiger, K. Svore, and M. Troyer, tion Technology Industry Council, American National
A software methodology for compiling quantum pro- Standard for Information Technology: programming
grams, arXiv preprint arXiv:1604.01401, 2016. language Common LISP, American National Stan-
[18] K. M. Svore, A. V. Aho, A. W. Cross, I. Chuang, dards Institute, 1430 Broadway, New York, NY 10018,
and I. L. Markov, A layered software architecture for USA, 1996, approved December 8, 1994.
quantum computing design tools, IEEE Computer, [35] J. M. Chow, Quantum information processing with
vol. 39, no. 1, pp. 7483, 2006. superconducting qubits, Ph.D. dissertation, Yale
[19] A. JavadiAbhari, S. Patil, D. Kudrow, J. Heckey, University, 2010.
A. Lvov, F. T. Chong, and M. Martonosi, Scaffcc: [36] A. J. Abhari, A. Faruque, M. J. Dousti, L. Svec,
Scalable compilation and analysis of quantum pro- O. Catu, A. Chakrabati, C.-F. Chiang, S. Vanderwilt,
grams, Parallel Computing, vol. 45, pp. 217, 2015. J. Black, and F. Chong, Scaffold: Quantum program-
[20] T. H aner, D. S. Steiger, M. Smelyanskiy, and ming language, DTIC Document, Tech. Rep., 2012.
M. Troyer, High performance emulation of quantum [37] S. Marlow, Haskell 2010 Language Report, https://
circuits, arXiv preprint arXiv:1604.06460, 2016. www.haskell.org/definition/haskell2010.pdf, 2010, ac-
[21] M. Smelyanskiy, N. P. Sawaya, and A. Aspuru- cessed: 2016-06-21.
Guzik, qhipster: the quantum high performance [38] D. Syme et al., The F# 4.0 Language Specifi-
software testing environment, arXiv preprint cation, http://fsharp.org/specs/language-spec/4.0/
arXiv:1601.07195, 2016. FSharpSpec-4.0-latest.pdf, 2016, accessed: 2016-06-
[22] A. Barenco, C. H. Bennett, R. Cleve, D. P. DiVin- 21.
cenzo, N. Margolus, P. Shor, T. Sleator, J. A. Smolin, [39] B. W. Kernighan, The C Programming Language,
and H. Weinfurter, Elementary gates for quantum 2nd ed., D. M. Ritchie, Ed. Prentice Hall Professional
computation, Physical review A, vol. 52, no. 5, p. Technical Reference, 1988.
3457, 1995. [40] R. Milner, M. Tofte, and D. Macqueen, The Definition
[23] M. A. Nielsen and I. L. Chuang, Quantum computa- of Standard ML. Cambridge, MA, USA: MIT Press,
tion and quantum information. Cambridge University 1997.
Press, 2010. [41] J. McCarthy, Recursive functions of symbolic ex-
[24] D. Deutsch, A. Barenco, and A. Ekert, Universality pressions and their computation by machine, part i,
in quantum computation, in Proceedings of the Royal Communications of the ACM, vol. 3, no. 4, pp. 184
Society of London A: Mathematical, Physical and 195, 1960.
Engineering Sciences, vol. 449, no. 1937. The Royal [42] P. Selinger and B. Valiron, A lambda calculus for
Society, 1995, pp. 669677. quantum computation with classical control, Math-
[25] S. Aaronson, Quantum computing since Democritus. ematical Structures in Computer Science, vol. 16,
Cambridge University Press, 2013. no. 03, pp. 527552, 2006.
[26] IEEE standard for binary floating-point arithmetic, [43]
B. Omer, Structured quantum programming, Ph.D.
New York, 1985, note: Standard 7541985. dissertation, Technical University of Vienna, 2003.
[27] J. W. Cooley and J. W. Tukey, An algorithm for [Online]. Available: http://tph.tuwien.ac.at/oemer/
the machine calculation of complex fourier series, doc/structquprog.pdf
Mathematics of computation, vol. 19, no. 90, pp. 297 [44] , QCL - A Programming Language for Quan-
301, 1965. tum Computers, http://tph.tuwien.ac.at/oemer/
[28] D. E. Knuth, The Art of Computer Programming, qcl.html, 2014, accessed: 2016-06-30.
Volume 1, Fascicle 1: MMIX A RISC Computer for [45] C. Lattner and V. Adve, LLVM: A Compilation
the New Millennium (Art of Computer Programming). Framework for Lifelong Program Analysis & Trans-
Addison-Wesley Professional, 2005. formation, in Proceedings of the 2004 International
[29] Rigetti Computing, pyQuil, 2016, accessed: Symposium on Code Generation and Optimization
2016-08-10. [Online]. Available: https://github.com/ (CGO04), Palo Alto, California, Mar 2004.
rigetticomputing/pyQuil [46] Clang developers, clang: a C language family fron-
[30] E. Jones, T. Oliphant, P. Peterson et al., SciPy: tend for LLVM, http://clang.llvm.org/, accessed:
Open source scientific tools for Python, 2001 2016-06-30.
2016, accessed: 2016-06-21. [Online]. Available: http: [47] MIT Quanta Group, Quantum circuit viewer:
//www.scipy.org/ qasm2circ, http://www.media.mit.edu/quanta/
[31] The JSON Data Interchange For- qasm2circ/, accessed: 2016-06-30.
mat, 1st ed., October 2013. [On- [48] , qasm-tools, http://www.media.mit.edu/qua
line]. Available: http://www.ecma-international.org/ nta/quanta-web/projects/qasm-tools/, accessed:
publications/files/ECMA-ST/ECMA-404.pdf 2016-06-30.
[32] F. E. Allen, Control flow analysis, SIGPLAN Not.,
vol. 5, no. 7, pp. 119, Jul. 1970. [Online]. Available:
http://doi.acm.org/10.1145/390013.808479
[33] W. M. McKeeman, Peephole optimization,

You might also like