A Resource Estimation and Verification Workflow in Q

A Resource Estimation and Verification Workflow in Q

A Resource Estimation and Verification Workflow in Q# Special session paper Mathias Soeken, Mariia Mykhailova, Vadym Kliuchnikov, Christopher Granade, Alexander Vaschillo Microsoft Quantum, Redmond, United States Abstract—An important branch in quantum computing in- Quantum algorithm volves accurate resource estimation to assess the cost of run- ning a quantum algorithm on future quantum hardware. A Implement Rewrite comprehensive and self-contained workflow with the quantum program in its center allows programmers to build comprehen- Q# program Optimized Q# program sible and reproducible resource estimation projects. We show how to systematically create such workflows using the quantum Test programming language Q#. Our approach uses simulators for verification, debugging, and resource estimation, as well as rewrite steps for optimization. Verification Visualization Resource estimation NTRODUCTION I. I Fig. 1. The proposed resource estimation and verification workflow starts from a quantum algorithm and returns verification, visualization, and resource Quantum computing has the potential to efficiently solve estimation results. The workflow consists of three stages: in the Implement some computational problems that are intractable to solve phase, the programmer expresses the algorithm as a Q# program. In the Rewrite phase, the compiler can optimize the program using automatic rewrite on classical computers [1], [2]. Quantum programming lan- steps. Finally, the Test phase addresses various tasks such as verification, guages [3] allow developers to formalize quantum algorithms visualization, and resource estimation. in terms of quantum programs that can be executed. While execution on a physical scalable fault-tolerant quantum com- Suchara et al. presented QuRE [17], a layout estimation tool puter is not yet possible, the execution of quantum programs targeting evaluation on physical quantum technologies. is already of high interest today, as it allows the developer to In this work, we show how to systematically integrate verify the implementation and to estimate the cost of running quantum resource estimation workflows in Q# [18]. In addition the algorithm, once the quantum hardware is available. to using the quantum programming language, we achieve this Verification is the task of checking whether the quantum by making use of simulators and rewrite steps. Simulators are program correctly implements the quantum algorithm. Several algorithms that execute a Q# program and perform various methods for verification exists, ranging from full-state simu- actions for intrinsic quantum operations. Rewrite steps stati- lation (e.g., [4]), automatic functional verification (e.g., [5], cally translate a Q# program into a different Q# program by [6]), formal verification with program logics (e.g., [7]), or applying rewrite rules on the program’s abstract syntax tree. interactive theorem provers (e.g., [8]). Resource estimation is the task of assessing the cost of running a quantum algorithm II. ESTIMATION AND VERIFICATION WORKFLOW on a future quantum computer. Assuming specific quality Fig. 1 illustrates the overall resource estimation and veri- and performance capabilities of the quantum computer, such fication workflow. Input to the flow is a quantum algorithm; as clock speed, topological constraints, noise models, and outputs can be verification results, visualization artifacts, and error correction overheads, resource estimation computes the resource estimates. The workflow is made up of three stages: required space in number of physical qubits and required implement, rewrite, and test. In the first stage, the developer runtime. Recent studies report resource estimates for various implements the quantum algorithm using Q#, a high-level quantum computing applications, including quantum chem- quantum programming language with built-in support for istry [9], [10], quantum cryptanalysis [11], [12], constraint sat- quantum computing specific constructs such as qubit alloca- isfaction and optimization [13], and quantum simulation [14], tion, intrinsic quantum operations, generation of the adjoint [15]. In all these studies, the authors have not applied a and controlled variants of an operation, or classical control systematic workflow to obtain the resource estimates. As a based on measurement results. It is important to note that in consequence, the presented results are difficult to compare, this workflow the developer writes a single quantum program, to reproduce, and to verify. A few frameworks for resource which will serve as “single source of truth” for all subsequent estimation have been proposed in the past. Recently, Oumarou steps. et al. presented QUANTIFY [16], an open-source framework In the second phase, the Q# compiler performs automatic for the quantitative resource analysis of quantum circuits; rewriting steps to optimize the Q# program. This phase addresses two concerns: (i) some optimizations are difficult j'i j0i j'i X s to detect manually and dedicated optimization algorithms can j+i Z r1 1 help to find these; (ii) some optimizations require to break j0i j i1 j0i Z X j 1i abstractions in the implementation level, for example, the requirement to inline code, so as to unlock further cross- j0i X s j+i Z r2 2 boundary optimization opportunities. The second phase is = mostly automatic, although some rewrite steps may require j0i j i2 j0i Z X j 2i manual configuration. j0i X s The third phase executes the resulting Q# programs (the j+i Z r3 3 manually written one and the automatically optimized one) j0i j i3 j0i Z X j 3i using a variety of simulators, depending on the required results. A simulator controls the execution of a program and j0i j i4 j0i X j 4i performs specific actions whenever qubits are allocated and s3 intrinsic operations are executed. Here are several examples of most commonly used simulators and their purposes: Fig. 2. Quantum circuit representation for quantum fanout with k = 4. The left-hand side shows a linear-depth implementation using CNOT gates. • The ResourcesEstimator updates counters for different The right-hand side shows the constant-depth implementation. Here, si = r ⊕ · · · ⊕ r . If j'i = α, we obtain for the resulting qubit register j i = operations, calculates the depth, and keeps track of the 1 i β maximum number of allocated qubits. j 1 2 3 4i = αj0000i + βj1111i. • The QuantumSimulator performs a full-state simulation and can be used to test various properties of the code (for IV. IMPLEMENTATION PHASE example, show that two operations implement the same unitary), but the number of qubits it allows to allocate is In this section, we describe how to implement the quantum very limited. fanout operation in Q#. We will only highlight some notewor- thy parts in the implementation, and refer the reader to the • The ToffoliSimulator can only be applied to quantum 2 operations that use only classical gates, so that the QDK documentation for further details. The implementation quantum state can be represented by assigning each qubit is as follows: a Boolean value. It is useful for testing such operations. operation ApplyFanout( source : Qubit, The Microsoft Quantum Development Kit provides API to target : Qubit[]) : Unit is Adj { body (...) { extend existing simulators or build custom simulators from 5 AssertAllZero(target); scratch for various applications. A CHP simulator [19] imple- 1 let k = Length(target); mentation is one example for such a custom simulator. Fact(k > 1, "There must be at least two copies"); The workflow is universal. Eventually, an actual quantum 10 using (qs = Qubit[2 * k - 3]) { hardware backend can be used instead of a simulator—without let evens = qs[0..2...]; changing the initial Q# program. let odds = qs[1..2...]; III. RUNNING EXAMPLE ApplyToEach(H, evens); 15 ApplyToEach(CNOT, Throughout this paper, we use quantum fanout as a running Zipped(evens, Most(target))); ApplyToEach(CNOT, example. Quantum fanout implements the unitary operation Zipped(Most(target), odds + [Tail(target)])); ApplyToEach(CNOT, ⊗k F : j'i ⊗ j0i 7! j0i ⊗ j 1 : : : ki; (1) 20 Zipped([source] + evens, evens)); ⊗k let rx = ForEach(MResetX, [source] + odds); where 'i = αj0i + βj1i and j i = j 1 : : : ki = αj0i + let rz = Mapped(IsResultOne, βj1i⊗k. Pham and Svore have shown that F can be im- ForEach(MResetZ, evens)); 25 plemented in constant depth with CNOT and Hadamard op- let s = Mapped(Fold(Xor, false, _), erations, as well as measurements, by using O(k) helper Prefixes(rz) + [rz]); qubits [20]. Fig. 2 illustrates the operation as a quantum circuit ApplyToEach(ApplyIfOne(_, Z, _), diagram for k = 4. The left-hand side depicts a straightforward 30 Zipped(rx, Most(target))); ApplyToEach(ApplyIf(X, _, _), linear-depth implementation that uses only CNOT gates. Note Zipped(s, target)); that the first k CNOT gates share the same control line - } AssertAllZero([source]); the source qubit j'i. The last CNOT gate brings the source 35 } qubit j'i into the j0i state. In the constant-depth optimized adjoint (...) { implementation on the right-hand side, we use H gates to AssertAllZero([source]); initialize some of the helper qubits in the state j+i = Hj0i. 40 let rx = Mapped(IsResultOne, This implementation of quantum fanout applies three layers ForEach(MResetX, Rest(target))); of CNOT gates, independent of the value of k. if (Fold(Xor, false, rx)) { 1github.com/qsharp-community/chp-sim 2aka.ms/get-started-qdk Z(Head(target)); V. REWRITING PHASE } 45 SWAP(source, Head(target)); The rewrite phase applies a sequence of rewrite steps to the Q# program. These operate on the abstract syntax tree AssertAllZero(target); } of the program. The Q# compiler contains several rewrite } steps targeting performance and resource optimization, in- cluding constant propagation, function inlining, and adjoint The operation takes as input the qubit source in the state gate cancellation [21]. An extension API in the compiler j'i and the register target in the state j0i⊗k. The algorithm allows developers to add custom compilation steps to their is implemented in the body-block (Line 4). The code uses projects [22]. assertions to ensure that the target qubits are indeed in the all-zero state when the operation is called (Line 5).

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    6 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us