Quantum programming made easy

2 downloads 0 Views 726KB Size Report
Nov 2, 2017 - (tc4). B ⊣ get : Nat → Nat → Nat. (tg). Table 1: Typing Rules. (toy) languages ..... Logical Methods in Computer Science, 8(1), 2012. [5] O. Cross.
Quantum programming made easy Luca Paolini1 , Luca Roversi2 , and Margherita Zorzi3

arXiv:1711.00774v1 [cs.LO] 2 Nov 2017

1

Dipartimento di Informatica, Universit` a di Torino, [email protected] Dipartimento di Informatica, Universit` a di Torino, [email protected] 3 Dipartimento di Informatica, Universit` a di Verona, [email protected] 2

November 3, 2017 Abstract We introduce the functional language IQu (“Haiku”) which, under the paradigm “quantum data & classical control” and in accordance with the model QRAM, allows to define and manipulate quantum circuits also by means of intermediate and partial measurement. Idealized Algol is the reference for the design of IQu. We extend the type system of Idealized Algol for typing both quantum-registers, i.e. the stores of quantum states, and quantum-circuits. The types for quantum-registers do not make any reference to linear logic formulas and are parametric on the dimension of the quantum-registers they are type of. IQu operates on quantum circuits as they were classical data so no restriction exists on their duplication. Concerning programming, we show the potential effectiveness of IQu by encoding well known quantum algorithms in it.

1

Introduction

After some attempts in the Nineties by Maynim[17], Peter Selinger in [27] proposes the first true investigation in quantum programming theory. The question Selinger rises is straight: “How could we program quantum computers?”. So far satisfying answers are unknown. Selinger outlines that besides the effort addressed to build the hardware of a quantum computer we also need programming paradigms which cannot rely on quantum Turing machines exactly as for current architectures we do not refer to classical Turing machines. The slogan “quantum data & classical control ” delineates Selinger’s design philosophy which we briefly summarize. A programmer can instruct a classical machine to generate “directives”. The directives are programs for a hypothetical quantum device which applies them to quantum data. It turns out that the classical part of the program is the coordinator of the unitary processing on quantum data by the quantum device. Quantum Random Access Machine (QRAM) [12] is the low level computation model of reference of “quantum data & classical control ” because it reflects the typical design of quantum algorithms. Selinger’s proposal is QPLS , a first-order quantum programming language. QPLS supplies structured data-type, is statically typed and run error-free and allows to program recursively. QPLS is an effective tool to identify basic principles of quantum programming which we can express as quantum flow charts or in terms of functional concrete syntax. Finally, we recall that superoperators are the main building block of the semantics for QPLS . After Selinger’s QPLS , further proposals of quantum languages we like to recall are [8, 2, 9, 4, 20, 34, 28, 29]. Not all of them adhere to the paradigm “quantum data & classical control ”. For those ones which do, Pagani [20] and Zorzi [34] focus on languages that can be seen as computational models. Selinger [28, 29], instead, is more oriented to pioneering prototypes for effective quantum programming languages. The most advanced proposal in the latter direction is the high-level circuit description language Quipper [32] which allows to create, manipulate, evaluate circuits in a style 1

that mixes procedural and declarative approaches. Quipper is algorithmically expressive allowing to implement relevant quantum algorithms. ProtoQuipper, a core of Quipper, is the subject of [26, 16] whose focus is on proof-theoretical properties of ProtoQuipper and on its relationship with the lambda calculus as defined in [28]. The languages in [28, 26, 16, 20, 34] follow the direction suggested by Selinger in [27] for dealing with manage higher-order functions. In Selinger’s words: ”...to account for the non-duplicability of quantum data due to the no-cloning property, it appears that (such) a language should be equipped with a linear type system along the lines of Girards linear logic”. Linear Logic-based types (or well-forming) systems are indubitably useful and suitable to manage quantum data, since Linear Logic naturally offers an elegant framework to distinguish between duplicable and not-duplicable resources. Notwithstanding, other solutions are possible, as shown in recent investigations (see below,[24, 23, 22]). These solutions come up when one moves the focus from the data-perspective to the control perspective, i.e. from quantum data to classical control. Inside the paradigm quantum data & classical control , we can decline the change of focus in several ways. Some first steps can be noted in Quipper, but a more mature language that develops these change more systematically is QWire [24]. We are talking about the programming pattern that looks at the classical world as a place where generating descriptions of quantum circuits. The circuits descriptions can be input for a quantum co-processor which the classical world look at as it was a kind of oracle. Measurement allows to consult the oracle. Once the “quantum oracle” answers, the control gets back to the classical computation. The specification about how the communication between the classical world and the “quantum oracle” develops can be formalized by means of dependent types. QWire promotes this approach which, however, is concretely pursued in qPCF [23, 22] an extension of PCF: in qPCF a single program can represent an infinite family of quantum circuits, albeit only total von Neumann measurements are available. The shift to dependent types allows a management of linear resources which is alternative to the one which is based on Linear Logic (e.g. [28, 34]). In particular, dependent types definitively circumvent the use of linear types and exponential modalities by allowing the definition of simple programming language that can smoothly program the common quantum algorithms presented in literature. The contributions of [20, 32, 24, 23, 22], provide answers to Selinger’s question, i.e. how to introduce higher-order constructs coherent with the right manipulation quantum data. This paper introduces IQu (“Haiku”). Its design strongly relies on Idealized Algol, a functional language with assignments. The result is a language with higher-order functions whose operational semantics includes the one of both QPLS [27] and qPCF. Morally, IQu improves qPCF also because it offers a general measurement in place of a total measurement and simplifies the type system by getting rid of Linear Logic modalities. More specifically: • No explicit linear constraints exist in IQu: (Linear Logic) exponential modalities do not occur in the types of IQu which manages linear resources in a way which differ from the Linear Logic-oriented approaches of [28, 13, 14, 15, 34, 26, 16]; • A simple form of polymorphism exists in the type system of IQu: classical control is decoupled from quantum computation by means of polymorphism which is limited to the types of quantum registers. Polymorphism avoids any reference to Linear Logic modalities by allowing a one-way form of dependent types (which can be extended to that presented in [23, 22]); • Partial or general measurement in the course of a computation is available for IQu. This is an advancement with respect to [23, 22]; • Explicit representation of quantum states is available in IQu. Similarly to [28, 13, 34], the operational semantics of IQu manipulates explicit representations of the “quantum memory”, i.e. quantum registers and co-processors. Instead, the quantum states remains hidden along the computation. • IQu is Turing complete: This is trivially true because programs of IQu can represent recursive family of circuits, but also all recursive partial function on integer numbers. 2

Synopsis Section 2 recalls some basic notions about quantum operations we need to introduce IQu. Section 3 introduces syntax and typing system of IQu. Section 5 defines the operational semantics and sketches its main properties. Section 6 proposes some encodings of well-known quantum algorithms the goal being to show how IQu works as a programming language. Section 7 conlcudes the paper.

2

Operations on quantum data

We refer [18] as a standard and comprehensive reference for quantum computation. Here we just recall what we need. We introduce mathematical tools to formalize operations on quantum co-processors, i.e. the interaction between classical and quantum world. The information of n ∈ N qubits is usually formalized by means of a normalized vector Hn which is a Hilbert space of dimension N = 2n with orthonormal basis: N

z }| { . . 1}i . | 0| .{z . . 0}i, . . . , | 1| .{z n

n

The binary number x[ of any value x in the interval [0, . . . , N − 1] identifies a vector in Hn . The binary representation is handy to represent every state |ψi of the Hilbert space as a linear combination: |ψi = c0 |0[ i + . . . + cN −1 |(N − 1)[ i with c0 , . . . , cN −1 ∈ C. Quantum circuits or measure operator can transform quantum states [33]. The notation reserved to input or output states is |φi, |φi1 , . . .. A quantum gate is a unitary transformation U : Hk → Hk where, typically, k is not greater than 3. We denote the quantum gates by U, V, W, . . .. Given two unitary vectors |φi, |ψi ∈ Hn , if U |φi = |ψi, then |ψi is the output state for the input state |φi. Quantum circuits are parallel and series compositions of quantum gates that can be interpreted as unitary transformation (obtained by composition). The latter idea is basic to define the operational semantics of a quantum programming language where quantum circuits occur. In Section 5, which introduces the operational semantics of IQu, the interpretation of the strings that we use to describe quantum circuits is a family of semantic functions which depend on a parameter: it is the dimension n of a Hilbert space which takes a circuit as its input and gives a unitary operator back. We recall that a measurement reduces a quantum state partially, or totally, to a classical state. More precisely, given a state |φi ∈ Hn , we can measure a single qubit of |φi (i.e. a partial measurement if n ≤ 2). The result of the measurement is a single classical bit together with the residual state vector, with an given probability. q q q q 1 5 2 3 Example 1. Let the state |ψi = 11 |00i + 11 |01i + 11 |10i + 11 |11i be given and let us q q 6 suppose we want to observe its first quantum bit. To that aim let us rewrite |ψi as 11 |0i( 16 |0i + q q q q 5 5 2 3 6 6 |1i) + 11 |1i( 5 |0i + 5 )|1i. Measuring the first qubit yields 0 with probability 11 and q q  1 5 the state collapses to the substate |0i 6 |0i + 6 |1i . Otherwise, the measurement of the first q q  5 2 3 qubit yields 1 with probability 11 and the residual state is |1i |0i + )|1i . 5 5 IQu allows for partial measurements of an arbitrary subset with k qubits of a quantum state with n qbits. Following [11], we define a partial measurement operator pMean : Hn ×N −→ ℘ N×Hn ×R ; let us assume that k ∈ N, N = 2n , K = 2k%n and j · h denote the number obtained by juxtaposing

3

of the the binary representations of j and h.  P P [ [  j