Arxiv:1806.01861V1 [Quant-Ph] 5 Jun 2018 Lower Clock Speed Than Classical Ones
Total Page:16
File Type:pdf, Size:1020Kb
Advantages of a modular high-level quantum programming framework Damian S. Steiger,1, ∗ Thomas H¨aner,1, y and Matthias Troyer1 1Theoretische Physik, ETH Zurich, 8093 Zurich, Switzerland We review some of the features of the ProjectQ software framework and quantify their impact on the resulting circuits. The concise high-level language facilitates implementing even complex algorithms in a very time-efficient manner while, at the same time, providing the compiler with additional information for optimization through code annotation { so-called meta-instructions. We investigate the impact of these annotations for the example of Shor's algorithm in terms of logical gate counts. Furthermore, we analyze the effect of different intermediate gate sets for optimization and how the dimensions of the resulting circuit depend on a smart choice thereof. Finally, we demonstrate the benefits of a modular compilation framework by implementing mapping procedures for one- and two-dimensional nearest neighbor architectures which we then compare in terms of overhead for different problem sizes. Keywords: Quantum Computing, Compilers, Quantum Programming Languages I. INTRODUCTION Quantum computers will be able to solve certain prob- lems faster than any classical supercomputers and thus enable finding solutions to problems that are intractable classical on any future classical computer. Quantum computers are not intended to replace classical technology. Rather, quantum they should be viewed as special-purpose accelerators, Run time similar to today's GPUs or FPGAs which are running in compute centers to speed up specific applications or subprocesses thereof. Problem size There are many reasons to believe that quantum com- puters will not replace classical computers. One is that most of the currently pursued technologies to build quan- Figure 1. Illustration of what is typically encountered when comparing a quantum algorithm which exhibits a quantum tum bits require a vacuum chamber or temperatures on speed-up to the best classical algorithm in terms of run time. the order of milliKelvin, which makes them bulky and un- The crossover point, i.e., the problem size after which the suitable for mobile technology. In addition, there are fun- quantum algorithm outperforms its classical counterpart, is damental constraints for the programs running on quan- shown as a red dashed line. tum hardware due to the laws of quantum mechanics. In particular, all operations must be made reversible which incurs a large polynomial overhead in both space and few examples of algorithms with quantum speedups are time when translating a classical computation consisting known and finding more is a very challenging task which of, e.g., NAND gates to reversible Toffoli gates. Further- is crucial to the development of the whole community. more, to successfully run a quantum program on a phys- In order to determine if quantum algorithms with a ical device, quantum error correction has to be employed scaling advantage can be useful for real applications, it in order to reduce the effects of noise on the computa- is important to investigate at which problem size the tion. This causes quantum computers to run at a much crossover point is reached after which the quantum al- arXiv:1806.01861v1 [quant-ph] 5 Jun 2018 lower clock speed than classical ones. gorithm has lower runtime, see Fig. 1 for an illustration. Hence, the focus of the quantum computing research If the crossover point is too far out, it might not be prac- community has been on finding applications for which tical to use a quantum computer, e.g., if observing any a quantum algorithm has a large scaling advantage in speed advantage requires a runtime of at least the age of time-to-solution, also known as a quantum speedup. A the universe [2]. Cost estimation of a quantum program handful of such algorithms has been discovered such as can be achieved time-efficiently using a full stack software the famous algorithm by Peter Shor for factoring inte- framework with a quantum programming language and gers [1]. This algorithm scales super-polynomially better sophisticated compilers. With these optimizing compil- than the best known classical algorithm and has applica- ers, such a framework also allows to lower the crossover tions in breaking certain encryption schemes. So far only point even in the absence of large-scale quantum com- puters. This is crucial in order to leverage the economic potential of small-scale quantum computers as soon as ∗ [email protected] possible. y [email protected] In this paper, we are concerned with the software stack 2 involved in running a quantum program. We provide a partial review of our software methodology [3] which was then implemented resulting in the ProjectQ software • Classical computation Host framework for quantum computing [4], but with a new • Static compilation of focus on some important aspects of the high-level pro- quantum program gramming language and new mappers. In particular, we show how different intermediate representations can de- crease the quantum resources for the example of Shor's algorithm and quantify the resource improvements by us- • Runtime environment ing meta-instructions (code annotation) in the high-level Controller including low-level language. We then introduce a new feature of ProjectQ, compilation and QEC namely mapping to a linear chain of qubits with nearest neighbor gates or a two-dimensional square grid. Con- • Feedback with QPU sidering the overhead of mapping is important in deter- mining the crossover points of quantum algorithms run- ning on specific architectures. While our mappers scale • Quantum instructions optimally in terms of circuit depth, there is potential QPU to reduce the constant factors by finding better heuris- • Measurement tics. Providing these mappers and applications as open source software allows to incrementally improve their per- formance. Mappers are not just important in the long run, but crucial in the current Noisy Intermediate-Scale Figure 2. Different levels of logic in a quantum hardware Quantum (NISQ) technology era [5], where quantum re- stack. For some architectures, the number of intermediate sources are very limited. We conclude with an outline hardware levels may vary and lower parts of the stack may of future research with and development of the ProjectQ reside in a cryostat [20]. framework. Related work Besides ProjectQ, there have been nu- merous other contributions in this field of quantum pro- for a grid with n points, see [19]. gramming languages and compilers. A few of them are available as open source such as Quipper [6], a quan- tum program compiler implemented in Haskell, the Scaf- II. COMPILATION TO QUANTUM fCC compiler based on the LLVM framework [7], IBM's HARDWARE QISKit [8], and Rigetti's pyQuil [9]. Moreover, there are closed source quantum programming languages such as The goal of a quantum software stack is to compile Microsoft's LIQUi ji [10] or Microsoft's Q# [11], the lat- quantum programs to run them on actual quantum hard- ter of which currently allows executing the resulting cir- ware. We give a short overview of a quantum software cuits on a local simulator employing simulation kernels stack, outlining the challenges involved from a high-level from ETH Zurich [12]. perspective before going into the details in the next sec- The task of mapping a quantum circuit to a restricted tions. For a recent review on quantum programming, see interaction graph has been studied extensively. The aim Ref. [21] and more details on our methodology can be of this paper is to provide model implementations of map- found in [3]. pers in ProjectQ. Future work will be concerned with A high-level schematic of a large-scale quantum com- extending and improving their performance beyond the puter is shown in Fig. 2. A quantum computer func- current state of the art. Mapping to a linear nearest tions as an accelerator for a classical host computer to neighbor architecture is discussed in detail for example solve specific subproblems. The software stack running in [13{15]. Our implementation is similar to Hirata et on the host computer performs the static compilation of al. [14] for a linear nearest neighbor architecture. Our a quantum program. This process includes decomposing algorithm finds qubit placements using a greedy search operations into a low-level logical gate set such as, e.g., while theirs also employs more compute-intensive opti- the two-qubit CNOT gate and single-qubit rotations. Af- mizations in order to reduce the total number of swaps. ter decomposing the quantum program into a low-level We improve upon their method by using a standard odd- gate set, the compiler on the host computer has to map even transposition sort [16] instead of bubble sort for the all operations to a restricted connectivity graph where, routing which can reduce the circuit depth by a constant e.g., only nearest-neighbor qubits can perform a CNOT factor using the same number of swaps. Our implemen- gate and hence qubits may have to be routed by swap tation of a mapper for the two-dimensional square grid operations. follows the description in [17, 18]. It has been known Closer to hardware, we imagine a powerful classical since 1986 that there are sorting networkp for square grids controller which provides the runtime software environ- which have a worst-case overhead of 3 n in circuit depth ment. This includes error correction, rotation synthesis, 3 circuit-depth overhead solution using a brute-force ap- proach for near-term hardware. It is important, however, to keep in mind that we should only apply compilation , techniques which at least scale to quantum program sizes that we cannot classically simulate because only there, a quantum computer might show an advantage. All smaller programs are just proof of concept along the way toward larger quantum computers.