Professional Documents
Culture Documents
IV Quil Examples 9
AbstractWe introduce an abstract machine archi- IV-A Quantum Fourier Transform . . . . . 9
arXiv:1608.03355v2 [quant-ph] 17 Feb 2017
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
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.
$ 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 } }
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