A Practical Quantum Instruction Set Architecture
Total Page:16
File Type:pdf, Size:1020Kb
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 Abstract—We introduce an abstract machine archi- IV-A Quantum Fourier Transform . .9 tecture for classical/quantum computations—including compilation—along 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 arXiv:1608.03355v2 [quant-ph] 17 Feb 2017 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 Instructions8 with 4–9 qubits have been demonstrated with the perfor- mance required to run quantum simulation algorithms [1, III-J2 Classical Binary Instructions8 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 algorithms—including 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 elements: Classical Computation Quantum Computation • A fixed but arbitrary number of qubits Nq indexed Classical Data th from 0 to Nq − 1. The k 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 th for valuable applications. In machine learning and quan- and indexed from 0 to Nc − 1. The k 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 puting device. It includes support for manipulating both O |Ψi ∈ H := BNq −k−1. (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 th QAM. the p 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 o qubit Qj and target qubit Qk is defined as X dim Hi×dim Hj Hi ⊗Hj := Cp,q |pii ⊗ |qij : C ∈ C . 1 0 0 0 p∈[dim Hi] | {z } q∈[dim ] basis element 0 1 0 0 Hj CNOT := : ⊗ → ⊗ . (2) 0 0 0 1 Bj Bk Bj Bk 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,jB. 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. We now wish to provide a constructive method for |bNq −1i ⊗ · · · ⊗ |b1i1 ⊗ |b0i0 Nq −1 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 induces an operator U˜ on by tensor-multiplying with |bNq −1 . b1b0i . H 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 U˜ = IN −1 ⊗ · · · ⊗ U ⊗ · · · ⊗ I1 ⊗ I0.