QUANTUM PROGRAMMING: IMPLEMENTING GROVER'S ALGORITHM WITH COVE MATT PURKEYPILE affiliation? BO SANDEN Colorado Technical University Department of Computer Science 4435 N. Chestnut Street, Colorado Springs, Colorado 80907, United States Received (date) Revised (date) Quantum computers hold the promise of being able to outperform their classical counterparts for certain tasks. Like classical computers these useful tasks are accomplished on hardware via the software that manipulates it. Much work has gone into creating quantum hardware, but surprisingly little work has gone into creating quantum software. Cove is a framework built on existing classical languages that allows them to be extended for quantum computation. Unlike new languages developed for quantum computing, frameworks built on top of classical languages come with decades of refinement for classical tasks– allowing the designer to focus on quantum computation. Keywords: Quantum Programming, Grover's Algorithm, Cove, Frameworks Communicated by: 1 Introduction They are still under development, but quantum computers hold the promise of being able to outperform existing classical computers for certain tasks. Quantum computers run on quantum bits, more commonly called qubits. Unlike their classical counter parts, bits, qubits can hold the values 0, 1, and a probabilistic combination of the two– formally called superposition. Not only can qubits be in superposition, but they can also be entangled: actions to one qubit may impact others. It is these strange properties of qubits that give a quantum computer capabilities that do not exist with classical ones. While quantum computers were more of a curiosity when they were first proposed in the 1980s, interest and research in the field has increased dramatically since the introduction of Shor's algorithm for factoring in the mid 1990s [1]. However a vast majority of this research is going towards the physical implementations of quantum computers. As is the case with classical computers, the hardware is of little use if there is not software to run on it. This paper introduces Cove, which is a software framework built on classical languages that extends them to allow for quantum computation. Since Cove is a framework for a classical language instead of a new language for quantum computation, Cove comes with all the power for classical computation that must also be tackled in those quantum specific languages. This narrows the focus of Cove to providing quantum computation instead of tackling that as well, which a new language must do. Furthermore, more than 8,500 languages have been developed as of 2007 [2], yet very few see any significant use– presenting another hurdle for the adoption of a language for quantum computation. The remainder of the paper is organized as follows; section 2 introduces several other quantum programming methods that have been proposed, as well as some of their flaws that Cove attempts to address. Section 3 presents the philosophy of Cove, along with rationale for many of the design decisions. Section 4 is a tutorial on the basics of Cove and how to use it, while section 5 illustrates how to carry out several common quantum algorithms. Finally, section 6 presents the conclusion. 2 Existing Programming Methods and Flaws Often a quantum computer is utilized only for part of the desired computation. Shor's algorithm is an excellent example: a quantum computer is utilized only for part of the algorithm as shown in Figure 1. Due to this, any method to program quantum computers must also be able to perform classical computation. Figure 1. Flow chart of Shor's algorithM. There have been perhaps a few dozen methods of quantum computer programming proposed to date. Nearly all of these exhibit one or more of several flaws, which make them difficult to integrate in a classical environment, especially for existing commercial developers. These flaws include, but are not limited to: A quantum specific language Utilizes functional programming Lack of scalability Difficult to integrate with existing (classical) software Lack documentation Unconventional techniques As outlined in the introduction, quantum specific languages present many challenges. Perhaps the largest is that any new language for quantum computation must also provide functionality for classical computation. Considering the decades of refinement and effort that has gone into the development of classical languages, this represents a significant hurdle. In reality, any language for quantum computation will likely lack the classical power of existing classical languages. Additionally there are thousands of programming languages that have been developed. Few of these languages see any significant use. When considering that a quantum computer may be utilized only for part of a program, it could be unlikely that a quantum language would be adopted. The rationale for this being that popular languages are selected for their general purpose nature, not because they tackle a few specific problem well. Functional programming may not seem like a flaw at first, as there has been much work in that area of programming and it fits the model of quantum computation well. However if quantum computing will be utilized in commercial development, perhaps like parallel programming has, functional programming needs to be examined from that perspective. In a commercial software development environment most developers do even hold a bachelors degree in computer science or a related discipline [3]. Any examination of job postings for developers reveals that most development in object oriented languages such as Java and C#. In this context functional programming represents a significant learning curve and challenge to the common commercial developer. Lack of scalability generally means that the programming proposal is not practical beyond small snippets of code. Two examples would be graphical programming and approaches requiring formal proofs. For quantum programming to be successful it should scale up to larger applications just as classical languages have evolved to do. Another shortcoming in many other methods is the difficulty to integrate with existing classical software. In all likelihood a quantum computer will only be exploited for a very small portion of a larger application. Perhaps a simple example would be replacing part of an existing database system with a part that exploit's Grover's algorithm [4] for searching. It would be prohibitively expensive to rewrite in a quantum language just so that some searching could be improved. Documentation is often neglected with existing programming proposal, but it represents perhaps the largest hurdle to learning a particular programming method. Without thorough documentation that contains examples, users are forced to spend time figuring out things that could've been resolved in a matter of seconds with complete documentation. Furthermore the programming technique itself must be as self documenting as possible. This means that obscure abbreviations or unclear names should be avoided. TODO: Ref to 10 commandments of webservices. Unconventional techniques is a general catagory that covers anything done outside of the norm or spirit of commonly accepted programming practices. One example would be poor object oriented design such as having classes alter the internal state of others through direct manipulation instead of message passing. 2.1 QRAM Model In 1996 Knill established the quantum random access machine (QRAM) model [5]. This model states that a quantum computer will be a slave device to a classical computer, as shown in Figure 2. This model is likely for many reasons. First of all, quantum computers will likely be expensive and limited in the number of qubits when they are first used commercially. This will make them impractical for classical computing, meaning that a majority of computations will still have to be performed on a classical machine, which utilizes a quantum computer only when necessary. Figure 2. Knill's QRAM model. Implicitly or explicitly, nearly all existing proposals for programming quantum computers make use of the QRAM model. Another important part of the model is that the classical computer has a logical representation of the quantum resource. This means that the quantum computer could take on any physical form, or perhaps even be a simulation. The key is that those should be as interchangeable as possible, ideally with little or no changes for the code on the classical computer. 2.2 Prior work There have been perhaps a few dozen programming proposals developed from the mid 1990s to present. Most of these techniques suffer from multiple flaws outlined previously. For a more complete survey of existing programming proposals the reader is referred to [6, 7]. Arguably the most complete work to date, and an inspiration for Cove, is Omer's QCL [810]. QCL is a procedural language for quantum computing with a C like syntax, as shown in Figure 3. TODO: say more Figure 3. Sample of Omer's QCL. The work closest to Cove are Bettelli's C++ extensions, sometimes called Q [11]. In this there are several classes that can be utilized for quantum computation. Like Cove, since these are built on top of a classical language the focus is on quantum computation and not duplicating the abilities for classical languages. Since C++ is a popular language, there is a large pool of developers already familiar with the syntax. Furthermore Bettelli presents a list of desirable criteria that has been taken to heart with Cove: completeness, classical extension, separable from classical programming, expressive, and hardware independent [12]. Figure 4 shows an example of quantum programming with Bettelli's C++ extensions, from [12]. Figure 4. Sample of Bettelli's C++ extensions. 3 Philosophy and Rationale of Cove The intent of this section is to detail the philosophy that Cove was developed as well as the rationale behind the major design decisions. Very few of the existing quantum programming proposals provide this. Given that we still may be a decade or more away from practical quantum computers it is unlikely that any of the existing proposals will be used to program quantum computers at that time in their current incarnation. Thus what is hoped from Cove is not that it survives as a software product, but that the philosophy and rationale behind it survive to help create a practical method of programming quantum computers. As previously detailed, Cove is a software framework built on top of existing classical languages. This allows for Cove to focus only on providing quantum programming, the classical is handled by the languages it is built upon. Specifically Cove is built on top of .NET. The motivating reason for doing so is that Cove is then usable by any .NET language, which includes C#, Visual Basic, IRON Python, F#, and so on. This opens Cove up to wide variety of languages and programmers. Perhaps the all encompassing philosophy behind Cove is that it should make quantum computing as easy as possible for the common developer. Many of the existing proposals are complicated and have a significant learning curves for them– thus increasing the cost for them to be adopted for commercial applications. TODO: Some more... One key concept of Cove is that of programming to interfaces. What is meant by this is that users largely programming against abstract interfaces, while the implementation is defined in a separate library. This separates the what the user wants to accomplish from the how. Ideally this allows for implementations to be swapped out with nothing more than a change of reference and using statement. This can allow for programs to be tested on quantum simulators that are later swapped out with more powerful simulations or one that even runs on a quantum computer. The current incarnation of Cove provides a prototype of a simulation that runs on the local system, allowing for some code to be written and executed. Given that Cove is a framework, this also means it is extensible by users. Framework designers cannot anticipate all uses of the frameworks they create, therefore extensibility is key. This extensibility allows users to leverage what already exists in the framework, potentially decreasing the cost of development. Cove can be expanded to the point that users can also create their own implementation, which allows them to create more efficient simulations or ones that run on actual quantum computers. Another important goal of Cove is that it integrates well with classical computation. As previously stated, a quantum computation may only be a small part of the overall computation. Arguably this can be done by extending an existing language. Many of today's popular languages have been under development for decades if you track their linage [13]. This requires a language specific for quantum computing to offer many of the features of existing classical languages if it is going to compete; which is an expensive proposition. Furthermore it is also costly, perhaps prohibitively, to rewrite code bases just in order to utilize a quantum computer. If quantum computation can be bolted onto an existing code base, it will be much easier to integrate quantum computation a . The all-encompassing theme of Cove is that it should make programming quantum computers as simple as possible for the common commercial developer. Additionally, since practical quantum computers are still a number of years away and may be used for applications not yet anticipated, it is designed in such a way that it is extensible. Along with this them of extensibility is that the implementations should be interchangeable. a Although web services also hold the potential to integrate with existing code bases. 4 A Short Primer on Cove Like classical computation, quantum computation sounds simple when listing all that must be done: initialization of a register to an initial state, performing operations on that register, and measuring it to obtain a classical result. This section provides a brief primer on how these actions are accomplished in Cove. Also since one of the aims of Cove is usability, some of the rationale is provided behind the design decisions and why they are believed to promote usability. The learning curve of any new programming technique represents an expense for the user. One of the easiest and most beneficial things that can be done to lessen this expense is to provide plenty of documentation. The documentation for Cove details every class, method, parameter, output, and possible exceptions. This documentation is provided four different ways: 1. 2. 3. 4. Through comments in the source code itself. Through intellisense documentation when using Microsoft Visual Studio. Through a local help file (chm) that is distributed with Cove. Online at the Cove website at https://cove.purkeypile.com/Help. As was mentioned in the previous section, there is distinction between the implementations and the interfaces. Ideally a user should program against the interfaces, which allows for the implementations to be swapped out. At present the only implementation for Cove is a prototype of a local simulation, meaning a simulation of a quantum computer that runs on an existing PC. Since this is a simulation, it experiences an exponential slow down as the number of qubits being simulated. Furthermore this is a simple simulation, meaning that few steps have been taken to optimize the simulation beyond the simple linear algebra of a 2n x 2n operation applied to a 2n matrix representing n qubits. Thus for practical purposes no more than a few handfuls of qubits can be simulated. This is also a prototype simulation, meaning that not every method in the interfaces are implemented, yet enough is implemented in order to carry out all the examples put forth in this paper. IQuantumRegister TestReg = new QuantumRegister(3); Figure 5. Creating a register of 3 qubits in Cove. Qubits are the fundamental unit of information in a quantum computer, with collections being referred to as (quantum) registers. In Cove registers are provided by the IQuantumRegister interface located in the interfaces, Cove.Base. There is no qubit interface for a single qubit, instead registers containing one qubit are used. There are several categories of methods available on IQuantumRegister, each which will be discussed in turn: Methods that add qubits to a register. Ones that measure the register. Those that manipulate the existing register (slicing). Miscellaneous methods. Methods that apply quantum operations. The first group of methods on a quantum register are those that add qubits register. These are straight forward as one would imagine. Lessening the number of qubits or rearranging the order of qubits fall under slicing. Aside from adding qubits to a register, another simple set of operations available are those that measure a register, or perhaps a subset of a register. Obviously measurements of qubits collapse them to a state that can be represented classically. As such, the output of the measurement functions are an instance of ClassicalResult. These instances can then be transformed through operations to integers, arrays of bits, and other various classical data types. Of course, if one doesn't care about the classical result it can simply be discarded. Several different measurement operations are provided, so a user can measure the entire logical register, or a subset in various ways. The slicing operations allow for logical manipulations of a register and are inspired by the slicing of lists in Python. Section 1: Base versus implementation. Section 2: Registers Section 3: Operations Section 4: Others (classical results too) 5 Cove Examples and Implementation of Grover's Section 1: Built in elementary operations and how to apply them. Section 2: How to build up new operations from the elementary ones. Include examples such as sum. Section 3: Building up operations for Grover's Section 4: Implementing Grover's 5 Conclusion Section 1: Areas for future work Section 2: Conclusion Acknowledgements TODO References [1] [2] [3] P. W. Shor, "Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer," SIAM Journal on Computing, vol. 26, p. 25, October 1997 1997. T. J. Bergin, "A History of the History of Programming Languages," Communications. ACM, vol. 50, p. 5, May 2007 2007. S. McConnell, Professional Software Development. Boston, MA: AddisonWesley, 2004. [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] L. K. Grover, "A fast quantum mechanical algorithm for database search," Proceedings of the twenty-eighth annual ACM symposium on Theory of computing, pp. 212-219, 1996. E. Knill, "Conventions for Quantum Pseudocode," Los Alamos National Laboratory LAUR-96-2724, 1996. S. J. Gay, "Quantum Programming Languages: Survey and Bibliography," Mathematical Structures in Computer Science, vol. 16, p. 20, March 24, 2006 2006. M. Purkeypile, "Cove: A Practical Quantum Computer Programming Framework," Colorado Springs, CO: Colorado Technical University, 2009, p. 265. B. Omer, "A Procedural Formalism for Quantum Computing," in Theoretical Physics. vol. Masters Vienna: Technical University of Viena, 1998, p. 93. B. Omer, Quantum Programming in QCL, 20Jan2009 ed. Vienna: Technical University of Vienna, 2000. B. Omer, "Procedural Quantum Programming," AIP Conference Proceedings, vol. 627, pp. 276-285, 2001. S. Bettelli, "Towards an architecture for quantum programming," in Mathematics. vol. Ph.D. Trento, Italy: University of Trento, 2002, p. 115. S. Bettelli, T. Calarco, and L. Serafini, "Toward an architecture for quantum programming," The European Physical Journal D - Atomic, Molecular, Optical and Plasma Physics, vol. 25, p. 19, August 2003 2003. R. W. Sebesta, Concepts of Programming Languages, 5 ed. Boston, MA: Addison-Wesley, 2002.