Automatic Parallelisation of Quantum Circuits Using the Measurement Based Quantum Computing Model

Similar documents
Measurement-based Quantum Computation

arxiv: v1 [quant-ph] 13 Apr 2007

Unitary Dynamics and Quantum Circuits

Measurement-based quantum computation 10th Canadian Summer School on QI. Dan Browne Dept. of Physics and Astronomy University College London

Quantum Information & Quantum Computing

Introduction to Quantum Algorithms Part I: Quantum Gates and Simon s Algorithm

Discrete quantum random walks

QuIDD-Optimised Quantum Algorithms

Quantum Information & Quantum Computing

Lecture 7: Quantum Fourier Transform over Z N

Checking Consistency. Chapter Introduction Support of a Consistent Family

Single qubit + CNOT gates

Quantum Algorithms. Andreas Klappenecker Texas A&M University. Lecture notes of a course given in Spring Preliminary draft.

Factoring on a Quantum Computer

92 CHAPTER III. QUANTUM COMPUTATION. Figure III.11: Diagram for swap (from NC).

Quantum information and quantum computing

Quantum Computing. 6. Quantum Computer Architecture 7. Quantum Computers and Complexity

Advanced Cryptography Quantum Algorithms Christophe Petit

Ph 219b/CS 219b. Exercises Due: Wednesday 20 November 2013

Short Course in Quantum Information Lecture 5

Measuring progress in Shor s factoring algorithm

Semiconductors: Applications in spintronics and quantum computation. Tatiana G. Rappoport Advanced Summer School Cinvestav 2005

Lecture 22: Quantum computational complexity

Lecture 4: Postulates of quantum mechanics

Complex numbers: a quick review. Chapter 10. Quantum algorithms. Definition: where i = 1. Polar form of z = a + b i is z = re iθ, where

On The Complexity of Quantum Circuit Manipulation

Analyzing Quantum Circuits Via Polynomials

Chapter 10. Quantum algorithms

Stochastic Quantum Dynamics I. Born Rule

Lecture 3: Hilbert spaces, tensor products

arxiv: v2 [quant-ph] 16 Nov 2018

Quantum Entanglement and the Bell Matrix

Ph 219b/CS 219b. Exercises Due: Wednesday 22 February 2006

Adequate set of connectives, logic gates and circuits

Grover s algorithm. We want to find aa. Search in an unordered database. QC oracle (as usual) Usual trick

Compute the Fourier transform on the first register to get x {0,1} n x 0.

1 Measurements, Tensor Products, and Entanglement

Introduction to Quantum Information Processing QIC 710 / CS 768 / PH 767 / CO 681 / AM 871

Universal Blind Quantum Computing

ROM-BASED COMPUTATION: QUANTUM VERSUS CLASSICAL

Seminar 1. Introduction to Quantum Computing

Quantum algorithms (CO 781, Winter 2008) Prof. Andrew Childs, University of Waterloo LECTURE 1: Quantum circuits and the abelian QFT

Quantum Phase Estimation using Multivalued Logic

Gates for Adiabatic Quantum Computing

QLang: Qubit Language

Transformation of quantum states using uniformly controlled rotations

Analyzing Quantum Circuits Via Polynomials

Baby's First Diagrammatic Calculus for Quantum Information Processing

Two-Qubit Quantum Gates to Reduce the Quantum Cost of Reversible Circuit

Quantum Searching. Robert-Jan Slager and Thomas Beuman. 24 november 2009

Introduction to Group Theory

Lecture 3: Superdense coding, quantum circuits, and partial measurements

ENERGY loss is an important consideration in digital design.

CHAPTER 2 AN ALGORITHM FOR OPTIMIZATION OF QUANTUM COST. 2.1 Introduction

Classical simulations of non-abelian quantum Fourier transforms

. Here we are using the standard inner-product over C k to define orthogonality. Recall that the inner-product of two vectors φ = i α i.

Semantic Techniques for Quantum Computation

Tutorial on Quantum Computing. Vwani P. Roychowdhury. Lecture 1: Introduction

Quantum Computation. Dr Austin Fowler Centre for Quantum Computer Technology. New Scientist, 10/11/07

Bounds on Quantum codes

CSE 200 Lecture Notes Turing machine vs. RAM machine vs. circuits

Hilbert Space, Entanglement, Quantum Gates, Bell States, Superdense Coding.

Quantum Computation. Michael A. Nielsen. University of Queensland

A New Lower Bound Technique for Quantum Circuits without Ancillæ

Ph 219b/CS 219b. Exercises Due: Wednesday 4 December 2013

Week-I. Combinational Logic & Circuits

Introduction to Quantum Computing

Introduction to Quantum Computing

- Why aren t there more quantum algorithms? - Quantum Programming Languages. By : Amanda Cieslak and Ahmana Tarin

Quantum Information Types

Quantum algorithms for testing Boolean functions

Quantum Error Correction Codes-From Qubit to Qudit. Xiaoyi Tang, Paul McGuirk

Projects about Quantum adder circuits Final examination June 2018 Quirk Simulator

ON THE ROLE OF THE BASIS OF MEASUREMENT IN QUANTUM GATE TELEPORTATION. F. V. Mendes, R. V. Ramos

Consistent Histories. Chapter Chain Operators and Weights

Tensor network simulations of strongly correlated quantum systems

FPGA-Based Circuit Model Emulation of Quantum Algorithms

Lecture 2: From Classical to Quantum Model of Computation

The Deutsch-Josza Algorithm in NMR

More advanced codes 0 1 ( , 1 1 (

Orthogonality and Algebraic Lambda-Calculus

Ph 219b/CS 219b. Exercises Due: Wednesday 21 November 2018 H = 1 ( ) 1 1. in quantum circuit notation, we denote the Hadamard gate as

LINEAR ALGEBRA - CHAPTER 1: VECTORS

Quantum gate. Contents. Commonly used gates

Common Core Algebra Regents Review

LECTURE NOTES ON QUANTUM COMPUTATION. Cornell University, Physics , CS 483; Spring, 2005 c 2006, N. David Mermin

Describing Quantum Circuits with Systolic Arrays

Quantum Query Algorithm Constructions for Computing AND, OR and MAJORITY Boolean Functions

Introduction into Quantum Computations Alexei Ashikhmin Bell Labs

Lecture 11 September 30, 2015

CSCI 2570 Introduction to Nanocomputing. Discrete Quantum Computation

arxiv:quant-ph/ v1 16 Jul 2003

Instantaneous Nonlocal Measurements

X row 1 X row 2, X row 2 X row 3, Z col 1 Z col 2, Z col 2 Z col 3,

Quantum parity algorithms as oracle calls, and application in Grover Database search

Quantum Computing Lecture 3. Principles of Quantum Mechanics. Anuj Dawar

QUANTUM ARTHUR MERLIN GAMES

Lecture 3: Constructing a Quantum Model

ICS141: Discrete Mathematics for Computer Science I

Stochastic Processes

Transcription:

Automatic Parallelisation of Quantum Circuits Using the Measurement Based Quantum Computing Model Einar Pius August 26, 2010 MSc in High Performance Computing The University of Edinburgh Year of Presentation: 2010

Abstract The main focus of this work is to implement a program that can be used to parallelise quantum circuits. This is done by translating the quantum circuits to the Measurement Based Quantum Computing (MBQC) model, applying a number of optimising techniques to the computation MBQC, and by translating it back to a quantum circuit. As a side result of implementing this method, a new algorithm for creating and optimising an MBQC graph from a quantum circuit is designed. The implemented program is used to investigate quantum circuits known from the literature: the QFT, and a specific type of "staircase" circuits. We show that our program will parallelise the "staircase" circuit to logarithmic depth, and increase the depth of QFT by a logarithmic factor. Finally, three new classes of quantum circuits are presented: the Toffoli staircase circuit, the Toffoli + CNOT staircase circuit, and a circuits consisting of quantum gates Z, CNOT, ω, Z(α), and J( π 2 ). In the computational experiments we perform, those classes of circuits will benefit from the parallelisation method implemented in this dissertation.

Contents 1 Introduction 1 2 Background 3 2.1 Quantum Computing........................... 3 2.2 The Quantum Circuit Model....................... 4 2.2.1 The QFT............................. 5 2.3 The MBQC model............................ 7 2.3.1 The Measurement Pattern.................... 7 2.3.2 From the Quantum Circuit to the MBQC Pattern........ 9 3 Methods 10 3.1 Optimisations in the MBQC Model.................... 11 3.1.1 Standardisation.......................... 11 3.1.2 Pauli Simplification........................ 13 3.1.3 Signal Shifting.......................... 13 3.2 The Graph Representation of the MBQC Pattern............. 14 3.3 Creating the Optimised MBQC Graph.................. 17 3.3.1 Adding a Z Gate to the MBQC Graph............. 18 3.3.2 Adding a J(α) Gate to the MBQC Graph............ 19 3.3.3 The Algorithm for Building the MBQC Graph......... 25 3.3.4 An Example of an MBQC Graph................. 30 3.4 From an MBQC Graph to a Quantum Circuit.............. 31 3.5 Optimising the Quantum Circuit..................... 33 4 Implementation 35 4.1 Development Infrastructure........................ 35 4.1.1 The Qt Framework........................ 35 4.1.2 Project Hosting.......................... 36 4.1.3 Integrated Development Environments.............. 36 4.1.4 Building the Project....................... 36 4.2 Architecture................................ 39 4.3 Design................................... 41 4.3.1 The Back-end........................... 42 4.3.2 The Front-end........................... 44 4.4 Using the Program............................ 45 i

4.5 The Input File Format........................... 45 4.5.1 The Graphical Version...................... 46 4.5.2 The Console Version....................... 46 5 Verification 48 5.1 The Presence of casual flow in the MBQC Graph............ 49 5.1.1 The Method............................ 49 5.1.2 The Implementation....................... 49 5.1.3 The Results............................ 50 5.2 The Verification of the MBQC Graph.................. 51 5.2.1 The Method............................ 51 5.2.2 The Implementation....................... 51 5.2.3 The Results............................ 52 6 Results and Analysis 53 6.1 A Parallelisable Set of Gates....................... 53 6.2 The Staircase Structure.......................... 55 6.3 The Toffoli Staircase........................... 56 6.4 QFT.................................... 59 7 Conclusions and Further Work 61 7.1 Conclusions................................ 61 7.2 Further Work............................... 62 Bibliography 65 ii

List of Tables 3.1 The modifications to the graph depending on the angle α of the added J(α) gate.................................. 23 iii

List of Figures 2.1 An example quantum circuit........................ 4 2.2 Calculating the depth of the quantum circuit................ 4 2.3 Common Quantum Gates......................... 6 2.4 The quantum circuit of a n qubit QFT algorithm............. 7 2.5 Qunatum circuit of QFT 2......................... 7 3.1 An MBQC graph before adding a J(α) gate................ 20 3.2 An MBQC graph after adding a J(α) gate................. 21 3.3 An MBQC graph after moving the entanglement command........ 21 3.4 Signal shifting on the MBQC graph.................... 22 3.5 The structure of theqft 2 MBQC graph.................. 30 3.6 The dependencies in the QFT 2 MBQC graph............... 31 3.7 The optimised circuit of QFT 2....................... 32 3.8 The structure of the optimised circuits................... 33 4.1 The initial architecture of the program................... 39 4.2 The final architecture of the program................... 40 4.3 The design of the back-end......................... 42 4.4 The UML class diagram of the front-end................. 44 4.5 The design of the GUI interface...................... 45 4.6 The interactions in the front-end...................... 46 5.1 A verifiable quantum circuit........................ 52 6.1 The structure of the optimised Z, CNOT, ω, Z(α), and J( π 2 ) quantum circuit................................. 53 6.2 The staircase circuit............................ 55 6.3 The Toffoli gate............................... 56 6.4 The Toffoli staircase circuit........................ 56 6.5 The depth of the Toffoli staircase circuit.................. 57 6.6 The number of qubits in the Toffoli staircase circuit............ 57 6.7 The Toffoli + CNOT staircase circuit................... 58 6.8 The depth of the Toffoli + CNOT staircase circuit............. 58 6.9 The number of qubits in the Toffoli + CNOT staircase circuit....... 59 6.10 The depth of the quantum circuits implementing the QFT algorithm... 60 iv

Acknowledgements I would like to thank my supervisors Dr. Chris Maynard and Dr. Elham Kashefi for their advice and supervision during the project. I would also like to thank my colleague and friend Vedran Dunjko for reading the drafts of my work and giving me feedback ot.

Chapter 1 Introduction Due to physical constraints in current technology, the state of qubits (quantum bits) can remain stable for only short time. Over longer time, qubits will spontaneously change their states. This means that the algorithms run on a quantum computer will have to finish in short time. This has motivated research in simplifying quantum algorithms, and their representations as quantum circuits. To simplify quantum circuits Iwama and Yamashita [1] provided transformation rules to reduce the cost of quantum circuits that consist of n-qubit Toffoli gates. Their solution assigned a cost to every gate and transformed the circuit to an equivalent circuit whose total cost was smaller. It is motivated by the fact that some gates are easier to implement on a physical system than others, and does not target the computational depth of the algorithms. In research on the quantum circuit depth, Cleve and Watrous [2] showed that calculating the approximate value of QFT can be parallelised to a quantum circuit with O(logn) sequential steps, where s the number of qubits. This research focused on one specific algorithm, not on generic quantum circuits. To optimise arbitrary quantum circuits, Maslov, Dueck, Miller, and Negrevergne [3] proposed and implemented a method that uses local optimisations. Their method uses predefined templates to replace non-optimal constructs in the circuit with more optimal ones. In tests, their primary goal was to reduce the gate count and then the depth of the quantum circuit. They applied their algorithm to quantum circuits known from literature and showed that their method was able to reduce the gate count and depth of quantum circuits. The downside of this method is that it requires a number of predefined templates that are used for optimisation and the results depend on those templates. Recently a novel technique [4] that uses the MBQC model was introduced by Broadbent and Kashefi. It is based on the algebraic framework for MBQC developed in [5]. Using this framework, they presented a technique to decrease the depth of a quantum circuit. Quantum circuits are translated to the MBQC model. After that a number of optimising transformations are applied. After the optimisations, the MBQC model is translated 1

back to a quantum circuit. This will result in a new quantum circuit that is equivalent to the first one. The new circuit may have a smaller depth, but it can also have a larger depth. The main goal of this project is to create a program that would use the method described in [4] to parallelise quantum circuits. Thus we must translate quantum circuits to MBQC, optimise them in the MBQC model and translate them back to quantum circuit model. In additional to the optimisations in the MBQC model, we have to apply optimisations to the quantum circuit we get from the MBQC model. The methods we use to accomplish that are described in chapter 3. A new iterative algorithm that translates a quantum circuit to the MBQC model and performs the MBQC optimisations is described in chapter 3.3. This algorithm is based on an algorithm with O(n 5 ) runtime described in [5]. Here s the number of qubits that the quantum computation will have in the MBQC model. Our algorithm does not perform the exact same computation as the one described in [5], but it is faster. In particular, the runtime for our algorithm is O(n 3 ). The difference between the algorithms is that our algorithm takes a quantum circuit as anput, wherein [5] an MBQC patters used as anput. We assume that the reader has familiarity with quantum computing, quantum circuits, and the MBQC model, hence we give only a brief summary of those topics in chapter 2. The equations and definitions we use in our work are presented in those chapters. An-depth description of quantum computing and quantum circuits can be found in textbooks [6, 7], and the MBQC model is described in [4, 5]. The implementation of the program is discussed in chapter 4. In addition to describing the architecture and design of the program, a reference on how to use the implemented program is provided. We do not present an-depth description of the code, the descriptions of the classes and methods in the implementation can be read from the source code comments. The adjustments we had to make to the initial architecture and design are also mentioned in this chapter. In the verification chapter 5 we show that the program implemented does what we promise. The results of applying the program on different circuits, known from the literature, are presented in chapter 6. We introduce three classes of circuits that can be parallelised with the method implemented by our program. We did not find a previously existing parallelisation method for these circuits. We thus show that the program can be used to study if a certain class of circuits is parallelisable or not. It is shown, that the result we get by trying to parallelise the QFT algorithm corresponds to the most general case, where the depth of the circuit should increase by a O(logn) factor. Finally conclusions from this project are presented in chapter 7 along with some ideas about possible further work. 2

Chapter 2 Background This chapter gives a brief introduction to quantum computing and the two models we use in this work: the quantum circuit model and the MBQC model. An-depth description of quantum computing and the quantum circuit model can be found in the textbooks [6, 7]. The aspects of MBQC that are relevant to this work can be found in [4, 5]. 2.1 Quantum Computing The analogue of the classical bit in quantum computing is the qubit. A qubit corresponds to a two-dimensional quantum mechanical system. The state of a qubit can be represented by an unit vector in two-dimensional complex Hilbert space H. We can choose an orthonormal basis in this space and label the basis vectors as 0 and 1. Then the general state of a qubit is: α 0 + β 1 (2.1) where α and β are complex coefficients and α 2 + β 2 = 1. The { 0, 1 } basis for the state of a qubit is called the computational basis. The state of a qubit is changed by applying unitary operators ot. A n-qubit state is an unit vector in the n-fold tensor product space H 1 H 2 H n. The 2 n basis states of this space are the n-fold tensor products of the states 0 and 1. We write 0 0 as 0 0. With these basis states, a n-qubit state φ is a 2 n dimensional complex unit vector φ = i {0,1} n α i i (2.2) 3

2.2 The Quantum Circuit Model In the quantum circuit model quantum computations are represented as quantum circuits. The qubits are represented as horizontal wires, unitary operators are represented as gates acting on a number of wires. A generic quantum circuit can be seen figure 2.1. Computations represented by quantum circuits are executed by applying quantum gates from left to right until all the gates have been applied. q 1 q 2 q 3 q 4 o 1 o 2 o 3 o 4 Figure 2.1 A generic quantum circuit. Each horizontal line represents a "wire". Each wire represents a qubit in the computation performed by the quantum circuit. q 1, q 2, q 3, and q 4 are the initial states of the qubits represented by the wires. o 1, o 2, o 3, o 4 are the output states of those qubits. The rectangles on the wires represent quantum gates. Gates can be applied to any number of wires. 1. 2. 3. 4. 5. 6. 7. q 1 q 2 q 3 q 4 o 1 o 2 o 3 o 4 Figure 2.2 Calculating the depth of the quantum circuit. The depth of this particular circuit is 7. We assume that applying a gate to the qubits in the circuit takes one discrete time step, and that gates acting on distinct qubits can be applied in parallel. Then we can divide quantum circuits to a number of horizontal slices, so that executing each step takes 4

exactly one time step. This is shown figure 2.2. The number of such slices in a circuit is the depth of that quantum circuit. We can also estimate the depth of an uniform family of quantum circuits as a function of the number of input qubits. For example if we say that a quantum circuit has logarithmic depth, then we mean that the number of discrete time steps it takes to evaluate the circuit increases logarithmically corresponding to the problem size, and we write that the depth of the circuit is O(logn). Some of the most common one and two qubit quantum gates are presented in figure 2.3. All the gates used in this work are either present in this figure or are introduced immediately before they are used. Every computation realizable by quantum circuits can be implemented by using only a small set of different gates. We call such a set a universal set of gates. Definition 2.2.1 A set of gates is said to be universal, if for any integer n 1, any n- qubit unitary operator can be expressed by a quantum circuit using only a finite number of gates from that set. The methods we use in this work require that all quantum circuits are written using only J(α) and Z gates. As these gates form a universal set of quantum gates [8], every quantum circuit can be implemented using only those two gates. 2.2.1 The QFT We will use the QFT algorithm throughout this work as an example, therefore we define it in this chapter. QFT is the quantum analogue of the discrete Fourier transform (DFT) algorithm. For a given dimension n the DFT is a linear function mapping the vector (a 0,a 1,...,a n 1 ) in C n to the vector (b 0,b 1,...,b n 1 ), where b x = n 1 (e 2πi y=0 n ) x y a y (2.3) QFT is an unitary operator that maps the quantum state n 1 x=0 α x x to the quantum state n 1 x=0 β x x, where β x = 1 n n 1 (e 2πi y=0 n ) x y α y (2.4) Throughout this work we use QFT m to denote the QFT algorithm on m qubits. In equation (2.4) s the number of orthogonal basis states. For a m qubit quantum system this number is 2 m, thus for QFT m we have n = 2 m in equation (2.4). The quantum circuit of QFT m is shown figure 2.4. As in this work we allow only circuits consisting of J(α) and Z gates we also present the QFT 2 algorithm that is written using only those two gates in figure 2.5. 5

The gate name The identity gate The Pauli X gate The Pauli Y gate The Pauli Z gate The arbitrary phase rotation gate The phase rotation gate The Hadamard gate The J gate The gates symbol and its unitary matrix I = X = Y = ( ) 1 0 0 1 ( ) 0 1 1 0 ( ) 0 i i 0 ( ) 1 0 Z = 0 1 ( ) 1 0 Z(α)= 0 e iα P = ( ) 1 0 0 i H = 1 ( ) 1 1 2 1 1 J(α)= 1 ( ) 1 e iα 2 1 e iα 1 0 0 0 CNOT = 0 1 0 0 The CNOT gate 0 0 0 1 0 0 1 0 1 0 0 0 Z = 0 1 0 0 The control-z gate 0 0 1 0 0 0 0 1 1 1 1 1 ω = 1 1 1 1 1 The ω-gate 2 1 1 1 1 1 1 1 1 1 0 0 0 The control-phase gate R n = 0 1 0 0 0 0 1 0 0 0 0 e 2πi 2 n Symbol used in quantum circuits X Y Z Z(α) P H J(α) R n Figure 2.3 Some of the most common one and two qubit quantum gates. 6

q 1 H R2 Rn q 2 H R2 Rn-1 q n 1 H R2 q n H Figure 2.4 The quantum circuit of a n qubit QFT algorithm. 1 J(0) J(pi/4) J(0) 2 J(-3pi/4) J(0) J(-pi/4) J(0) J(pi) Figure 2.5 A quantum circuit for QFT 2 that uses only J(α) and Z gates. 2.3 The MBQC model The MBQC model is a model of quantum computing where the quantum state is changed by performing measurements on some qubits and applying corrections based on the outcome of these measurements. A detailed description of the MBQC model is available in [5]. We present a short summary of the aspects of MBQC that we use in our work and it is based on [5, 4]. In this chapter we describe how computations in MBQC can be represented as measurement patterns. Later in chapter 3.2 we show how we represent the MBQC patterns as graphs in our work. In MBQC one qubit measurements are done on a preprepared entangled quantum state. The outcome of these single qubit measurements is probabilistic. To make computations deterministic, the measurement results are used to change the measurements on some other qubits through local corrections. 2.3.1 The Measurement Pattern An MBQC patters defined as P = (V,I,O,A), where V is the set of qubits, I V the set of input qubits, O V the set of output qubits and A a finite set of commands acting on V. The patters written, as a sequence of commands, of which there are five different types. When performing a computation the commands are applied from right to left, until all of the commands have been performed. Thus throughout this work, the beginning of the patters its right end and the end of the patterts left end. We explain those five command types and describe a few basic relations between them. The preparation command N i prepares the qubit i into state + = 1 2 ( 0 + 1 ). A preparation command is applied to all of the non-input qubits. We omit these commands from the pattern and assume that this command is implicitly applied to non-input qubits before they are used. 7

The command E i j applies the Z gate to the qubits i and j. As Z is a symmetric operation, we have And because Z is its ownverse operation: E i j = E ji (2.5) E i j E ji = I (2.6) The measurement operation Mi α one of the following states: is defined as a orthogonal projection of qubit i onto + α = 1 2 ( 0 + e iα 1 ) α = 1 2 ( 0 e iα 1 ) followed by a partial trace of the system over the measured qubit. All non-output qubits in a measurement pattern are measured. We denote the classical outcome of the measurement on qubit i as s i Z 2. We define s i = 0 if the measurement outcome of the command Mi α was + α, and s i = 1 if it was α. The measurement outcomes can be summed together modulo 2, and the sums of measurement outcomes are called signals. A measurement can depend on other measurements through signals. A dependent measurement can depend on two signals, t and s: t [M α i ] s = M ( 1)s α+tπ i (2.7) To calculate the signals, all the measurement results that appear in the signals t and s need to be known. This means that all those measurements must be performed before the dependant measurement. There are two one qubit Pauli correction commands: Xi s and Zi s. These commands apply the Pauli X and Z gates to qubit i if the signal s = 1 and do nothing if s = 0: Xi 1 = X i (2.8) Zi 1 = Z i (2.9) X 0 i = Z 0 i = I i (2.10) The correction operators are used to make the computation deterministic by countering undesired measurement outcomes. The outcome of a single qubit measurement in MBQC is random. The correction operators are used to change the state of the system so, that after measuring 1 it would be the same as if the outcome would have been 0. Thus although the measurement outcomes are random, the computatios kept deterministic through corrections. 8

The correction commands relate to the dependant measurement command in the following way [5]: t [Mi α ] s Xi r = t [Mi α ] s+r (2.11) t [Mi α ] s Zi r = t+r [Mi α ] s (2.12) Mi α Xi s Zi t = t [Mi α ] s (2.13) We use [[P]] to denote the quantum computation realised by an MBQC pattern P. 2.3.2 From the Quantum Circuit to the MBQC Pattern We can create a pattern that realises a computation that is equal to a computation the quantum circuit model by adding command sequences that equal the gates to the pattern. The MBQC patterns realising a J(α) and Z gate are following:[5]: J(α) = X 2 M1 α E 1,2 (2.14) Z 1,2 = E 1,2 (2.15) In equation (2.14) qubit 1 in the patters the output qubit that corresponds to the wire the J(α) gate acts on, and qubit 2 is a new qubit for the pattern. As an example, we present the measurement pattern for the quantum circuit of QFT 2, shown the figure 2.5. The patters obtained by using the rules (2.14) and (2.15): QFT 2 =X 9 10 M π 4 9 E 9,10 X 2 9 M 0 2 E 2,9X 7 8 M π 7 E 7,8 X 6 7 M0 6 E 6,7 E 2,6 X 5 6 M π 4 5 E 5,6 X 4 5 M0 4 E 4,5 (2.16) E 2,4 X 3 4 M 3π 4 3 E 3,4X 1 2 M 0 1 E 1,2 9

Chapter 3 Methods The procedure we implemented in our program to parallelise the quantum circuits is following: Translate the quantum circuit to the MBQC model. Perform the following optimisations on the computation the MBQC model: Standardisation Signal shifting Pauli simplifications Translate the computation from the MBQC model back to the quantum circuit model. Use optimisations described in [9] to reduce the depth of CNOT and Z gate blocks from O(n) to O(logn). The optimisations we apply to the computation are defined for the MBQC pattern. There are three different techniques that we use in MBQC model to optimise the pattern: standardisation, signal shifting, and Pauli simplifications. These optimisations are defined for the MBQC patterns as a set of rewrite rules, and an-depth description of them can be found in [4] and [5]. We use a graph to represent the MBQC pattern computations in our program, and thus we will describe the effects these optimisations have on the underlying graph. The actual MBQC pattern optimisations are implemented as modifications to the graph and are merged into one algorithm with the creation of the MBQC graph. First we describe the three optimisations we perform on the MBQC pattern. Then we explain how we construct the optimised MBQC graph, and finally we show how to convert it back to a quantum circuit and describe the optimisations on that quantum circuit. As we have three different quantum circuits during the parallelisation process that our program performs, we will use the following notation to distinguish them: 10

original circuit - The unoptimised quantum circuit given as the input to the program. optimised circuit - The quantum circuit that we get after translating the MBQC graph to the circuit model. parallelised circuit - The quantum circuit that we get after we apply the parallelisation techniques described in this chapter to the optimised circuit. This is the output of our program. 3.1 Optimisations in the MBQC Model 3.1.1 Standardisation A patters said to be in standard form if all the entanglement operations are at the beginning of the pattern, followed by all the measurement operations, and the correction operations are at the end of the pattern. For moving the entanglement command to the beginning of the pattern, we have the following rewrite rules: [5] : E i j Xi s Xi s Z s je i j (3.1) E i j Zi s Zi s E i j (3.2) E i j A k A k E i j (3.3) where A is not an entanglement command and k represents a set of qubits acted on by A, and does not contai and j. The following commutativity rules allow us to move the correction commands to the end of the pattern:[5]: A k X s i X s i A k (3.4) A k Z s i Z s i A k (3.5) where A is an arbitrary command and k represents qubits acted on by A, and does not contai. In [4] and [5] it was an additional requirement that A would not be a correction command. This was required to obtain termination for the standardisation algorithm, but for our algorithm, introduced in chapter 3.3, we have to allow the correction rules to commute. We also note that the X i and Z i correction commute in the pattern evef they are applied to the same qubit: X s i Z t i = Z t ix t i (3.6) 11

This holds because ( )( ) ( ) 0 1 1 0 0 1 XZ = = 1 0 0 1 1 0 ( )( ) ( ) 1 0 0 1 0 1 ZX = = 0 1 1 0 1 0 (3.7) (3.8) (3.9) Operators XZ and ZX differ only by a global phase, and because in quantum computing the global phase of an one qubit unitary operator is physically insignificant the commutation rule (3.6) holds. Equation (2.13) can be used to merge the X and Z corrections on a qubit to its measurement. After merging all the corrections to the measurement command ots qubit we are left with only corrections on the output qubits, and those can be moved to the end of the pattern using the commutativity of the correction commands (3.4), (3.5). A measurement pattern P = (V,I,O,A) in the standard form can be written as: P = CME (3.10) where C is the operator that performs all the X and Z corrections, M is the operator that performs all the measurement commands and E is the operation that performs all the entanglement commands. C, M, and E are also allowed to be empty. In a standardised pattern all the corrections are done on the output qubits. We want to write the standardised MBQC pattern so, that the corrections on some particular output qubit are the last commands in the pattern. This will be used in chapter 3.3 to help us define how to add gates to patterns. Due to the commutativity of the correction commands (3.4), (3.5), we can move the corrections on some output qubit o i to the left of the pattern, and because of equation (3.6) we can always write them so that the Z oi correction appears before the X oi correction. We write C(O) to mark the operator that performs all the corrections X and Z corrections on qubits in the set O. We mark the corrections on all the output qubits except qubit o i as C(O\{o i }) and have the following equivalence: Thus we can write a standardised MBQC pattern as: C(O) = X s o i o i Z t o i o i C(O \ {o i }) (3.11) P = CME = = C(O)ME = (3.12) = X s o i o i Z t o i o i C(O \ {o i })ME The above equation holds evef qubit o i does not belong to pattern P or P is an empty pattern, i.e. o i / O: P = C(O)ME = = I oi C(O)ME = (3.13) = X 0 o i Z 0 o i C(O \ {o i })ME 12

We will use this form as a convenience when describing the algorithm that translates the quantum circuits to MBQC computations. 3.1.2 Pauli Simplification We say that a measurement is a Pauli X measurement when the measurement angle is α = 0 and a Pauli Y measurement if the measurement angle is α = π 2. Pauli simplification allows us to perform Pauli X and Y measurements on the first step of the computation. When there is a Pauli X measurement in the pattern, we can remove the X correction dependencies from the qubit according to equation (3.14). When a Pauli Y measurement is performed on a qubit, the X correction dependencies can be changed to Z correction dependencies according to equation (3.15). The Z correction dependencies can afterwards be moved to the end of the pattern by a process called signal shifting, defined in the next section. The equations describing Pauli simplifications are following [5]: An from equation (2.13) we get: M 0 i X s i = M 0 i (3.14) M π 2 i X s i = M π 2 i Z s i (3.15) t [M 0 i ] s = t [M 0 i ] (3.16) t [M π 2 i ] s = s+t [M π 2 i ] (3.17) If all possible Pauli simplifications have been performed on an MBQC patern P, then there are no X corrections on qubits whose measurement angle is α = 0 or α = π 2. 3.1.3 Signal Shifting It is possible to move all the Z corrections on measured qubits to the end of a pattern. This process is called signal shifting and the rewrite rules used for signal shifting are following [5]: t [M α i ] s S t i [M α i ] s (3.18) t [M α j ] s S r i S r i t[(r+s i)/s i ] [M α j ] s[(r+s i)/s i ] (3.19) X s j S r i S r i X s[(r+s i)/s i ] j (3.20) Z s js r i S r i Z s[(r+s i)/s i ] j (3.21) where s[(r + s i )/s i ] denotes substitution of s i with r + s i in signal s. The Si r is the signal shifting command and is used to move the signal to the left of the MBQC pattern. In a signal shifted pattern, the Z corrections are applied only to the output qubits. 13

3.2 The Graph Representation of the MBQC Pattern This project requires the implementation of the quantum computations in the MBQC model. In particular the computations should be represented as MBQC patterns as the optimisations that we have to use are defined for the MBQC patterns. To represent the patterns a graph is used. For our purposes, it will suffice if the graph can represent only standardised MBQC patterns. Definition 3.2.1 A standardised MBQC pattern graph is a tuple G = (V,I,O,E,M,S,T ) where: V is the set of vertices in G. Each vertex represents a qubit. I V is the set of input vertices. O V is the set of output vertices. E is the set of edges in G. M is the set representing measurements angles for vertices in V. S is a set of sets of vertices that represents X correction dependencies on each vertex v V. T is a set of sets of vertices that represents Z correction dependencies on each vertex v V. We say that a vertex v depends on another vertex w if a X or Z correction has to be performed on the qubit represented by v, depending on the measurement performed on the qubit represented by w. We will call the standardised MBQC pattern graph just MBQC graphs in this work. The sets S and T determine on which other vertices a vertex v V depends on. v can be measured if every vertex in S T has been measured. In MBQC model any number of measurements can be done in parallel as long as the measurements they depend on have been performed. The earliest computational step a measurement can be done can be found using algorithm 1 - CalculateLayer. A layer is a set of vertices in an MBQC graph, where the earliest step a vertex can be measured is the same for each vertex in the layer. The algorithm 1 thus recursively finds the layer of each other vertex a vertex depends on, and sets its layer to the maximum of those plus one. If the vertex does not depend on any other vertices, it can be measured at first step and thus belongs to layer one. The symmetric difference of two sets A and B is written as A B and defined as the set of elements that are in either A or B but not in both. It can be written by using the union, intersection, and difference operations: A B = (A B) \ (A B) (3.22) We say that an MBQC graph G = (V I,O,E,M, S,T ) is equivalent to a standardised MBQC pattern P = (V,I,O,A), if the following relations between them are true: 14

Algorithm 1: CalculateLayer(v) Data: A standardised MBQC pattern graph G = (V, I, O, E, M, S, T ). Input: A vertex v V. Output: The layer of vertex v. 1 begin 2 layer 1; 3 // The recursion will terminate if S v T v is empty; 4 for d S v T v do 5 layer max(layer,calculatelayer(d) + 1); 6 return layer; The sets of vertices, inputs vertices, and output vertices of G and P are equal: V = V (3.23) I = I (3.24) O = O (3.25) The entanglement commands of P correspond to the edges in G: E = E i1 j 1 E i2 j 2 E ik j k E = E i 1 j 1 E i 2 j 2 E i k j k (3.26) The entanglement command is its ownverse (equation (2.6)), and using the symmetric difference will implicitly remove edges that are represented even number of times in the graph, leaving at most one edge between two vertices. The measurement angles of P are stored in the set M : M α q M q = α, q V \ O (3.27) The X correction signal on qubit q in pattern P is represented as a symmetric difference in graph G. X s 1+s 2 + +s m q S q = s 1 s 2 s m, q V (3.28) The Z correction signal on qubit q in pattern P is represented as a symmetric difference in graph G. Z t 1+t 2 + +t m q T q = t 1 t 2 t m, q V (3.29) Equations (3.23) - (3.29) allow us to directly create the MBQC graph from the pattern. Creating the pattern from the graph needs some additional information, because these equations do not give the order of execution for the pattern commands. As the patters a standardised pattern, the entanglement commands should be the first ones. The order 15

of the other commands can be obtained by ordering the graphs vertices by their layer in ascending order and using equations (3.27) - (3.29) to create the commands. The order of the commands for qubits in the same layer does not matter, as these measurements do not depend on each other and thus commute. The graph can represent only standardised MBQC patterns because in equation (3.26) we assume that all the entanglement commands have been moved to the beginning of the pattern. This is enough for our purpose, as we will see in the next section. 16

3.3 Creating the Optimised MBQC Graph We define an optimised pattern as a standardised, signal shifted, and Pauli substituted pattern and the graph representing an optimised pattern as an optimised graph. Note that an empty pattern, i.e. a pattern with no commands, is trivially also an optimised pattern. As an example for an optimised pattern, we once again use QFT 2 : QFT 2 =X10 1+9 Z2+5 10 X 8 2+5+7 Z8 4+6 M9 0 [M π 7 ] 4+6 M6 0 [M π 4 5 ] 1+4 M4 0 M 3π π 4 3 [M 4 2 ] 1 M1 0 (3.30) E 9,10 E 2,9 E 7,8 E 6,7 E 2,6 E 5,6 E 4,5 E 2,4 E 3,4 E 1,2 It is easy to verify that the pattern (3.30) is an optimised pattern. First, all the entanglement commands are at the beginning, measurements in the middle, and the corrections at the end. Thus the patters in the standard form. Second, there are no Pauli simplifications that can be performed. Finally, no more signal shifting rules can be applied to the pattern. Thus pattern (3.30) is an optimised pattern. The MBQC graph corresponding to this patters presented later in chapter 3.3.4. Definition 3.3.1 If there exists a quantum circuit that realizes the same computation as an MBQC pattern P, and if P g is the MBQC pattern of a quantum gate g, then we say that pattern P is obtained by adding the gate g to pattern P, if [[P ]] = [[P g P]]. Definition 3.3.2 If P is the MBQC pattern of an optimised graph G and P is the MBQC pattern of an optimised graph G, then we say that G is obtained by adding a gate g to G, if P is obtained by adding the gate g to P. We design aterative algorithm for creating a optimised MBQC graph G from a quantum circuit QC. We start with an empty graph and add gates from the circuit QC to the graph G in the order they should be applied in the circuit. After all the gates from QC are added to G, the graph G will realize a quantum computation that is equivalent to the computatiomplemented by the circuit QC. We allow only J(α) and Z gates in our input circuit, these gates form a universal set of gates, and are sufficient for creating every possible quantum computation. Thus it is enough to examine the addition of only those two gates to the pattern. This method would give us an algorithm for constructing an optimised pattern, but we have to represent it in the graph form we use. The graph modifications that are required for building the optimised graph, can be easily read from the changes in the pattern, after a gate addition. The following sections describe the changes in the pattern that occur, if we add a sequence of commands to it that corresponds to J(α) or Z gate, and then optimise the new pattern. From those changes we derive the modifications to the original graph, representing the initial pattern. We then get a graph corresponding to the new optimised 17

pattern. As the graph is optimised, we can add another gate to it using the same method, and repeat that for all the gates in the circuit. When extending the pattern (and graph), it is always assumed, that the original pattern (and graph) is already optimised. 3.3.1 Adding a Z Gate to the MBQC Graph Let P be an arbitrary optimised MBQC pattern and QC a quantum circuit that performs an computation equivalent to [[P]]. Let QC be a quantum circuit that is obtained by adding a Z i j gate to the end of QC. Then let O be the set of output qubits in P, o i the output qubit in pattern P, corresponding to wire i in QC, and o j the output qubit in pattern P that corresponds to wire j in QC. Using equation (3.13), we can write pattern P as: P = X s i o i Z t i o i X s j o j Z t j o j C(O \ {o i,o j })ME (3.31) Note that this holds evef pattern P is an empty pattern or does not originally contain qubits o i or o j. We can create a pattern P that performs the same computation as QC by adding the entanglement command E oi o j to the end of pattern P (2.15): P = E oi o j P = E oi o j X s i o i Z t i o i X s j o j Z t j o j C(O \ {o i,o j })ME (3.32) And using equations (3.1), (3.2), and (3.3) the entanglement command E oi o j moved next to the entanglement operator E. can be P = X s i o i Z t i+s j o i X s j o j Z t j+si o j C(O \ {o i,o j })ME oi o j E (3.33) It is easy to see, that if pattern P is optimised, then the pattern P in (3.33) is also optimised. We did not change the measurement commands, this means that if P was optimised P is signal shifted and Pauli simplified. As the measurements are in the middle, corrections at the end, and entanglements at the beginning, pattern P is in the standard form and thus optimised. Let G = (V,I,O,E,M,S,T ) be the MBQC graph, as defined in chapter 3.2, that represents the computation performed by pattern P, and G = (V,I,O,E,M,S,T ) the graph for pattern P. As our application uses the graph representation to store the computations, we are interested in how do we have to modify graph G to get graph G. First we should ensure that both vertices o i and o j are in the graph. Then, as we can see from (3.33), when adding the entanglement command E oi o j to the pattern P, we have to modify the Z correction dependencies on vertices o i and o j. The entanglement operator E oi o j itself is represented as an edge between o i and o j. If equation (3.31) shows the 18

pattern P and (3.33) the pattern P, then according to equations (3.23) - (3.29) the graph G should be modified the following way to get the graph G : V = V {o i,o j } (3.34) I = I ({o i,o j } \V ) (3.35) O = O {o i,o j } (3.36) E = E {E oi o j } (3.37) T o i = T oi S o j (3.38) T o j = T o j S oi (3.39) Only the elements that in G differ from the elements in G are presented. Equation (3.34) guarantees that the vertices representing the qubits o i and o j are in the graph G and equation (3.36) that they are in the set of output vertices. Equation (3.35) has the effect of adding o i and o j to the set of input vertices in G if they previously did not belong to belong to G. Equations (3.38) and (3.39) deal with the changes in the Z correction dependencies and equation (3.37) adds an edge to the graph. We also present the operation of adding a Z gate to an MBQC graph as an algorithm: Algorithm 2: AddControlZGate(i, j,g) Input: i and j - the wires in quantum circuit on which a Z gate acts on, and an optimised MBQC graph G = (V,I,O,E,M,S,T ). Output: The input graph G with an added Z i j gate. 1 begin 2 create vertices o i and o j ; 3 create edge E oi o j ; 4 I I ({o i,o j } \V ); 5 V V {o i,o j }; 6 O O {o i,o j }; 7 E E E oi o j ; 8 T [o i ] T [o i ] S[o j ]; 9 T [o j ] T [o j ] S[o i ]; 10 return G; 3.3.2 Adding a J(α) Gate to the MBQC Graph Let P be an arbitrary optimised MBQC pattern and QC a quantum circuit that performs a computation equivalent to P. Let O be the set of output qubits in P, o i the output qubit in pattern P that corresponds to wire i in QC, and QC a quantum circuit that can be obtained by adding a J(α) gate, acting on qubit i, to the end of QC. We allow P to be any optimised pattern, even a empty one, and thus QC can be an empty circuit. According to equation (3.13), the pattern P can be written as: 19

T oi Rest of the graph o i S oi Figure 3.1 An MBQC graph before we add a J(α) gate that acts on wire i. P = X s o i o i Z t o i o i C(O \ {o i })ME (3.40) The MBQC graph corresponding to the original pattern P can be drawn as shown figure 3.1. As the modifications we perform will only affect one existing vertex, we focus on that vertex on the figures. We can create a pattern P that performs the same computation as QC by first adding a new qubit to P, and then adding the commands, corresponding to the J(α) gate (2.14), to the end of pattern P. P = X o i M α o i E ni o i P = = X o i Mo α i E ni o i X s o i o i Z t o i o i C(o \ {o i })ME (3.41) The way we have to modify the graph corresponding to pattern P to get the MBQC graph of pattern P is shown figure 3.2. Equations (3.1), (3.2), and (3.3) can be used to move the entanglement command to the beginning of the pattern: P = X o i Mo α i X s o i o i Z s o i Z t o i o i C(O \ {o i })ME ni o i E (3.42) As can be seen from equation (3.42), moving the entanglement command to the beginning of the pattern will introduce Z corrections to vertex. This means that we also need to modify the underlying graph as shown figure 3.3. Now we use the commutativity of the Z correction (equation (3.5)) to move the Z correction on qubit to end of the pattern, past the measurement on qubit o i, and equation (2.13) to merge the correction commands on qubit o i with its measurement command. P = X o i Z s o i t oi [M α o i ] s o i C(O \ {o i })ME ni o i E (3.43) 20

T oi Rest of the graph -α E ni o i S oi S ni = o i Figure 3.2 An MBQC graph after we add a J(α) gate that acts on wire i. We have to add a new vertex and an edge between the new and old vertex. We represent output vertices as white circles and measured vertices as black circles. The black vertex is o i and α is the measurement angle of that vertex. Rest of the graph T oi -α E ni o i T ni = S oi S oi S ni = o i Figure 3.3 An MBQC graph with an added J(α) gate after moving the entanglement command in the pattern form to the beginning. 21

T oi T ni = S oi Rest of the graph -α E ni o i S oi S ni = T oi o i Figure 3.4 Performing signal shifting on an MBQC graph after adding a J(α) gate. Next we perform the signal shifting using equations (3.18) - (3.21). The changes to the underlying graph are shown figure 3.4 and are derived from the following equation: P = X o i Z s o i S t o i o i [M α o i ] s o i C(o \ {o i })ME ni o i E = S t o i o i X t o i +o i Z s o i [M α o i ] s o i C(O \ {o i })ME ni o i E (3.44) Adding a new gate to the pattern will not introduce additional dependencies, through signals, on qubit o i. Thus, after adding another Z or J(α) gate, the signal S t o i o i could always be shifted to the end of the pattern, without any effect to the other commands in the pattern. We will therefore omit S t o i o i and move command on qubit o i next to the other measurement commands. This can be done, because none of the corrections in C(O \ {o i }) act on qubit o i, and thus we can use the commutativity of the correction commands (3.4) and (3.5). P = X t o i +o i Z s o i C(O \ {o i })[Mo α i ] s o i ME ni o i E (3.45) If α = 0 we have a Pauli X measurement, and we should use the Pauli X simplification rule (3.14). We will do it after moving the entanglement command to the beginning of the pattern equation (3.42). We thus perform the following sequence of rewrites if α = 0: P = X o i Mo 0 i X s o i o i Z s o i Z t o i o i C(O \ {o i })ME ni o i E = = X o i Z s o i t oi [M 0 o i ]C(O \ {o i })ME ni o i E = = X o i Z s o i S t o i o i M 0 o i C(o \ {o i })ME ni o i E = (3.46) = S t o i o i X t o i +o i Z s o i M 0 o i C(O \ {o i })ME ni o i E = = X t o i +o i Z s o i C(O \ {o i })Mo 0 i ME ni o i E Similarly, if α = π 2, we have to use the Pauli Z simplification rule (3.17), and we will 22

General case Pauli X measurement Pauli Y measurement M o π i α 0 2 S o i S oi S n i T oi {o i } S oi T oi {o i } T o i T S oi E E {E oi } V V {o i, } O (O \ {o i }) { } I I ({o i } \V ) Table 3.1 The modifications to the graph depending on the angle α of the added J(α) gate. have the rewrite sequence: P = X o i M π 2 oi X s o i o i Z s o i Z t o i o i C(O \ {o i })ME ni o i E = = X o i Z s o i M π 2 oi Z s o i o i Z t o i o i C(O \ {o i })ME ni o i E = = X o i Z s o i s oi +t oi [M π 2 oi ]C(O \ {o i })ME ni o i E = = X o i Z s o i S s o i +t oi o i M π 2 oi C(o \ {o i })ME ni o i E = (3.47) = S s o i +t oi o i X s o i +t oi +o i Z s o i M π 2 oi C(O \ {o i })ME ni o i E = = X s o i +t oi +o i Z s o i C(O \ {o i })M π 2 oi ME ni o i E Because qubit o i is now measured, it is not an output qubit any more; instead, the added qubit is the new output qubit corresponding to the circuit wire i in QC. It is easy to verify, that if the original pattern P was optimised, then the final forms of pattern P in equations (3.45), (3.46), and (3.47) are indeed optimised patterns. First, they all have the correction commands at the end, measurements in the middle and entanglement commands at the beginning and are therefore in the standard form. Second, the added measurement does not have a t signal, and because P was optimised, neither do the measurements in M. Thus all of the three patterns are signal shifted. Finally, when α = 0 or α = π 2 (patterns (3.46) and (3.47)), the newly added measurements will have the signal s equal to zero, and therefore if P was optimised, the Pauli patterns (3.45), (3.46), and (3.47) are Pauli simplified. This means that all of the three possible final forms of pattern P are optimised patterns. Let G be the graph representing pattern P. The changes to pattern P, needed to get P, are easily readable from the optimised final forms (3.45), (3.46), and (3.47). From those changes, we can derive the modifications for the underlying graph G, needed to get the graph G that corresponds to pattern P. We need to make sure that vertices o i and are in the graph, add an edge between 23

them, set the measurement for o i and modify the sets S oi, S ni, T oi, T ni according to the correction signals for o i and in the pattern P. All those modifications are summarised in table 3.1. Algorithm 3 uses those modification rules and describes how to add a J(α) gate to an MBQC graph. Algorithm 3: AddJGate(i,α,G) Input: i the wires in quantum circuit on which a J gate with angle α as parameter acts on, and an optimised MBQC graph G = (V,I,O,E,M,S,T ). Output: The input graph G with an added J i (α) gate. 1 begin 2 create vertices o i and ; 3 create edge E oi ; 4 I I ({o i } \V ); 5 V V {o i, }; 6 O (O \ {o i }) { }; 7 E E E oi ; 8 M oi α; 9 S ni T oi {o i }; 10 T oi /0; 11 T ni S oi ; 12 // If the measurement is a Pauli X or Y measurement; 13 if M oi = 0 or M oi = π 2 then 14 // If the measurement is a Pauli Y measurement; 15 if M oi = π 2 then 16 S ni S ni S oi ; 17 S oi /0; 18 return G; 24

3.3.3 The Algorithm for Building the MBQC Graph We showed in the previous sections how to add J(α) and Z gates to an MBQC graph. We can now construct the algorithm for creating an MBQC graph realising the same computation as a quantum circuit. This is presented as algorithm 4. In the following sections we will analyse the space and time complexity of this algorithm. Algorithm 4: Creating an MBQC graph from a quantum circuit. Data: The gates of a quantum circuit C in a array GAT ES sorted by the order they are applied. Result: An MBQC graph G = (V, I, O, E, M, S, T ) implementing a computation that is equivalent to the computatiomplemented by circuit C. 1 begin 2 for gate GAT ES do 3 if gate is a Z gate then 4 i the first wire gate acts on; 5 j the second wire gate acts on; 6 G AddControlZGate(i, j, G) 7 else 8 // gate is a J(α) gate; 9 i the wire gate acts on; 10 α the parameter of gate; 11 G AddJGate(i,α,G); 12 return G; Space Complexity Let QC be a quantum circuit with n wires, k J(α) gates, and l Z gates, and let G = (V,I,O,E,M,S,T ) be the MBQC graph that is created with algorithm 4. The number of input vertices I and output vertices O of G is equal to the number of wires in QC, as the input and output size of the computation realised by G must be the same as in the circuit QC. The number of vertices will be equal to n + k as we need to add a measured non-output vertex for each J(α) gate, and we need n output qubits to read the output from. The number of edges in the MBQC graph will be a maximum of k + l, but might be less, as by adding a gate, we use the symmetric difference to add an edge to the 25

graph. Thus we have: I = n (3.48) O = n (3.49) V = n + k (3.50) E = O(k + l) (3.51) M = k (3.52) S = O( V I ) = O(k) (3.53) T = O( O ) = O(n) (3.54) S q = O( M ) = O(k) (3.55) T q = O( M ) = O(k) (3.56) where: s the number of wires in the input circuit QC. k is the number of J(α) gates in the input circuit QC. l is the number of Z gates in the input circuit QC. I is the number of input vertices in the MBQC graph G. O is the number of output vertices in the MBQC graph G. V is the number of vertices in the MBQC graph G. E is the number of edges in the MBQC graph G. M is the number of edges in the MBQC graph G that are measured. S is the number of vertices in the MBQC graph G that can have X corrections. Every non-input qubit can have a X correction. T is the number of vertices in the MBQC graph G that can have Z corrections. After signal shifting only output qubits will have Z corrections. S q is the maximum number of vertices on whose measurement outcome the X correction on a vertex can depend on. T q is the maximum number of vertices on whose measurement outcome the Z correction on a vertex can depend on. Knowing the sizes of each element we use to represent our graph, we can determine the total space required to hold this graph. V + I + O + E + M + S S i + T T i = =(n + k) + n + n + O(k + l) + k + O(k)O(k) + O(n)O(k) = (3.57) =O(n + k + l + k 2 + n k) = =O(l + n k + k 2 ) 26

Algorithm 4 and the functions AddZGate() (algorithm 2), and AddJGate() (algorithm 3) it uses do not use any temporary variables, thus the total space requirement of algorithm 4 is equal to the size of the final MBQC graph, and that is according to equation 3.57 O(l + n k + k 2 ). If the depth of the circuit QC is d, then the worst case the number of J(α) gates k, and Z gates l are: k = O(n d) (3.58) l = O(n d) (3.59) This corresponds to the case when a gate is applied to every wire on every step of the computation. Thus we can express the space complexity of our algorithm in accordance with the depth of circuit QC: O(l + n k + k 2 ) = O(n d + n 2 d = n 2 d 2 ) = O(n 2 d 2 ) (3.60) Time Complexity Let QC be a quantum circuit with n wires, k J(α) gates, and l Z gates, and let G = (V,I,O,E,M,S,T ) be the MBQC graph that is created with algorithm 4. This describes the same situation as the previous section, thus we will use the same notations for this section. Let the sets used in the algorithm be sorted sets. The union, difference and symmetric difference of two sorted sets can be done in O(logm) time if one of the sets is of constant size. Here m is the number of elements in the non-constant size set. If none of the two sets is of constant size, then these operations take O(min(m 1,m 2 )) time, where m 1 and m 2 are the number of elements in the two sets. First lets examine how much time it takes to add a Z gate to the graph. We can do this by examining algorithm 2. Creating the edge and vertices takes O(1) time, all the set operations until line 8 will have one operand with constant size, thus those operations take time as follows: Line 4: O(log V + log I ) Line 5: O(log V ) Line 6: O(log O ) Line 7: O(log E ) Thus the total time to execute lines 4-7 is: O(log V + log I ) + O(log V ) + O(log O ) + O(log E ) = =O(log V + log I + log O + log E ) 27

Neither of the operands on line 8 and 9 are of constant size, and the worst time taken to calculate these operations is: O(min( T q, S q )) + O(min( T q, S q )) = =O(min(O( M ), O( M ))) + O(min(O( M ), O( M ))) = =O( M ) The total runtime T Z for adding a Z gate to the graph G is therefore: T z =O(log V + log I + log O + log E + M ) (3.61) Algorithm 3 describes how to add a J(α) gate to the MBQC graph G. We can write down the run-times of the different operations just as for adding the Z gate: Line 2: O(1) (Creating an vertex takes the same constant time for every new vertex.) Line 3: O(1) (Creating an vertex takes the same constant time for every new edge.) Line 4: O(log V + log I ) Line 5: O(log V ) Line 6: O(log O ) Line 7: O(log E ) Line 8: O(1) (Assigning a constant number of items can be done in constant time. In this case we assign one element.) Line 9: O( T q + log T q ) = O( M ) (Copying a set takes linear time.) Line 10: O(1) (This is equivalent to removing all elements from a set, this can be done in constant time. (In the most naive implementation the size of the set can just be set to 0)) Line 11: O( S q ) = O( M ) (Copying a set takes linear time.) Line 16: O(min( S q, S q )) = O( S q ) = O( M ) Line 17: O(1) (Same as line 10) Adding it all together we get the runtime T J for adding a J(α) gate to graph G: T J = O(log V + log I + log O + log E + M ) (3.62) This is the same runtime as we got in equation (3.61) for adding a Z gate to the graph. 28

As we have k J(α) and l Z gates, the total runtime T of creating the graph G is: T = (k + l) O(log V + log I + log O + log E + M ) = = (k + l) O(log(n + k) + logn + logn + log(k + l) + k) = = (k + l) O(log(n + k) + log(k + l) + k) = = (k + l) O(logn + logl + k) = (3.63) = O(k logn + k logl + k 2 + l logn + l logl + kl) = = O(k logn + k 2 + l logn + l logl + kl) Here we used equations (3.48) - (3.52) to substitute the sizes of the elements in the MBQC graph with the parameters of the original circuit. If the depth of the circuit QC is d, then we can replace the number of of J(α) gates k, and Z gates l according to equations (3.58) and (3.59): T = O(k logn + k 2 + l logn + l logl + kl) = = O(n d logn + n 2 d 2 + n d logn + n d lognd + n 2 d 2 ) = (3.64) = O(n 2 d 2 ) This gives us a runtime that depends on the number of qubits n and the depth of the input circuit d as O(n 2 d 2 ). We can also express the runtime that it takes to construct the MBQC graph depending on the number of vertices in the final MBQC graph. In that case it would be useful to assume that no two Z gates that cancel each other out are added to the graph. Those could be replaced with the identity gate in the original circuit, before starting to construct the graph. Then the number of gates added to the graph will be E, as each gate will introduce, and never remove, an edge. The size of the graph elements depend on the number of vertices V as: Thus the runtime for the algorithm 4 is: I = O( V ) (3.65) O = O( V ) (3.66) E = O( V 2 ) (3.67) M = O( V ) (3.68) T = E O(log V + log I + log O + log E + M ) = (3.69) = O( V 2 ) O(log V + log V + log V + log V + V ) = (3.70) = O( V 3 ) This result is interesting because using the rewrite rules that we based our algorithm on (described in [4, 5]), optimising an MBQC pattern takes O(n 5 ) time. These rewrite 29

2 4 5 3 pi/4 0 pi/4 α Input vertex, measured with angle α 1 3 6 7 8 β Auxiliary vertex, measured with angle α 0 -pi/4 0 -pi Output vertex 9 10 0 Figure 3.5 The MBQC graph of QFT 2, as created by our algorithm, without the signal dependencies. rules are more powerful than our algorithm, because they can optimise any valid MBQC pattern, our algorithm works only on patterns that we could obtain from quantum circuits. Also the algorithms do not perform the same computation. Our algorithm takes a quantum circuit as anput, and outputs the MBQC graph corresponding to an optimised pattern. The algorithm in [5] takes an MBQC pattern as anput and outputs an optimised MBQC pattern. Nevertheless given an MBQC pattern realizing a quantum circuit as anput to the algorithm in [5], the output pattern would be equivalent to the pattern represented by the MBQC graph written out by our algorithm. 3.3.4 An Example of an MBQC Graph As an example of the graph that our algorithm creates, we present the MBQC graph of QFT 2. Figure 3.5 shows the edges and vertices of the graph and in figure 3.6 we present the X and Z corrections. 30

2 4 5 3 pi/4 0 pi/4 α Input vertex, measured with angle α 1 3 6 7 8 β Auxiliary vertex, measured with angle α 0 -pi/4 0 -pi Output vertex 9 10 Z corrections 0 X corrections Figure 3.6 The X and Z corrections of the MBQC graph of QFT 2. 3.4 From an MBQC Graph to a Quantum Circuit To convert the MBQC graph back to a quantum circuit, we took the algorithm that converts MBQC patterns to quantum circuits, described in [4], and modified it so that it would work with our MBQC graph. If we have an MBQC graph G and an empty circuit C, then the algorithm for converting the graph to a circuit consists of the following steps: Algorithm 5: From the MBQC graph to the Quantum Circuit. 1. For every vertex in G add a wire to the circuit C. 2. Apply the Hadamard gate to every non-input wire in the circuit. 3. Add Z gates to the circuit according to the edges in G. 4. Iterate through the layers in the MBQC graph starting from the first one and for each non output vertex v in a layer: (a) Add a J( α) gate to the circuit, where α is the measurement angle of the vertex. (b) Add a CNOT gate for every vertex whose measurement depends on this vertex. The control qubit should be v. 5. For every output vertex o: (a) Add a Z gate between wires corresponding to vertex o and every vertex in the set T o. (b) Add a CNOT gate between wires corresponding to vertex o and every vertex in the set S o. The qubit o should be the target qubit. 6. Add a Z measurement to every non-output qubit. As a example of this algorithm, figure 3.7 shows the circuit we get if we translate the MBQC graph of QFT 2 back to the quantum circuit model. In the figure we can see the 31

J(a) gate blocks Input qubits Output qubits Output Auxiliary qubits control-z gate blocks CNOT gate blocks Figure 3.7 The QFT 2 circuit right after translating it back from the MBQC model. structure of the quantum circuits we get from the MBQC graph. We should note, that algorithm 5 assumes that all the non-input qubits have the initial state 0. We can see the initial Hadamard gates (created on step 2 of the algorithm) and Z gates (created on step 3) at the beginning. We then get some J(α) gate blocks interlaced with CNOT blocks (created on step 4), and end with a block of Z and CNOT gates (created on step 5) before the final measurements (created on step 6). 32

3.5 Optimising the Quantum Circuit The circuit we get after translating back from the MBQC model using algorithm 5 will have the structure shown figure 3.8 (and in figure 3.7). To further decrease the depth of this circuit, we can use the techniques described by Moore and Nilsson [9] to reduce the depth of the sub-circuits consisting of only Z and CNOT gates to a logarithmic depth. This can be done using the following propositions: Proposition 3.5.1 (Proposition 5 from [9]. A Circuit of any size on n qubits, consisting of diagonal or mutually commuting gates, each of which couples at most k qubits, can be parallelised to depth O(n k 1 )2 O(k) with no ancillae, and to depth O(k logn) + 2 O(k) with O(n k ) ancillae. Proposition 3.5.2 (Proposition 6 from [9].) A Circuit of any size on n qubits composed entirely of controlled-not gates can be parallelised to O(logn) depth with O(n 2 ) ancillae. Initialisation of noninput qubits J gate blocks Measurements Z J(α) CNOT J(α) J(α) Z CNOT Initial entanglement commands block CNOT gate blocks between the J gates Z corrections block on output qubits X corrections block on output qubits Figure 3.8 The structure of the optimised circuits. We do not present the exact technique that is used to achieve the depth promised in those propositions, as this can be read from [9]. Let QC be a quantum circuit with n wires, k J(α) gates, l Z gates, and depth d. Let G = (V,I,O,E,M,S,T ) be the MBQC graph realising the same computation as QC. From equations (3.50), (3.58), (3.59) we can see that the number of vertices V in G is: V = k + l = O(n d) + O(n d) = O(n d) (3.71) Step 1 in algorithm 5 translates each of the vertices vertices in G to a wire in the optimised circuit. Thus the optimised circuit will have O(n d) qubits. Using proposition 3.5.1 the Z sub-circuits in the optimised circuit are parallelised to O(log nd) = O(log n + log d) depth. Furthermore, the CNOT sub-circuits are parallelised to the same O(logn + logd) depth using proposition 3.5.2. Let d be the depth of the MBQC computation. Broadbent and Kashefi proved in [4] that d will not be more than O(d). As 33

each of the J(α) block between the CNOT sub-circuits represents a step in the MBQC computation, the total depth of the parallel circuit after we reduce the depth of CNOT and Z sub-circuits will be O(d logn + d logd) = O(d logn + d logd). The O(d logn + d logd) depth is only the upper bound of the parallelised circuit. There exists circuits that will have a smaller depth after parallelisation than before. Some of those circuits are described in the results chapter 6. As the parallel circuits depth O(d logn + d logd) depends on the MBQC graphs depth, if we can reduce the depth of the original circuit in the MBQC model, the parallelised circuits depth will also decrease. This is the reason, why the optimisations in the MBQC model can reduce the quantum circuits depth. For example, if a O(n) depth circuit can be optimised to O(logn) depth in the MBQC model, then the depth of the parallel circuit would be O(logn logn + logn loglogn) = O(log 2 n). 34

Chapter 4 Implementation Two versions of the parallelisation program were implemented in this project: a graphical and a console version. The language used to write them is C++. The Graphical User Interface (GUI) does not provide access to all the information available through the console version, but having a visual output of the circuit helped a lot in analysing the circuits and identifying their structure. In addition to the program for parallelising the quantum circuits, we created a small program for finding the flow in an MBQC graph. This was done to verify the correctness of the parallelisation program and is described in chapter 5.1. 4.1 Development Infrastructure 4.1.1 The Qt Framework Qt framework can be downloaded from http://qt.nokia.com/. Qt is a cross-platform application and UI framework owned and distributed by Nokia. It is a collection of C++ class libraries. The version 4.6.2 of the framework was used for this project. The framework is distributed under the GNU Lesser General Public License (LGPL). This licence allowed us to create a open source program using the Qt framework. We chose Qt as the GUI framework because it provides easy to use classes for the basic elements of GUIs. It also has classes that make it easy to draw, manipulate and group custom low level graphics elements. This functionality is used to draw the Gates and Wires of the graphical quantum circuits. The ease of use was amportant factor when choosing the GUI framework, as creating the GUI was not the main goal of our project, and we did not want to spend too much time on developing it. 35

4.1.2 Project Hosting We chose Google Code as the code hosting service because it is free, and we can easily share our code, and distribute the release files. It makes our project easily accessible to anyone interested in using it or developing it further. Google Code provides a revision control system, issue tracker and a wiki service. This project uses the Subversion (SVN) system provided by Google Code. All the projects source code, examples and dissertation files are kept under this version control system and thus accessible through the projects page http://code.google.com/p/parallelqc/ at Google Code. 4.1.3 Integrated Development Environments Two Integrated Development Environments (IDE) were used in this project: Xcode and Qt Creator. Xcode The Xcode IDE was used on Mac OS X to manage the non-gui source files and the examples. This was done as a convenience, as the building of the non-gui code was done by using makefiles. The makefiles were used as external targets in the Xcode IDE. The Xcode project file, named ParallelCQ.xcodeproj, is included with the project. The version of Xcode used in this project is 3.2.2. Qt Creator The Qt Creator was used to build the GUI version of the program. It is the most convenient way to create Qt projects and is ported to many platforms (OS X, Linux, Windows, etc.). Qt Creator is distributed with the Qt framework and can be downloaded from http://qt.nokia.com/. The project file for Qt Creator is the file named ParallelQC.pro in the GUI directory of the project, and we built it using Qt Creator 1.3.1. We did not use Qt for anything else than developing the GUI of the program. We wanted that the console version could be built on systems where Qt framework is not installed. 4.1.4 Building the Project Building the Console Version The console version of the parallelisation program is located in the Console subdirectory. A makefile is provided to build the program, and two targets: Release and 36

Debug are provided. The default target will build both the Debug and Release versions. The build products will be put into the Console/bin directory. Building the Graphical Version To build the graphical version, the file ParallrlQC.pro in the GUI directory of the project should be opened with Qt Creator. Then the project can be built by only clicking on the build button. The built application will be in the GUI/bin directory. On Mac OS X running qmake in the GUI directory will create a Xcode project file instead of a Makefile, and this can be used to build the graphical version without Qt Creator. On Linux running qmake in the GUI directory will create a Makefile and this can also be used to build the graphical version. We did not test if this actually works on Linux, and so the safest way would be to use Qt Creator. Building the Utility Programs Two utility programs were provided along with the console and graphical versions of the parallelisation program. The first utility program is called QFT and is located in the Utilities/QFT directory. A makefile is provided for building it. The purpose of this program is to create quantum circuits implementing the QFT n algorithm, given n as the input. The circuits created by this program are formatted so that they can be given as input to the parallelisation program. The program accepts two parameter pairs: -n <number> - The number of qubits the QFT circuit should act on. -o <file name> - The file where the QFT circuit should be written. If this parameter is not specified, a file named QFT<n> will be used as output, where <n> is the number of qubits the circuit acts on. As an example the command: QFT -n 5 Will create a file named QFT5 with the quantum circuit of QFT 5, and the command: QFT -n 5 -o SomeFile Will write the same thing into the file SomeFile. The second Utility program is called Flow and is located in the Utilities/Flow directory. A makefile is provided for building both of them. This program is used to test if a graph has casual flow, described in chapter 5.1. The file describing the graph should be created with the console version of the parallelisation program (using the -g argument as described in chapter 4.5.2). In addition to the Utilities/Flow program implementing the flow finding algorithm, a shell script is provided with the source code, that checks the flow on every 37

example in the Examples directory of the project. This script, called TestFlow.sh does the following for each file in the Examples directory: 1. Run the console version of the optimisation program and output the MBQC graph to a temporary file. 2. Run the flow finding program on the graph in the temporary file. 3. Output if the graph has flow or not. In the end the script will remove the temporary file used for storing the graph and output the total number of run and failed tests. 38

4.2 Architecture Initially the program was meant to be separated into two main layers: the Graphical Implementation layer and Non-Graphical Implementation layer. Between them would have been anterface layer that would have allowed them to access each others functionality. The Graphical Implementation layer was meant to be using the Qt framework to draw GUI elements and for file I/O. This architecture can be seen the figure 4.1. Qt Framework Graphical Implementation Logic Interfaces Non-Graphical Implementation MBQC model Interface Implementation User Interface Algorithms Interface Implementation Quantum Circuit model GUI Elements File I/O Implementation Interface Figure 4.1 The initial architecture of the program. The initial architecture of our program, shown figure 4.1, divided the whole program into four large and mostly independent logical parts: The MBQC model. The Quantum Circuit model. The Algorithms. The User Interface. The MBQC model and Algorithms would have beemplemented in the Non-Graphical layer and the User Interface and Quantum Circuit in the Graphical layer. We wanted to implement the Quantum Circuit in the Graphical part, because we wanted to use the I/O routines of the Qt framework, and some of the classes in Qt seemed to suit very well to implement the logic of the Quantum Circuit model. The final architecture of the program is somewhat different from the initial one, as can be seen by comparing the initial architecture in figure 4.1 with the final one in figure 4.2. To get a working version of the program, the first architecture would have required us to 39

build a GUI first, as the File I/O and Quantum Circuit were meant to be implemented in the Graphical layer. At the beginning of the project we realized that, as the GUI should not be the main feature of our project, we should first get something running using a simple command line interface. That way we could add the GUI if we had enough time at the end of the project. Motivated by this, we moved the File I/O to the Non- Graphical layer and split the Quantum Circuit model to a Graphical and Non-Graphical part, making the Non-Graphical part independent from the Graphical part. We also added a new layer called Console Implementation that implements the command line user interface, and created a small Utility module to the Non-Graphical Implementation layer. Qt Framework Graphical Implementation Instances of the Logic Classes Logic Interfaces Non-Graphical Implementation Graphical User Interface MBQC model GUI Elements Logic The MBQC graph Interface Implementation File I/O Graphical Quantum Circuit Drawing Classes Logic Interface Algorithms Implementation Console Implementation Command Line User Interface The original circuit The optimised circuit The parallel circuit Quantum Circuit model Implementation Interface File I/O Utilities Figure 4.2 The final architecture of the program. The section called "Instances of Logic Classes" represents the instances of the items from the Logic part, that both the Graphical and Console Implementation use. 40

4.3 Design The final design of the program differs completely from its initial design. We therefore do not present the initial design, it can be found in the project preparation paper [10]. The final desigs presented in the next two sub chapters, but first we will outline the reasons for the design changes. There were three main problems that required us to rethink the design: The division of the Quantum Circuit code to graphical and non graphical parts. The use of a new algorithm for optimising the MBQC patterns. The poor performance of the initial implementation of the graphical Quantum Circuit. As a convenience we will refer to the Interface and Non-Graphical layer described in the architecture chapter 4.2 and figure 4.2 as the back-end of our program. The Graphical Implementation will be referred to as GUI front-end and the Console Implementation as the Console front-end. We explained in the Architecture chapter 4.2 that we decided to split the Quantum Circuit model into distinct graphical and non-graphical parts, initially it was all implemented as graphical. This meant that we had to move the logic of the quantum circuits out from the GUI front-end to the back-end. Thus we had to change the design of the back-end. The initial design assumed that we will perform the MBQC optimisations, described in chapter 3.1, on the MBQC pattern. During our project we invented a new and faster algorithm (chapter 3.3) that works on a special kind of MBQC graphs (chapter 3.2). To implement that algorithm and the MBQC graph, we had to completely redesign the MBQC model part. The initial version of the graphical circuit we developed for the GUI front-end used Qt classes to automatically arrange the gates in the circuit. The gates themselves were also derived from Qt classes that carry a lot of functionality unnecessary for this project. This design was chosen because it would have made editing the quantum circuits through the GUI easy to implement. The downside was that it was infeasible to display circuits with more than about twenty gates. Editing the circuits through the GUI was not a requirement for the program, so we redesigned the graphical circuit part, neglecting the possibility of editing the circuits. According to the new design, the gates are composed of lower level Qt classes and the arrangement of the gates in the circuit is calculated manually only once, when the circuit is created. The new design made it feasible us to visualise the quantum circuits that are feasible to parallelise with our program. 41

4.3.1 The Back-end The back-end is comprised of the Non-Graphical and Interface layer shown figure 4.2. It is divided into four logical parts, shown figure 4.3: The Quantum Circuit. The MBQC Graph. The algorithms that convert quantum circuits to MBQC graphs and vice verse. The Utility functions. Back-end Quantum Circuit CircuitIO Algorithms CircuitToGraph MBQC graph GraphIO Gate GraphToCircuit Graph Circuit GraphToBasicCircuit Edge SimpleCircuit GraphToUnitaryCircuit Vertex GateFactory Decompose Utility Figure 4.3 The design of the back-end, showing the classes and modules used in the back-end. The Decompose algorithm is colored blue, because it translates a quantum circuit to another circuit and does not use the MBQC graph. The quantum circuit files contain the classes for describing a quantum circuit and the functions for I/O. The most basic element in a quantum circuit is a Gate, the Circuit class is a subclass of Gate. This allows us to add sub-circuits as gates to the circuits. This kind of sub-circuit can for instance represent a complex quantum gate that is made up from a number of more primitive gates. A subclass of the Circuit class is the SimpleCircuit class. This class can be composed only of gates acting on one qubit, and it is used in the GUI to identify the sets of gates, that can be drawn on the same computational step in the circuit. The MBQC graph files contain the classes for the Graph, its Edges and Vertices, and the I/O functions for the Graph. The graph has the structure described in chapter 3.2 and functions to add gates to the graph described in chapter 3.3. The I/O routines for graph and the circuit are written as separate functions, to make the graph and circuit classes independent of any input and output format and functions. These functions for the Quantum Circuit and MBQC graph are in separate files from the Quantum Circuit and the MBQC Graph code. Both the Quantum Circuits and the 42

MBQC graphs can be written to a output stream, but as our program is meant for parallelising quantum circuits, only instances of the Quantum Circuits can be read from a input stream. We do not need to input MBQC graphs to our program. The Algorithms are a separate collection of functions because they do not strictly belong to neither the Graph nor the Circuit class, but to both of them. Keeping them in a separate file reduces the dependencies between the circuit and the graph. The circuit does not need to know about the graph and vice verse. Also we could easily add or modify the algorithm functions without changing the circuit or graph code. We implemented five algorithms in the Algorithms module: CircuitToGraph - Translates a quantum circuit to an MBQC graph. GraphToCircuit - Translates an MBQC graph to a quantum circuit. Uses algorithms described in chapters 3.4 and 3.5. GraphToBasicCircuit - Translates an MBQC graph to a quantum circuit, but does not apply the final optimisations described in chapter 3.5. GraphToUnitaryCircuit - Translates an MBQC graph to a quantum circuit, but does not create the initialization and the circuit and the measurement block. This circuit is used by the verification programs to calculate the unitary operator of the optimised circuit. Decompose - Decomposes translates a circuit to a new circuit, where all the gates are decomposed to J(α) and Z gates. Only legal gates are decomposed. The Utilities module contains only an utility function to convert C++ objects (or items of built-in type) to C++ strings. 43

The classes for displaying circuits and handling user input. MainWindow QMainWindow 1 1 1 CircuitInfo ControlPanel QToolBar QWidget CircuitView QGraphicsView 1 3 3 The graphical quantum circuit glasses QGraphicsScene CircuitScene <uses> Circuit 0..* 0..* 0..* 0..* Wire QubitGate 1 ControlZ ControlNOTGate WireLabel QGraphicsItemGroup Front-end classes Qt Framework classes Back-end classes Figure 4.4 The UML class diagram of the front-end. 4.3.2 The Front-end This section describes the GUI front-end. The console front-end is lightweight and the implementation consists of only a single file that according to the command line arguments calls the appropriate back-end functions. The class diagram, describing the design of the front-end, is presented in figure 4.4. As can be seen from that figure, the front-end is dependent on the back-end only through the CircuitView and CircuitScene classes. This was designed to minimise the frontends dependence from the back-end. In figure 4.4 the main Qt classes that are used are presented along with the classes that were implemented in this project. As can be seen from figure 4.4, the are are three classes in the Main Window that are responsible for interacting with the user and displaying the circuit and its properties. Figure 4.5 shows a screenshot of the program, and highlights the parts of the GUI that are implemented by those three classes. The communication and responsibilities of these classes are also shown figure 4.6. The front-end holds three instances of circuits: the original, optimised, and parallel circuits. The input from ControlPanel is used to choose the circuit that should be displayed, the CircuitView class will then draw 44

The controls to select between original, optimised and parallel circuits. Implemented in the ControlPanel class. The graphical representation of the quantum circuit. Implemented in the CircuitView class. The attributes of the quantum circuit. Implemented in the CircuitInfo Class. Figure 4.5 The GUI Interface design, and the classes that implement the different parts. the selected circuit and Circuit info class will show the circuits depth and number of qubits used. 4.4 Using the Program 4.5 The Input File Format The files used to describe the quantum circuits accepted by our program as the input must have the following structure: The circuit is described as a sequence of gates, where gates appear in the order they should be applied. Each gate is described on a separate line. Each gate description has the structure: <gate name>[(<argument>)] qubit1 qubit2... The gate name is the first element on the line, followed by an optional argument in parentheses, and the last elements are the qubits the gate acts on. The gates that are supported 45