scieee AI-readable full text Open interactive document viewer

Matrix product state preparation algorithms on quantum computers

Carballo Araruna, Víctor

Abstract

La computació quàntica té el potencial d'oferir acceleracions en molts problemes interessants com la factorització o les simulacions de química. En la majoria dels algoritmes quàntics, el maquinari quàntic real només és necessari per a passos específics, mentre que la resta es calcula clàssicament amb tècniques com les xarxes tensorials. En l'enfocament de les xarxes tensorials, els estats quàntics es codifiquen com estats de productes de matrius (en anglès MPS), de manera que preparar estats en ordinadors quàntics donats per un MPS és una tasca crucial. No obstant això, aquest procés demana un gran nombre de portes T, que es preveu que siguin un recurs escàs en el maquinari quàntic. En aquest treball desenvolupem una sèrie d'optimitzacions a un algoritme de preparació de MPS que redueixen el nombre original de portes T en un factor de quatre. També proposem una implementació de l'algoritme a la biblioteca de computació quàntica Qualtran, que se centra en l'estimació de recursos i l'optimització d'algoritmes. A més, proporcionem dades numèriques sobre el cost real i l'error en la preparació de l'estat i mostrem que l'error disminueix exponencialment amb el nombre de ancil·les. Els resultats obtinguts permeten la preparació d'estats quàntics més grans i precisos amb menys recursos. Això permet la simulació de sistemes més complexos com molècules i materials, amb un impacte directe en la investigació i la indústria.

Full text

Aerospace Technology Engineering Informatics Engineering Matrix product state preparation algorithms on quantum computers Final Degree Project May 2024 Tutor Pietro Massignan Supervisor Jordi Tura i Brugu´ es Author V ´ ıctor Carballo Araruna Abstract (EN) Quantum computing holds the potential to offer speedups on many interesting problems such as factorization or chemistry simulations. In most quantum algorithms, actual quantum hardware is only needed for specific steps, with the rest being computed classically by techniques like tensor networks. In the tensor network approach, quantum states are encoded as matrix product states (MPS), thus preparing states in quantum computers given by an MPS is a crucial task. However, such process demands a great number of T gates, which is expected to be a scarce resource in quantum hardware. In this work we develop a series of optimizations to an MPS preparation algorithm that reduce the original number of T gates by a factor four. We also propose an implementation of the algorithm to the quantum computing library Qualtran, which focuses on resource estimation and algorithm optimization. Additionally, we provide numerical data on the actual cost and error in the state preparation and show that the error decays exponentially with the number of ancillas. The results obtained allow the preparation of larger and more precise quantum states with less resources. This enables the simulation of more complex systems such as molecules and materials, with direct impact in research and industry. Keywords: quantum state preparation, matrix product states (MPS), quantum resource estimation, tensor networks, quantum computing, time evolution block decimation (TEBD). 1 Abstract (ES) La computaci´on cu´antica tiene el potencial de ofrecer optimizaciones en muchos problemas interesantes como la factorizaci´on o las simulaciones en qu´ımica. En la mayor´ıa de los algoritmos cu´anticos, el hardware cu´antico solo es necesario para pasos concretos, el resto se calcula cl´asicamente mediante t´ecnicas como las redes tensoriales. En el enfoque de las redes tensoriales, los estados cu´anticos se codifican como estados de productos de matrices (en ingl´es MPS), por lo que preparar estados en ordenadores cu´anticos codificados como MPS es una tarea crucial. Sin embargo, este proceso demanda un gran n´umero de puertas tipo T, que se espera que sean un recurso escaso en el hardware cu´antico. En este proyecto desarrollamos una serie de optimizaciones a un algoritmo de preparaci´on de MPS que reduce el n´umero original de puertas tipo T en un factor de cuatro. Tambi´en proponemos una implementaci´on del algoritmo en la librer´ıa de computaci´on cu´antica Qualtran, que se centra en la estimaci´on de recursos y la optimizaci´on de algoritmos. Adem´as, proporcionamos datos num´ericos sobre el coste real y el error en la preparaci´on del estado y mostramos que el error decae exponencialmente con el n´umero de ancillas. Los resultados obtenidos permiten la preparaci´on de estados cu´anticos m´as grandes y precisos con menos recursos. Esto permite la simulaci´on de sistemas m´as complejos como mol´eculas y materiales, con un impacto directo en la investigaci´on y la industria. Palabras clave: preparaci´on de estados cu´anticos, estados de productos de matrices (MPS), estimaci´on de recursos cu´anticos, redes tensoriales, computaci´on cu´antica, decimaci´on de bloques de evoluci´on temporal (TEBD). 2 Abstract (CAT) La computaci´o qu`antica t´e el potencial d’oferir acceleracions en molts problemes interessants com la factoritzaci´o o les simulacions de qu´ımica. En la majoria dels algoritmes qu`antics, el maquinari qu`antic real nom´es ´es necessari per a passos espec´ıfics, mentre que la resta es calcula cl`assicament amb t`ecniques com les xarxes tensorials. En l’enfocament de les xarxes tensorials, els estats qu`antics es codifiquen com estats de productes de matrius (en angl`es MPS), de manera que preparar estats en ordinadors qu`antics donats per un MPS ´es una tasca crucial. No obstant aix`o, aquest proc´es demana un gran nombre de portes T, que es preveu que siguin un recurs esc`as en el maquinari qu`antic. En aquest treball desenvolupem una s`erie d’optimitzacions a un algoritme de preparaci´o de MPS que redueixen el nombre original de portes T en un factor de quatre. Tamb´e proposem una implementaci´o de l’algoritme a la biblioteca de computaci´o qu`antica Qualtran, que se centra en l’estimaci´o de recursos i l’optimitzaci´o d’algoritmes. A m´es, proporcionem dades num`eriques sobre el cost real i l’error en la preparaci´o de l’estat i mostrem que l’error disminueix exponencialment amb el nombre de ancil·les. Els resultats obtinguts permeten la preparaci´o d’estats qu`antics m´es grans i precisos amb menys recursos. Aix`o permet la simulaci´o de sistemes m´es complexos com mol`ecules i materials, amb un impacte directe en la investigaci´o i la ind´ustria. Paraules clau: preparaci´o d’estats qu`antics, estats de productes de matrius (MPS), estimaci´o de recursos qu`antics, xarxes tensorials, computaci´o qu`antica, decimaci´o de blocs d’evoluci´o temporal (TEBD). 3 Contents 1 Introduction 8 1.1 Introduction to quantum physics . . . . . . . . . . . . . . . . . . . . . . . 11 1.2 Introduction to quantum computing . . . . . . . . . . . . . . . . . . . . . . 15 1.3 Introduction to Tensor Networks and Matrix Product States . . . . . . . . 22 2 Preparing a state from an MPS 29 2.1 Preparing a state in a quantum computer given by an MPS . . . . . . . . . 29 2.2 Decomposing quantum gates with Householder reflections . . . . . . . . . . 33 2.3 How to prepare a quantum state given its coefficients . . . . . . . . . . . . 36 2.4 How to perform rotation arrays efficiently . . . . . . . . . . . . . . . . . . 37 2.5 Cost estimation of the algorithm . . . . . . . . . . . . . . . . . . . . . . . . 39 3 Methodology and project planning 44 3.1 Research..................................... 45 3.2 Firstwritingblock ............................... 46 3.3 Implementation................................. 47 3.4 Numericalresults................................ 48 3.5 Secondwritingblock .............................. 49 4 Implementation 50 4.1 AboutQualtran................................. 50 4.2 Class diagram and overview . . . . . . . . . . . . . . . . . . . . . . . . . . 51 4.3 The state preparation bloq . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 4.4 The gate decomposition bloq . . . . . . . . . . . . . . . . . . . . . . . . . . 56 4.5 The MPS preparation bloq . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 5 Improvements to the algorithm 60 5.1 Merging phase and amplitude preparation . . . . . . . . . . . . . . . . . . 60 5.2 Differential QROM loading . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 5.3 T-cost for the improved version . . . . . . . . . . . . . . . . . . . . . . . . 65 6 Numerical results and error study 67 6.1 Results for the algorithm cost . . . . . . . . . . . . . . . . . . . . . . . . . 67 6.2 Error and probability of failure . . . . . . . . . . . . . . . . . . . . . . . . 71 7 Sustainability 77 7.1 Sustainabilitymatrix.............................. 77 7.2 Ethicalimplications............................... 82 4 CONTENTS Final Degree Project 7.3 Relationship with the Sustainable Development Goals . . . . . . . . . . . . 84 8 Conclusions and outlook 86 A Numerical example of an MPS 88 A.1 Decomposingastate .............................. 88 A.2 Computing a coefficient from an MPS . . . . . . . . . . . . . . . . . . . . . 89 5 “Nature isn’t classical, dammit, and if you want to make a simulation of nature, you’d better make it quantum mechanical, and by golly it’s a wonderful problem, because it doesn’t look so easy.” - Richard P. Feynman, Simulating Physics with Computers Common sense is the collection of prejudices acquired by age eighteen. - Albert Einstein 6 Acknowledgements This final degree project could not have been possible without many people. First, I would like to express my deepest gratitude to Jordi Tura for hosting me in his group and supervising my work. His scientific and academic advice have been crucial to the development of this project. I am also grateful to my local supervisor Pietro Massignan, who greatly helped me by giving periodic feedback and insight and to Catalonia Quantum Academy for the support. Words cannot express my gratitude to Patrick Emonts and Stefano Polla, who not only supervised and oriented my work, but also patiently corrected many more mistakes in the original manuscript that I could ever count. The ones that could remain are, doubtlessly, my fault. Without the dozens of hours of conversations on the ideas here contained and the hundreds of questions that you answered I would not have been able to tackle this project. I am deeply indebted with CFIS for giving me the opportunity to study the two degrees I was passionate about and providing the support needed to do my final degree thesis in the University of Leiden. I would also like to express my gratitude to the entire applied quantum algorithms group for receiving me during this year. You guys are amazing people doing amazing stuff. Thanks to those that shared office with me, to those with whom I talk to during launch every day, to those who helped me solving problems and to those who came to me looking for help on solving theirs. You all left your mark on me both on an academical and personal level. I could not have undertaken this journey without Alexia, thanks for being the way you are and teaching me some of the most important things I have learned. I am also deeply grateful to Xian, who has been with me on the good and the not so good moments. Thanks for giving me some of the most interesting conversations I ever had. Finally, I am also grateful to my family Dejane, Agapito, Antonia, Jose and Dani. You all made the person who I am today. 7 Chapter 1 Introduction Quantum computing is a rapidly growing field of physics and computer science that has the potential to reshape the landscape of information technology [1]. At its core, quantum computers are devices that use the quantum laws of nature to compute. They harness natural quantum phenomena such as entanglement and superposition to perform calculations at speeds that expect to transcend the capabilities of classical computers for some applications [2, 3, 4]. Classical computing is achieved by applying Boolean operators to strings of bits. These strings of bits are physically represented by electric potential on a circuit. A schematic example of such device is . (1.1) In contrast, quantum computers apply quantum operators to quantum states. Those quantum states are the analog of the strings of bits in the classical devices and can be physically realized by different means. For example, a two level quantum system such as the spin up and down of an electron or the excited and non excited states of a system. A schematic example of a quantum computation with the spin of an electron is ,(1.2) the notation is explained later on in this chapter. However, quantum hardware is very error prone. The quantum system that is operated upon has to be in complete isolation from the environment. Any kind of interference would cause coupling between the quantum state and its surroundings, ruining the computation through a process known as decoherence. Regarding how we treat those errors, there are two models of quantum computation. The first one is known as Noisy Inermediate Quantum Computers (NISQ). When computing on NISQ devices we assume that there are going to be errors and accept it as part of the computation. The second model is 8 CHAPTER 1. INTRODUCTION Final Degree Project example of a composite system. Consider two qubits in states |ψ1⟩=1 √2(|0⟩+|1⟩) and |ψ2⟩=1 √2(|0⟩−|1⟩), the system that results from their combination is |ψ⟩=1 √2(|0⟩+|1⟩)⊗1 √2(|0⟩−|1⟩) = 1 2(|00⟩−|01⟩+|10⟩−|11⟩).(1.29) Similar to the case of a single qubit, the total sum of probabilities for any collection of measurement operators must be equal to one. In the case of the state |ψ⟩it is easy to see that each one of the four elements of the computational basis (|00⟩,|01⟩,|10⟩and |11⟩) has probability 1/4 of being measured, so the sum of probabilities is 1. The example in equation (1.29) shows a quantum state that is a product of two separate subsystems, but this might not always be the case. Consider the following quantum state |ψ⟩=1 √2(|00⟩+|11⟩).(1.30) It is easy to show that there are no α, β, γ, δ ∈Csuch that 1 √2(|00⟩+|11⟩) = (α|0⟩+β|1⟩)⊗ (γ|0⟩+δ|1⟩). This special state is known as the first Bell state or EPR pair (named after the physicist Einstein, Podolsky and Rosen [11]) and is very important from a historical and scientific perspective. It is an example of a phenomena known in physics as quantum entanglement, which means that a given state cannot be expressed as a product of smaller states. Conceptually, this system can be seen as two qubits that might be arbitrarily far away from each other and that begin in a state of superposition (they are not in |0⟩nor |1⟩). If one of them is measured, the outcome of this measurement instantly affects the other. This instantaneous action-reaction at a distance intrigued many physicist in the early days of quantum physics, such as Einstein, Podolsky and Rosen, who used a system equivalent to this to question the probabilistic nature of quantum mechanics [11]. John Stewart Bell proposed an experiment in 1964 [12] that could indicate whether the nature of quantum mechanics was truly probabilistic using a quantum state equivalent to 1 √2(|00⟩+|11⟩). 1.2 Introduction to quantum computing Richard Feynman famously asked the question on whether quantum mechanics can be used to compute. Nowadays it is known that there are some quantum algorithms that offer advantages over their classical counterparts, as we will see later on this chapter. This section covers how the concepts of quantum mechanics laid out in 1.1 can be used in order to perform computations. Then, the topic of simulating quantum computers on classical ones is discussed, together with the issues that arise from there. After that we present a very simple quantum algorithm that shows some of the properties of quantum computing with respect to its classical counterpart. To conclude, some concepts of real hardware and limitations are covered in order to give the reader the motivation for some metrics used in quantum algorithms. When thinking about some aspects of quantum computing it is useful to draw a parallel with classical computers. The computational model of Turing machines establishes that a computer is essentially a memory state to which a set of operations can be applied [13]. 15 CHAPTER 1. INTRODUCTION Final Degree Project For simplicity, from now on we will only consider languages with two symbols such as two level quantum systems, or classical bits. These two symbols are referred as 0 and 1. Those operations follow the rules of Boolean algebra. Quantum computers are similar in this regard. They are composed of a set of quantum systems in a given state, to which operations that follow the rules of quantum mechanics can be applied. The difference might seem trivial at this point, but some of the phenomena shown before such as superposition (section 1.1) and entanglement (also in section 1.1) can be applied here as well. This leads to some very non-intuitive behavior. For example, a circuit evaluating all possible inputs at the same time or qubits being correlated to one another. Even though the need of measurement imposes a barrier on how much knowledge it is possible to extract from this computation. Some algorithms such as Grover’s [14], used for integer factorization, or Shor’s [15] searching algorithm with O(√n) cost manage to harness these properties to achieve speedups with respect to their classical counterparts. Let us begin the discussion on quantum computing with what is known as quantum operators or quantum gates. These are quantum analogs to the classical logical gates, with special properties derived from the postulates of quantum mechanics. All quantum gates have the same number of inputs and outputs, which is a consequence of them being unitary matrices. A gate that acts on nqubits has ninputs and outputs and is described by a 2n×2ncomplex matrix. Below is a list of the most common quantum operators, together with their representation and matrix. •X-gate (equivalent to classical NOT): ï0 1 1 0òX •Z-gate (flips the sign of |1⟩): ï1 0 0−1òZ •H-gate or Hadamard:1 √2ï1 1 1−1òH •S-gate (π/4 rotation on the Z axis): ï1 0 0eiπ/2òS •T-gate (π/8 rotation on the Z axis): ï1 0 0eiπ/4òT •CNot or controlled NOT (applies a NOT to the second qubit if the first is in |1⟩):     1 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0    X •Toffoli (applies a NOT to the third qubit if the two first are in |11⟩): 16 CHAPTER 1. INTRODUCTION Final Degree Project •Swap (swaps the two affected quantum states):     1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1     •Measurement: In classical computing, logical circuits are represented as a series of inputs that move through lines, get combined through gates and come out as outputs. A quantum circuit is the quantum analogue to this, with the difference that the number of inputs and outputs is fixed, similarly to what happens with individual gates. This is a direct consequence of quantum operators being unitary, and it also implies that all circuits that do not present measurements are totally reversible, so no quantum information is lost until measurement. Let us show an example of a quantum circuit acting on one qubit and its equivalent matrix representation |ψ⟩=1 √2ï1 0 0−1òï1 1 1−1òï1 0ò=1 √2(|0⟩−|1⟩) (1.31) |0⟩H Z =1 √2(|0⟩−|1⟩).(1.32) Note that in the case of matrix multiplication the order of application is from right to left, whereas a quantum circuit is read from left to right. This other circuit operating on two qubits prepares the bell state shown in equation (1.30) from the initial state |00⟩ |0⟩H |0⟩ =1 √2(|00⟩+|11⟩) (1.33) After running a quantum circuit the result is a quantum state from which the information has to be extracted though measurement. Due to the probabilistic nature of quantum mechanics, in some cases one needs to perform several measurements of a state that results from a circuit in order to extract relevant information from it. But postulate 3 shows that measurement collapses a quantum state to the measurement outcome, destroying information in the process. A first approach to this problem could be to execute the entire quantum circuits, clone the result and measure it an arbitrary number of times. In classical computing it is usual to copy data from one place to another. Even tough this is a trivial task for a classical computer, it is impossible to perform on its quantum counterpart. This fact is known as the no-cloning theorem [16], and it implies that there is no unitary operator Usuch that, when applied to |ψ⟩|γ⟩produces |ψ⟩|ψ⟩, for all normalized states |ψ⟩. In order to obtain nmeasurements of a state one has to repeat the entire circuit ntimes, thus the need for efficient MPS state preparation algorithms. At the beginning of this section we drew a parallel between Turing machines and quantum computers. An important concept in classical computing is that of Turing completeness 17 CHAPTER 1. INTRODUCTION Final Degree Project or computational universality. A computing device is said to be computationally universal if it can simulate any Turing machine, which implies that it is theoretically capable of solving any problem that a classical computer can solve. A device that is capable of performing the NAND gate is computationally universal [17]. Hence, to demonstrate that a quantum computer can perform any computation that its classical counterpart is capable of, it is enough to find a quantum equivalent of the NAND gate. Recall that two conditions that any quantum gate must satisfy are having the same number of inputs as outputs and not destroying information. The classical NAND gate does not have any of those two properties, so it is necessary to adapt it to satisfy the quantum requirements. The Toffoli gate shown in 1.2 can be seen as an equivalent to an AND gate if the third bit starts in the zero state |0⟩, and as a NAND gate if the third bit is in the one state |1⟩ |a⟩ |a⟩ |b⟩ |b⟩ |1⟩a∧b.(1.34) With this gate a quantum computer could perform any classical computation. Additionally, it can use this gate with its inputs in a superposition of states to evaluate multiple inputs at the same time. For example, Toffoli Å1 √2(|011⟩+|111⟩)ã=1 √2(|011⟩+|110⟩) (1.35) performs the NAND for inputs |01⟩and |11⟩simultaneously and stores the result in the third bit. This example already shows some of the capabilities of quantum computing, though the process of measurement limits the amount of information that we can extract from the quantum state. Now that the fundamentals of quantum computation and quantum circuits have been reviewed, let us show an example of a simple quantum algorithm that achieves an advantage over classical performance in order to motivate the use of quantum computers. Consider the following problem: we are given one of the four possible functions over one bit (0, 1, NOT or the identity) and have to decide whether that function is balanced or not with just a single evaluation, i.e. if through all possible outputs there is the same number of ones than zeros (identity and NOT) or not (0 and 1 functions). This problem is obviously impossible to solve in a classical computer, as one would need two evaluations in order to decide, but there exists a quantum algorithm that enables the decision with a single evaluation. It is known as the Deutsch algorithm. The function is given as an unitary gate that performs the following action Uf|x, y⟩=|x, y ⊕f(x)⟩Uf x x y y ⊕f(x) , 18 CHAPTER 1. INTRODUCTION Final Degree Project Ufis then inserted in this quantum circuit |0⟩H Uf H |1⟩H x x y y ⊕f(x) 1 2 3 . Let’s now review the quantum state at each step. 1. At this stage the state is |ψ1⟩=|+−⟩ (recall that |+⟩=H|0⟩and |−⟩ =H|1⟩). 2. After Ufhas been applied the second qubit holds the result of y⊕f(x), where x comes from the first state. This leaves the state |ψ2⟩=1 2(|0,0⊕f(0)⟩−|0,1⊕f(0)⟩+|1,0⊕f(1)⟩−|1,1⊕f(1)⟩).(1.36) Some simplification leads to |ψ2⟩=1 2|0⟩|f(0)⟩−f(0)∂+|1⟩|f(1)⟩−f(1)∂.(1.37) Now note that if f(0) = 0 then |f(0)⟩ − f(0)∂=|−⟩, and −|−⟩ for the case f(0) = 1. A similar reasoning can be applied for the second term, which results in |ψ2⟩=1 √2Ä(−1)f(0) |0⟩+ (−1)f(1) |1⟩ä|−⟩ (1.38) The two qubits are now in a product state, thus no entanglement is present. Also, no further gates are applied to the second qubit, so it can be ignored from now on in order to make the computations simpler. 3. Before seeing the effect of the application of H, let us consider the two cases present. •If the function is constant, then f(0) = f(1) and |ψ2⟩=±|+⟩. •If the function is balanced, then f(0) =f(1) and |ψ2⟩=±|−⟩. Hence, applying the Hadamard gate would result in |ψ3⟩=±|0⟩if the function is constant, and |ψ3⟩=±|1⟩if balanced. Because the sign only introduces a nonmeasurable global phase, this value can be directly measured with certain probability of getting the correct result. This algorithm can be expanded to more qubits, it is referred as the Deutsch-Josza algorithm. It is also capable of distinguishing between balanced and constant functions, and it follows a similar structure to the one seen here, with some modifications. In the previous example we sowed an algorithm that takes less runs on a quantum computer than its classical analog. But, in the end, all the computations that a quantum computer performs boil down to linear algebra, which classical computers are also capable of doing efficiently (the fields of graphics and neural networks are based on these kind of computations). It is reasonable to ask whether a classical computer could also 19 CHAPTER 1. INTRODUCTION Final Degree Project perform these operations and simulate a quantum computer efficiently, i.e. in polynomial run time. The general answer to this question is no, a classical computer is not capable of simulating an arbitrary quantum circuit in polynomial time. The reason is that the Hilbert space grows exponentially with the number of qubits (for a system with nqubit one has 2ncoefficients to describe it). However, some shortcuts enable the simulation of some kinds of circuits. The first option is to keep the number of states relatively small. Even though the cost of direct simulation is exponential, this does not imply that it is impossible to perform said computations for a given amount of qubits. However, this technique gets out of reach relatively quickly. For a system consisting of 20 qubits, an operator is represented by a 220 ×220 matrix which would require 1TB of memory to be stored. For a system with 300 qubits the number of possible states is greater than the estimated number of protons in the universe. Another option is to use data compression techniques. For a simple example of this, imagine a circuit with nqubits that does not have any gate that acts on more than a single qubit. Then no entanglement is produced and it could be simulated as nindependent single qubit systems, thus linear in the number of sites. However, practical examples are not as trivial and require more sophisticated compression algorithms. A very popular approach is called Matrix Product States [18, 19]. It uses Singular Value Decomposition to achieve a complexity that is exponential in the amount of coupling of the subsystems, rather than on the qubits themselves. If one assumes that quantum operators are relatively local, i.e. act on a reduced number of neighboring gates, this method becomes polynomial in the number of qubits and potentially exponential in circuit depth. More on this representation in sections 1.3 and A.1. Despite the complexity of using classical hardware to simulate quantum circuits, classical simulation is an indispensable tool due to the limitations of current quantum machines. Some algorithms, such as Time Evolution Block Decimation [20] (TEBD), which can be used to find the state of minimum energy of a system, can only run on a classical computer. For more information on the TEBD algorithm refer to section 1.3. Thus far we have only considered ideal quantum computers. Real hardware is very different from the mathematical abstraction presented until now, as they have to deal with problems like quantum noise in the qubits. The interference from the outside world causes some level of entanglement to the environment. Also, perturbations such as thermal fluctuations or external radiation can cause small random shifts to the vector in the state space. These effects can make the state lose quantum properties such as entanglement or superposition in a process called decoherence. Also, ideal devices do not have limitations on the gates applied to them. However, real qubits are disposed in a grid-like layout that limits the direct interaction to neighboring sites. In addition to that, multi qubit gates are normally constructed from a combination of a fixed set of gates. Thus, it is more costly to apply gates of arbitrary size or gates that act on two distant qubits, in terms of elementary operations needed. Keeping the coherence of a quantum system is one of the greatest challenges of this technology. For that reason, computations must be performed very quickly and at cryogenic temperatures (even though some platforms allow for room temperature), as otherwise the quantum states would decay into a classical state or randomly drift or flip. Two ways of avoiding decoherence were already mentioned: short computing times and 20 CHAPTER 1. INTRODUCTION Final Degree Project low temperatures, but this is not enough. Other techniques are required in order to correct the random shift that the quantum state vector experiences. The one that is of relevance for this discussion is surface code quantum error correction. There are two main elements in surface code QEC. The first is that each logical qubit is composed of several physical qubits. The second is the use of a limited gate set with some special properties. Similarly to how classical computers only have a limited variety of operations that can be applied (the set of instructions in the assembly language of the processor), quantum computers work with a finite number of elementary gates. More complex operations are formed (or approximated) with these. A gate set that is commonly used is the Clifford+T gate set. The Clifford gate set is formed by the Hadamard, S and CNOT gates. The four Pauli operators (I, X, Y and Z gates) can be constructed by combinations of these. However, as the Gottesman-Knill theorem states [21], any quantum circuit composed of these gates can be simulated classically in polynomial time, because the set of gates produced by this group is finite. This means that it is not possible to achieve universal quantum computation with these gates alone. An extra gate must be added to the set, and this is the T gate (shown in 1.2). With the T gate, the set of gates produced is now infinite and even covers all possible gates [22, 23]. Surface code QEC works as follows: Clifford gates do not need to have a high degree of precision. Whenever a Clifford gate is applied, a fast and error prone technique is used. The error generated over all the physical qubits is corrected through a special kind of measurement that does not fully collapse the state, but rather correct the error produced on gate application (this is known as the surface code). This technique can’t be used to correct the application of the T gate, as it would undo its effect. Thus, T gates need to be applied very precisely. Building or approximating an arbitrary gate from this set is not a trivial task which falls under the realm of quantum compilation, but an important example to cover is that it is possible to build a Toffoli gate with this set [23], so a quantum computer that would use it is also Turing complete. Note that this is not the optimal construction of a Toffoli gate (for the state of the art technique, refer to diagrams (2.47) and (2.48)). = T TT† HT†TT†T H (1.39) In order to apply a T gate precisely, a process called T state distillation is used, in which many faulty T states are combined in order to produce a high accuracy T state. This T state is then used in the quantum computer to apply a T gate. The process of T state distillation is very resource intensive. Also, because T gates are needed in order to achieve universal quantum computation, they are also frequently used in almost any algorithm. Hence, it is estimated that in practical applications of quantum computing, a big part of 21 CHAPTER 1. INTRODUCTION Final Degree Project the hardware resources available to the device will be used to produce T states. Those are also expected to be the bottleneck in most applications. Thus T-gate count is an effective way of measuring the cost of a quantum algorithm. 1.3 Introduction to Tensor Networks and Matrix Product States Tensor networks are a graphical language that ease the manipulation of tensors and common operations such as contraction, splitting, etc. MPS are also typically formulated in terms of tensor networks. Some operations on them, including how they are obtained from a raw state, are better understood in this language. For our purposes it is enough to consider a tensor as a ndimensional grid of complex numbers. The number of dimensions nis also known as the rank of the tensor. Let us begin the introduction to tensor networks with a notation shortcut known as Einstein notation. Operations between tensors typically involve many indices and several sum symbols. This notation is a way of writing such expressions that aims to simplify by eliminating redundant symbols. Any expression that is written in Einstein notation follows this set of rules: 1. If an index is repeated, it is implicitly summed over. 2. An index can appear once or twice for each term. 3. All terms must contain identical non-repeated terms. Consider the example of the matrix multiplication M=ABCDE in the usual notation mi,j = Σk1Σk2Σk3Σk4ai,k1bk1,k2ck2,k3dk3,k4ek4,j.(1.40) Below is the same equation but written in Einstein notation mi,j =ai,k1bk1,k2ck2,k3dk3,k4ek4,j.(1.41) All the sum symbols are gone and it is known that the knmust be added because they appear repeated in different tensors. In quantum mechanics both states and operators can be seen as many-dimensional tensors. Anqubit state is a tensor with ndimensions and a nqubit gate is a tensor with 2n dimensions (nfor input and nfor output). Applying an operation to a state is equivalent to contracting the input dimensions of the operator with the dimensions of the quantum state. Because of that, it is convenient to have a graphical representation of the operations that take place between them. Tensor networks are precisely that, a language that enables to draw both the tensors and how they must combine. In a tensor network, a tensor is represented as a shape (usually circles, rectangles or diamonds) that has lines that extend out of it. Those lines are called legs, and they denote each one of the dimensions of the tensor. As an example, a vector ψ, a matrix Mwith labeled indices iand j, and a rank 22 CHAPTER 1. INTRODUCTION Final Degree Project four tensor Acould look like M ij ψA.(1.42) If a dimension is to be summed over in Einstein notation it is denoted with a repeated index. In the context of tensor networks this is known as contraction, and it is represented joining the respective legs. For example, the tensor operation |ϕ⟩=M|ψ⟩is Mψ ϕ =.(1.43) Note that the number of unpaired legs in the diagram equals the rank of the resulting tensor (in the case of (1.43), the result is a vector with one leg). Diagram (1.44) shows three more examples of tensor networks. The first computes ⟨ϕ|ψ⟩, the second is a matrix product AB and the third is a more complex tensor operation between a rank four tensor, two rank three tensors and two vectors, which as it has four unpaired legs would result in a rank four tensor. ψϕ A B .(1.44) As happens with regular addition, the order of contraction does not affect the result, even though it does affect the time complexity of the computation [8]. In section 1.1 it was shown that any quantum state is represented by a 2ndimensional complex vector, and that operators are equivalent to matrices that act on such vectors. Hence, the circuit diagrams depicted in section 1.2 can be interpreted as tensor networks with a specialized notation for the purpose of quantum computing. For example, the circuit that prepares a bell state can be redrawn in a form that resembles the tensor network notation seen thus far as |0⟩H |0⟩ = |0⟩H CNOT |0⟩ .(1.45) It is clear from the tensor network that the result from the circuit is a quantum state composed of two qubits. Contracting all the legs of the circuit would be equivalent to performing the computation itself. Let us introduce now the Matrix Product State representation. As mentioned in section 1.2, the exponential size of an ndimensional Hilbert space makes it a challenge when 23 CHAPTER 1. INTRODUCTION Final Degree Project it comes to classical computer simulations of quantum systems and circuits. One of the ways to overcome this limitation is to use compression methods to reduce the amount of space and computing power required to handle such vector spaces. A Matrix Product State (MPS) is one of the most popular methods used to compress and work with quantum states. This section covers how this representation works in detail but, in short, it relies on the application of consecutive singular value decompositions (SVD) to the desired state in order to extract the relevant information. This method has the advantage of allowing a high level of control over the error or the amount of memory used to represent such spaces (but not both). Also, even though in the worst case scenario it also has an exponential representation cost, it can achieve polynomial cost scaling on the number of qubits of the system if the level of entanglement is sufficiently low or the accuracy is limited. Given a quantum state on nbits |ψ⟩, its naive representation in terms of coefficients can be expressed as |ψ⟩=X σ∈{0,1}n cσ0σ1...σn−1|σ⟩,(1.46) which requires a coefficient for each one of the 2ncombinations. But for an MPS, the same state |ψ⟩is written as follows |ψ⟩=X σ∈{0,1}n Aσ0 a1Aσ1 a1a2Aσ2 a2a3...Aσn−2 an−2an−1Aσn−1 an|σ0σ1...σn−1⟩.(1.47) Note that Einstein notation is used (indices that are repeated are summed over). Now each coefficient is obtained from combinations of tensor contractions. If this notation looks daunting, refer to appendix A.2 for a numerical example. This expression requires n−2 tensors of size 2c2and two of size 2c, where cis the bound dimension, that is, the size of the matrices used to represent the state. Whereas the cost in (1.46) is dominated by the system size, in (1.47) it is given by the bond dimension size. This is beneficial, because the bond dimension can be adjusted and it offers a direct trade off between fidelity to the original state and cost. Let us consider a state in a ndimensional Hilbert space |ψ⟩∈H⊗n |ψ⟩ ... .(1.48) The first step is to group all indices except for the first one into a single index σ2σ3...σn. Now |ψ⟩is represented as a C2×2n−1matrix, to which an SVD decomposition can be applied as |ψ⟩ 22n−1 SVD UV S,(1.49) 24 CHAPTER 2. PREPARING A STATE FROM AN MPS Final Degree Project state |ψMPS⟩: |ψMPS⟩=U0⊗n=GnGn−1... G2G10⊗n.(2.5) In some steps it is easier to understand the inverse process, that is 0⊗n=U†|ψMPS⟩=G1†G2†... Gn−1†Gn†|ψMPS⟩.(2.6) Consider an MPS on 4 sites with bond dimensions 2, 4, 2. The bond dimension of size 4 can also be represented as two indices of size 2 . (2.7) Now recall that, because the quantum state is normalized to be a unit vector, if one contracts this MPS with itself (the tensors are the conjugate transpose) then the result is 1. It is possible to add an extra dimension to some tensors of one of the MPS which is fixed to be at |0⟩. This is equivalent to add an extra dimension that is always indexed with the same value. Here we want to add the |0⟩to make the upper and left sides of the tensors on the right (dark purple below) have the same number of legs as in the lower right side. Following with the MPS shown before: . (2.8) The placement of the |0⟩might seem rather arbitrary at this point, but it will become clear in the next step. The previous tensor network can now be deformed into the following 31 CHAPTER 2. PREPARING A STATE FROM AN MPS Final Degree Project shape . (2.9) This new form is very similar to a quantum circuit. It describes a circuit that un-prepares the MPS, so applying it in reverse produces a circuit that prepares the MPS from the zero state. Notice how the gates are applied in the direction of orthogonality of the MPS, from top to bottom. This process transforms each one of the tensors on every site to the identity (analogously to the equations (2.1), (2.2) and (2.3)), undoing the entanglement with the neighboring sites at each step. As mentioned before, this tensor network is very close to a quantum circuit but it is not yet a valid circuit, as the tensors applied to the MPS are not unitary matrices. Even though the columns of the tensor in matrix form are orthogonal among each other (because of the left orthogonality constraint on the MPS), the new legs added are only defined in the ket |0⟩state, not in the |1⟩. This results in rectangular matrices for most of the gates. However, this is not problematic, as the only initial or final state we care about are the all zero state (this is by design, one could have chosen a different initial or final state). The rest of the columns can be filled out with the null space of the other columns if it is necessary to get the complete quantum gate. This is not the case, as in the following sections it is explained how to implement a quantum gate partially, that is, given only some of its columns. To conclude this section, the expressions for the gates are given in tensor network notation. These gates are for the circuit that prepares the MPS, the reverse of what was showed in Eq. 2.9. Note the convention used for the gate indices G 1 2 3 4=G1,2,3,4 , (2.10) the convention for the bond and physical dimensions of the tensors differs in order to what was used in equations (2.1), (2.2) and (2.3). The intermediate gates and the last one follow this scheme Gn−1 sn−1,an−2=Aσn−1 si−1,ai−2(2.11) Gi 0,si,ai−1,ai=Aσi si,ai−1,ai.(2.12) 32 CHAPTER 2. PREPARING A STATE FROM AN MPS Final Degree Project The nth gate is completely defined, whereas the intermediate gates range from completely defined to only half of the columns specified. The first gate only has one column defined G0 0,0,s0,a0=A0 s0,a0.(2.13) As mentioned before, undefined parts are to be filled with the null space of the specified ones if the complete gate is necessary. Otherwise, the gate can be left as is if an incomplete gate is fine, as is the case here. 2.2 Decomposing quantum gates with Householder reflections In order to execute the unitary gates mentioned in section 2.1 in a real quantum computer, it has to be compiled into a given gate set, in this case the Clifford + T set. The process used is described in Refs. [33] and [32]. The structure of the explanation given here is inspired in that work. It consists of a series of Householder reflections applied to the state plus one ancilla qubit that are equivalent to the desired gate. Let us first briefly mention the idea behind Householder reflections. These are a tool for building linear transformations that correspond to a reflection over a hyperplane. If the normal unit vector to a hyperplane is given by |n⟩, then the linear transformation is given by the matrix R=I−2|n⟩⟨n|.(2.14) Take the example in Fig. (2.1). This reflection over the line with normal |n⟩takes the point pto p′. By careful selection of the hyperplanes, it is possible to use combinations of these reflections to decompose a quantum gate. For more information on Householder reflections we refer to [34]. p p′   ⌝ n Figure 2.1: effect of a Householder reflection. Back to gate decomposition, let Ube a gate on nqubits out of which only kcolumns are specified, that is, a 2n×kmatrix with unit length, mutually orthogonal columns. It can 33 CHAPTER 2. PREPARING A STATE FROM AN MPS Final Degree Project be expressed as U= k−1 X i=0 |ui⟩⟨i|(2.15) The uivectors are each one of the specified columns, and the omitted part corresponds to the unspecified columns. For example U=Ü0.651 −0.071 0.123 −0.745ê⟨0|+Ü0.292 −0.875 0.139 0.361 ê⟨2| → Ü0.651 0 0.292 0 −0.071 0 −0.875 0 0.123 0 0.139 0 −0.745 0 0.361 0ê.(2.16) An ancilla qubit will be also used in order to implement the gate in the following way V=|0⟩⟨1|⊗U+|1⟩⟨0|⊗U†,(2.17) leading to a new matrix Vthat is unitary. This ancilla is used to make both vectors |1, i⟩ and |0, ui⟩orthogonal. Otherwise the reflections would interfere with each other. The new gate Vreflects |1⟩|i⟩into |0⟩|ui⟩and vice-versa: V|1⟩|i⟩=|0⟩⟨1|1⟩⊗U|i⟩+|1⟩⟨0|1⟩⊗U†|i⟩=|0⟩|ui⟩(2.18) V|0⟩|ui⟩=|0⟩⟨1|0⟩⊗U|ui⟩+|1⟩⟨0|0⟩⊗U†|ui⟩=|1⟩|i⟩.(2.19) The decomposition in reflections is done as follows |0⟩⟨1|⊗U+|1⟩⟨0|⊗U†= k−1 Y i=0 (I−2|wi⟩⟨wi|),(2.20) with wibeing the vector normal to the hyperplane of reflection, defined as |wi⟩=1 √2(|1⟩⊗|i⟩−|0⟩⊗|ui⟩) =Wi|0⟩⊗|0,0⟩. (2.21) Note that Wiis a matrix that prepares this state from the |0,0⟩state, the details on the implementation of this matrix are shown later. Let us briefly show that the selected hyperplane leads to the desired gate V. Each one of the terms in the product is expanded as I−2|wi⟩⟨wi|=I−(|1, i⟩−|0, ui⟩)(⟨1, i|−⟨0, ui|)(2.22) Consider now the effect of each one of the states |1, j⟩and |0, uj⟩. For the first case (I−2|wi⟩⟨wi|)|1, j⟩=|1, j⟩−⟨1, i|1, j⟩(|1, i⟩−|0, ui⟩).(2.23) 34 CHAPTER 2. PREPARING A STATE FROM AN MPS Final Degree Project If i=jthen it results in |0, ui⟩, as desired. If j=ithen the state is unaffected, |1, j⟩. For the second case (I−2|wi⟩⟨wi|)|0, uj⟩=|0, uj⟩+⟨0, ui|0, uj⟩(|1, i⟩−|0, ui⟩).(2.24) Again, if i=jthen the result is |1, i⟩, as desired, whereas if i=jthen the state is unaffected (notice that from the orthogonality constraint on the MPS ⟨ui|uj⟩= 0 if i=j). Thus, the mentioned hyperplane performs the desired transformations. Back to the main algorithm, each one of the reflections in the product can now be written as I−2|wi⟩⟨wi|=WiW† i−2Wi|0,0⟩⟨0,0|W† i =Wi(1 −2|0,0⟩⟨0,0|)W† i.(2.25) The central term is straightforward to implement, as it is the identity but with the upper left term with a negative sign. The Wigate decomposes as Wi= (CR|ui⟩)(CR|i⟩)((XZH)⊗I),(2.26) where R|ui⟩is a gate that prepares the quantum state given by uifrom the zero state |ui⟩=R|ui⟩|0⟩,(2.27) so CR|ui⟩prepares the state |ui⟩controlled negatively on the reflection ancilla (that is, only if that qubit is in |0⟩). CR|i⟩prepares the register |i⟩conditioned on the reflection ancilla (it writes the classical value iinto the quantum register if the reflection ancilla is in |1⟩). This can be performed with CNOTs. The gates XZH act on the reflection ancilla, and the identity on the other registers. One can check that by applying this gate the state is prepared: Wi|0,0⟩= (CR|ui⟩)(CR|i⟩)((XZH)⊗I)|0,0⟩ =1 √2(CR|ui⟩)(CR|i⟩)(−|0,0⟩+|1,0⟩) =1 √2(−|0, ui⟩+|1, i⟩). (2.28) The last step to be analyzed is how to build the gate CR|ui⟩, which is equivalent to a gate preparing a quantum state controlled by the reflection ancilla. This might seem like a recursive problem, but it is not. Firstly, this state is given by a list of coefficients, not by an MPS, so a much simpler algorithm can be used. Second, this gate is not an arbitrary gate, because its main function is taking the state |0⟩into |ui⟩and vice-versa, only the first column is defined. This greatly simplifies the problem. 35 CHAPTER 2. PREPARING A STATE FROM AN MPS Final Degree Project 2.3 How to prepare a quantum state given its coefficients This section shows how to build a gate that prepares an nuiqubit arbitrary quantum state from which one has the list of the Nui= 2nuicoefficients |ψ⟩=1 ∥a∥2X x∈{0,1}nui ax|x⟩(2.29) in a quantum register from the zero state (as is the case of R|ui⟩). We define py, (y∈ {0,1}w and w≤nui) as the probability that the first wqubits of |ψ⟩have the measurement outcome y: py=1 ∥a∥2X prefixw(x)=y∥ax∥2,(2.30) where prefixw(x) = yindicates whether the first wbits of xare equal to y. Thus, a rotation around the yaxis of angle θ= cos−1√p0prepares the state |ψ1⟩=√p0|0⟩+√p1|1⟩. If |ψ⟩is composed of just one qubit, then |ψ1⟩=|ψ⟩up to the phase in each component, which will be taken into account at the end. Unfortunately, this is not usually the case. For a multi-qubit system, it is necessary to apply this procedure recursively: at the wth step one computes the angle θy= cos−1ppy0/pyand applies a rotation controlled by all the previous qubits, where a 0 at the ith position of ymeans that the control must be negative and vice-versa. The recursive step is then expressed as |ψw⟩=X y∈{0,1}w √py|y⟩|0⟩(2.31) |ψw+1⟩=X y∈{0,1}w √py|y⟩Å…py0 py|0⟩+…py1 py|1⟩ã.(2.32) By following the chain of conditional probabilities it is possible to show that this scheme indeed prepares the state |ψ⟩(except for the phase of each coefficient). An example of a circuit performing such operation on three qubits is . |0⟩Ry(θ) |0⟩Ry(θ0)Ry(θ1) |0⟩Ry(θ00)Ry(θ01)Ry(θ10)Ry(θ11) (2.33) The cost of performing such a number of rotations might seem exponential in the problem size, but it is not, as the number of rotations for nuiqubits is nui−1 X i=0 2i= 2nui−1 = Nui−1 (2.34) 36 CHAPTER 2. PREPARING A STATE FROM AN MPS Final Degree Project whereas the number of coefficients given is 2nui. Recall that in the case of R|ui⟩, the coefficients are the elements from column uiof the gate U, which are determined by the virtual bond dimension of the MPS. The previous procedure prepares the amplitude of each coefficient of |ψ⟩, but the phase is missing. In order to fix this, it is enough to add one rotation gate at the last qubit around the zaxis for each coefficient of the state controlled by all the previous qubits. For the example circuit shown in Eq. (2.33), one should add at the end ϕ1ϕ2ϕ3ϕ4ϕ5ϕ6ϕ7 (2.35) where ϕkis the phase of the coefficient |k⟩. Assuming the phase of the first coefficient is zero (as the global phase is not important) this final step adds another N−1 rotations, for a total of 2(N−1). The previous procedure is used to implement R|ui⟩, but the gate that is actually used is a negatively controlled version of R|ui⟩. In order to achieve that, it is enough to add an extra negative control to each gate. Thus, the gate CR|ui⟩can be implemented with a cost polynomial in the number of coefficients of ui, but there is still a final detail to finish the overview of the method: how to perform these rotations with the Clifford+T gate set, and how to do it as efficiently as possible. 2.4 How to perform rotation arrays efficiently In the previous section it was shown that an arbitrary state composed of Nuicomplex coefficients can be prepared in a quantum computer using 2(Nui−1) rotations. Even though this is still a polynomial amount regarding the number of coefficients, it is the major contributor to the T-gate count of the whole algorithm. Decomposing a rotation into gates from the Clifford+T gate set has been one of the most important tasks in quantum compilation, with numerous approaches to it ([22, 35, 36, 37], to name a few). In this context, the Solovay-Kitaev theorem [22] guarantees that any rotation can be approximated with a number of gates from the Clifford+T set that escalates as O(logc(1/ϵ)), where cis a constant and ϵis the error of the approximation. This is a crucial result, because any unitary can be decomposed as a set of rotations and CNOTs [23], but it has the problem that it does not guarantee that the number of T-gates used is kept as low as possible. There are many approaches to the implementation of individual rotations, but here we will take advantage of a phenomena known as phase kickback. The whole method is divided in two steps. 37 CHAPTER 2. PREPARING A STATE FROM AN MPS Final Degree Project For the first step we need to encode the rotation angles. The precision of the rotation is given by the number of qubits bin the register where the angle is to be stored. Then one divides the 2πradians of the circumference in 2bsections, and if the value |x⟩is loaded into the register, then the rotation angle is θx= 2πx 2b.(2.36) The error comes from the limited resolution of 1/2bover the circumference. The details on how to load these angles are shown later. For the second step we exploit the phase kickback technique. Assume that there is a state prepared in another register which also is composed of nqubits as follows |ψgrad⟩=1 √2b 2b−1 X k=0 e−2πik/2b|k⟩.(2.37) This state is known as the phase gradient, and can be achieved by performing the Fourier transform of the all one ket |111...1⟩(Fourier transforms are not relevant for this work, we refer to Ref. [9] for more information on how to prepare this state). Let us show how it can be used to rotate a state |x⟩. Let b= 2 and a value stored in the rotation angle register of 3: |x⟩|3⟩(e−2πi0/4|0⟩+e−2πi1/4|1⟩+e−2πi2/4|2⟩+e−2πi3/4|3⟩).(2.38) Take into account that |3⟩is not a 4 state qudit, but rather the state |11⟩. Now, it is possible to add the rotation angle register and the values in the phase gradient register, leaving the result in the latter, with the quantum addition circuit [38]. The state is now |x⟩|3⟩(e−2πi0/4|3⟩+e−2πi1/4|0⟩+e−2πi2/4|1⟩+e−2πi3/4|2⟩).(2.39) Note that addition is performed modulo 2b. It is possible to take common factor of the angle that corresponds to |0⟩in order to leave the phase state in its original form, which leads to e2πi3/4|x⟩|3⟩(e−2πi3/4|3⟩+e−2πi0/4|0⟩+e−2πi1/4|1⟩+e−2πi2/4|2⟩),(2.40) where e2πi3/4=e−2πi1/4because we are working modulo 4. This is the original state but with a phase of e2πi3/4. Thus with this technique it is possible to rotate a state. It would be convenient as a last step to undo the write operation in the angle register to disentangle it from the original state. The phase gradient state has not been affected and can thus be reused, so preparing a single |ψgrad⟩is enough. Also, it is possible to work with several states in superposition to load multiple angles simultaneously (even though having to load each value of the rotation angle to the register individually prevents the complete parallelization of the process). For example, imagine one wants to rotate |0⟩by 2π·42/2band |1⟩by 2π·137/2bradians. The initial state is |ϕ⟩= (|0⟩+|1⟩)|0⟩|ψgrad⟩(2.41) 38 CHAPTER 2. PREPARING A STATE FROM AN MPS Final Degree Project up to normalization. The registers are, from left to right, the states to be rotated, the register for storing the angle of rotation and the phase gradient. Then one writes the values 42 and 137 to the second register conditional on the first one (the exact circuit to perform this is shown later) |ϕ⟩= (|0,42⟩+|1,137⟩)|ψgrad⟩(2.42) and finally add the angle register to phase gradient and take the common factor of the phase at |0⟩as in Eq. (2.40) in order to get the desired rotation (e2πi42/2b|0,42⟩+e2πi137/2b|1,137⟩)|ψgrad⟩(2.43) and finally uncompute the angle load to disentangle the state and the angle value register (e2πi42/2b|0⟩+e2πi137/2b|1⟩)|0⟩|ψgrad⟩.(2.44) The only thing that remains to be explained is how to load the angle values into the respective register. This is the step that increases the T-gate cost the most, because each angle has to be loaded individually. The exact method that is to be used is the one from Ref. [33], but a simpler version of the circuit is shown here to better illustrate the point (which in the paper corresponds to the select network). For real applications the select swap variant from Ref. [33] is more efficient. An example of a circuit for performing such operation is select register |0⟩ ⟨0| target register 0⊗b block 1 block 2 (2.45) It prepares the value |7⟩in the target register if the select register is in |0⟩(what is denoted as block 1) and |2⟩if the select register is in |1⟩(block 2). In the previous case, the select register corresponds to the control bits and the target is the register in which the angle is written. This construction is also known as a Quantum Read Only Memory or QROM. 2.5 Cost estimation of the algorithm In this section we analyze the cost of implementing each step of the previous algorithm in order to give a total T-gate count. As the overall cost of the algorithm is heavily MPS dependant, we instead provide a cost for implementing each one of the gates shown in 39 CHAPTER 2. PREPARING A STATE FROM AN MPS Final Degree Project diagram (2.9). The overall cost is easily derived from adding up all the gates as a function of the different bond dimensions. Thus, we consider the cost of implementing an nqubit gate, out of which only kcolumns are specified and where the register that holds the rotation angle is of size b. The sources of T-cost for each gate of this algorithm are: •The reflection (1 −2|0,0⟩⟨0,0|). •The conditional state preparation CR|ui⟩: –Loading the rotation values into the rotation register. –Performing the rotation via addition. –Uncomputing the rotation values loaded. The cost of the conditional state preparation has a factor of two because there are two W gates for each reflection: Wand W†. How to implement a Toffoli gate Even though the quantum computing resource that has been mentioned the most up until now is the T gate or T state, it is not common to find a T-gate on itself in a quantum algorithm, but rather used inside a Toffoli gate. Thus, how to build a Toffoli gate with the minimum amount of T-gates is crucial. A very common pattern in the MPS state preparation algorithm (and many others) is two Toffolis surrounding some other circuit, as can be seen in Eq. (2.45) or in the quantum addition algorithm from Ref. [38]. Such a structure is usually displayed in this form |0⟩ ... ⟨0|→... .(2.46) A decomposition into Clifford+T was shown in Eq. (1.39) with T cost 7, but in the case in which a Toffoli is applied and then uncomputed (as in Eq. (2.46)) then in can be implemented with just T-cost 4 [38] (three T gates and one T state). The circuit is as follows: = T† T† |T⟩T H S (2.47) =Z H (2.48) 40 CHAPTER 3. METHODOLOGY AND PROJECT PLANNING Final Degree Project the specific topics on each section, which are cited therein. The first stages of this section can overlap with the research block, as there are not any dependent tasks between them. 3.3 Implementation The implementation stage covers most of the coding related tasks of the project, excluding numerical data acquisition. The timeline matches the three main blocks mentioned in chapter 4, with an extra step that is dedicated to improving and optimizing the original algorithm. Some stages allow for a certain amount of parallelization, as is the case of state preparation and gate decomposition, because Qualtran allows the user to define a bloqs interface and work with it even though it is not fully implemented. For the MPS preparation stage we have opted for waiting until the gate decomposition bloq is fully defined because the complexity when handling the indices of the MPS requires thorough testing through the entire implementation period. Timeline •Implementation of the state preparation bloq (w. 1 Feb - w. 2 Feb): this step covers the implementation of a bloq that prepares a quantum state from a list of its coefficients. •Implementation of the gate decomposition bloq (w. 2 Feb - w. 3 Feb): during this stage the bloq that is used to decompose an arbitrary quantum operator into simpler bloqs is implemented. •Implementation of the MPS preparation bloq (w. 4 Feb): this period is dedicated to using the previously defined gate decomposition bloq to build the MPS preparation algorithm. •Optimizations (w. 1 March - w. 2 March): once the implementation of the original algorithm is done, this step is dedicated to improving it and finding alternative and more efficient ways in terms of T-cost. Figure 3.4: Gantt chart of the algorithm’s implementation. Methodology The implementation not only covers the coding of the algorithm itself, but also test cases to ensure the code is correct and detailed documentation. The documentation can be 47 CHAPTER 3. METHODOLOGY AND PROJECT PLANNING Final Degree Project broken down in two types: code documentation and tutorials on how to use the bloqs. The tutorials explain how to use the code, a general overview of the algorithm and some special considerations. 3.4 Numerical results This block contains the gathering of the data shown in chapter 6, as well as making the plots. The types of data collected can be divided in: T-gate costs, error measurements and probability of failure for the gate synthesis process. Regarding the cost and the error, these apply both to the state preparation as well as gate decomposition processes. Timeline •Cost of state preparation (w. 2 March). •Cost of gate decomposition (w. 2 March). •Error in state preparation (w. 3 March - w. 4 March). •Error in gate decomposition (w. 3 March - w. 4 March). •Probability of failure in gate decomposition (w. 1 April). •Plotting (w. 3 March - w. 2 April). Figure 3.5: Gantt chart of the numerical data acquisition. Methodology All numerical data is extracted from the original algorithm, except for the error in state preparation, which is obtained though a script that recreates the algorithm without simulating the quantum circuit, which is much faster. The cost is obtained from a single run of the algorithm for each sample, because it is not dependant on the coefficients of the state. For the error, we first define which metric is used and then proceed to gather the data. 48 CHAPTER 3. METHODOLOGY AND PROJECT PLANNING Final Degree Project The error is generally taken as the average over a given number of samples (indicated in the respective section). Sometimes a worst result is also given for reference on the worst case scenario. The plotting is done with Matplotlib, using a style as uniform as possible for consistency. 3.5 Second writing block The final step of the project covers the second writing bloq. It involves all the sections not covered by the first, as well as the revision of the manuscript (both new and previous chapters). As all sections except the numerical results chapter are independent of the previous step, this allows almost complete overlap with the numerical results stage. Timeline •Implementation (w. 3 March). •Improvements to the algorithm (w. 4 March - w. 1 April). •Numerical results (w. 2 April - w. 3 April). •Conclusions and acknowledgements (w. 4 April), •Revision and corrections of the manuscript (w. 3 March - w. 1 May). Figure 3.6: Gantt chart of the second writing block. Methodology The methodology for this section is analogous to that of the first writing block. Regarding the revision and corrections, it is done as an iterative process of revision by my supervisors and myself. 49 Chapter 4 Implementation This chapter covers the implementation details of the algorithm explained in section 2 and a discussion of the choices made. The first section is about the library of choice for this project. Then comes a diagram of the different classes implemented as well as the relations between them. Finally, there is one more section dedicated to discuss in depth each one of the three main sections in the project. The implementation here detailed is in process of being merged to the open source quantum library Qualtran [40]. 4.1 About Qualtran With the popularization of quantum computing, several frameworks that allow to write, manipulate and simulate quantum circuits emerged in the recent years. Some of the most widely known are Google’s Cirq [41], IBM’s Qiskit [42], Amazon’s Braket [43], among many others. The great number of frameworks offers many options that target specific use cases. Many of these libraries focus on “diagram like” quantum circuits. This is why the open source quantum library Qualtran is different from many other frameworks available. It focuses on resource counting and optimization. An example of this is that qubits can be allocated and deallocated on demand, instead of having the same amount of qubits for the entire computation. In addition to that, it has interoperability both with Cirq, Google’s most well known and widespread quantum library, as well as Quimb [44], a popular library used for tensor network and MPS simulation. Thus, it can be used as a bridge to connect the tensor network oriented representation that is a matrix product state with the more abstract circuit oriented side represented by Cirq. At the moment of writing, Qualtran has fifteen contributors, twenty-four forks, more than a hundred stars and close to five hundred commits. It’s completely developed using Python, which also makes it attractive by using a wide spread and flexible programming language. Qualtran has a modular approach to building circuits. Gates are grouped in what are called bloqs. Bloqs can be composed of other bloqs. An interesting feature is that these bloqs need not to be fully implemented, they can be empty placeholders with cost annotations to perform accurate resource estimation and optimization. This is very useful in 50 CHAPTER 4. IMPLEMENTATION Final Degree Project the early prototyping phases of a project. For these reasons, we have chosen Qualtran for implementing the algorithm. 4.2 Class diagram and overview The implementation is divided in three main stages: state preparation (from a list of coefficients), gate decomposition and MPS preparation. The reason behind this division is that all these three bloqs are useful on its own, so they are divided in different modules. This section gives an overview of the purpose of each one of them, as well as general information that is common to all. Figure (4.1) offers an UML style diagram of the entire implementation. Only the new classes are shown, even though some other pre-existing classes had to be modified. This is the case for ReflectUsingPrepare. The modifications to this class are detailed in section 4.3. The first thing to note is that almost all classes inherit from the bloq class, and those who don’t inherit from another class that is a child of bloq. As mentioned before, Qualtran has a modular approach to building circuits and groups bloqs and gates into another bloqs. It is the basic building structure of this library. Thus, even though some methods are technically public, they are not of interest for the end user of the library, as is the case for the build composite bloq, but rather used by other parts of Qualtran to compose the circuit. When a function is of interest for the end user, it will be explicitly mentioned. Let us then explain some common methods that are shared between most of the bloqs: •signature: it indicates the number of input and output registers for each bloq, as well as the number of qubits for each of these registers. •build composite bloq: specifies the behaviour of the bloq by indicating the gates used as well as how they connect. •attrs post init : method from Python’s attrs library that runs several assertions to ensure that the initialization of the class is correct. In addition to those methods, some attributes are shared between many classes and will be also discussed here to avoid repetition later on: •phase bitsize: size of the register that is used to store the different rotation angles. It is the only source of error in the algorithm and increasing it improves the precision of the results, but requires three extra ancillas for each unit increased. •uncompute: indicates whether the bloq that is implemented is the normal or the adjoint version. An important thing to note is that the association relation in the UML diagram does not imply that a class in the Python code has an attribute of another class, but rather that some bloq uses another bloq. Also, not all the bloqs used have been included in the diagram. 51 CHAPTER 4. IMPLEMENTATION Final Degree Project (4.1) 52 CHAPTER 4. IMPLEMENTATION Final Degree Project Another detail that can be noticed through almost all classes is the use of the tuple data structure. This choice is in part imposed by the attrs.frozen decorator that most of the bloqs have. This decorator needs a hash of the class, thus the attributes must be hashable items. As data structures like list or numpy’s array are modifiable, they are not hashable and therefore can’t be used in this case. Qualtran is also capable of writing a diagram that indicates the inputs and outputs of each bloq thanks to the signature method described before. An example of a bloq diagram for a swap gate on five registers is xSwap x y 5 y 5 x 5 y 5 , (4.2) where xand yare the names of the registers, Swap is the name of the gate and the numbers over the arrows indicate register sizes. It is also possible to show a diagram of the bloqs that make up another bloq. For a swap on a single qubit that diagram would result in xCNOT control target 1 y 1 CNOT control target CNOT control target 1 1 x 1 y 1 1 1 . (4.3) These diagrams will be used in later sections to show the internals of the different bloqs. Also, the inputs and outputs (in the previous examples xand y) are referred as soquets or registers. Many gates do not have a fixed amount of input and output soquets. This is the case of the PrepareMPS bloq. It can receive a phase gradient state from the user (which can be reused from previous bloqs) or generated internally, with the respective additional cost. Hence, the build composite bloq can receive a different number of parameters depending on the registers necessary (in the previous case, the phase gradient might or might not be needed by build composite bloq). Registers that are not always present are grouped under the **soqs dictionary. If that is the case for a given bloq, it will be specified which extra register it might need and when does it need them. To conclude this overview, all bloqs also have tests units via pytest and the most important ones: PrepareMPS,DecomposeGateViaHR and StatePreparationViaRotations also have detailed tutorials which can be found in the same folder as the source code. 53 CHAPTER 4. IMPLEMENTATION Final Degree Project 4.3 The state preparation bloq The set of bloqs corresponding to state preparation implements the algorithm described in sections 2.3 and 2.4. More precisely, StatePreparationViaRotations implements the method from circuit (2.33) and PRGAViaPhaseGradient implements the rotation blocks, which is known as a phase rotation gate array (PRGA). Let us first explore the second bloq. This gate gives a phase offset specified by the user for each value of a select register, that is select target Rz(θ00)Rz(θ01)Rz(θ10)Rz(θ11) (4.4) to which a control register can be added. This is performed with the phase kickback scheme described in Sec. 2.4 and the QROM gate from diagram (2.45). Translating it to circuit format and adding a control qubit results in i b b control target select QROM QROM 0⊗brot reg ADD |ψphase grad⟩ sel sel targ a a targ ba+b (4.5) where iis the size of the select register and bis the size of the phase gradient register, which specifies the precision achieved. Notice that the target qubit is used as a control for the QROM, thus the rotation is only performed when the target is at state |1⟩. This is equivalent to replacing the Rz(θ) gates from circuit (4.4) with Zθ/π, up to some phase that will be considered later. The previous scheme successfully applies the phase rotations, but for the state preparation algorithm what is needed is a PRGA that rotates over the Y axis. This can be achieved by a quarter turn rotation on the X axis to move the Y axis to the Z axis. A quarter turn rotation on the X axis is a gate that can be generated exclusively from Cliffords, thus no extra T-gates are added. The equivalence is Rx(π/2) = H S H (4.6) Rx(−π/2) = H S S S H .(4.7) 54 CHAPTER 4. IMPLEMENTATION Final Degree Project Adding this rotation to the circuit leaves the PRGA that will be used to encode the state i b b control target Rx(π/2) Rx(−π/2) select QROM QROM 0⊗brot reg ADD |ψphase grad⟩ sel sel targ a a targ ba+b (4.8) which affects the overall state as |ψ⟩= 2i−1 X k=0 eiπθk/2b(cosπθk/2b|0target⟩+ sinπθk/2b|1target⟩)|k⟩|ψphase grad⟩,(4.9) where θkcorresponds to the different angle values loaded by the QROM and |k⟩are the different values that the select register takes. Note also the phase introduced by replacing the Rz(θ) by the equivalent of a Zθ/π. It is not a problem though, as it can be corrected up to an error of 2π/2b+1 when encoding the phase of the state. Now it is possible to use the PRGAViaPhaseGradient to implement the state preparation circuit from diagram (2.33). The parallel gates that prepare each qubit can be seen as different PRGAs . |0⟩Ry(θ) |0⟩Ry(θ0)Ry(θ1) |0⟩Ry(θ00)Ry(θ01)Ry(θ10)Ry(θ11) PRGA 1 PRGA 2 PRGA 3 (4.10) where the select qubits are the ones with the controls and the target is the qubit to be prepared. These three PRGA are of the type that act on Y, as presented in diagram (4.8). After these there is yet another PRGA to encode the phases (and undo the offsets), this one acting over the Z axis, with all the qubits as the select registers and an ancilla as a target. 55 CHAPTER 4. IMPLEMENTATION Final Degree Project There is still one class from this group that has not been mentioned, and it is Rotation- Tree. The goal of this class is, given the list of coefficients of the state, to compute the rotation angles needed to encode both the amplitudes and also the phases with the offsets already taken into account. It then converts these angle values to the integer values to be encoded by the QROM in the rotation register. Regarding the class that implements the described functionality, it has a very simple interface. It receives the list of coefficients that encode the state, the size of the phase register, the number of control qubits (later it will be used with a single control, but more can be added or left uncontrolled) and whether to implement the state preparation or un-preparation (Uor U†). From this, the bloq is ready to be used. This is the signature of the bloq for a state preparation on a two qubit state with an angle register of four qubits and controlled on a single qubit (4.11) and the decomposition, from which it is possible to identify the two RPGAs that encode the amplitude and the last RPGA that encodes the phases, together with the Rx gates that transform phase rotations into amplitude rotations . (4.12) 4.4 The gate decomposition bloq The second set of bloqs, which is composed of DecomposeGateViaHR and PrepareOracleDecomposeGateReflection, implements the gate decomposition process shown in section 2.2. This gives a procedure to build the gates used to prepare the MPS from simpler gates. For context, recall that the gates are built column-wise, with a reflection for each column. The reflections are made up of a generic reflection on the zero state and two Wmatrices that prepare the axis of reflection. The bloq PrepareOracleDecomposeGateReflection is a subclass of PrepareOracle that implements the gate that prepares the axis of reflection from equation (2.21). This bloq has the effect Wi|0⟩⊗|0,0⟩=1 √2(|1⟩⊗|i, 0⟩−|0⟩⊗|ui⟩),(4.13) 56 CHAPTER 5. IMPROVEMENTS TO THE ALGORITHM Final Degree Project With this construction, a circuit equivalent to the one shown in diagram (5.3) looks like (5.7) where the first two |0⟩represent two qubits of the quantum state |ψ⟩to be prepared, the third select registers corresponds to the qubits previously prepared, the fourth and fifth are registers initiated at zero where the rotation angle is written and |ψpg⟩is the phase gradient state on bqubits. The angles for the first qubit are written with a normal QROM, as there is no previous angles, and then the first add bloq prepares the amplitude and the second the phase of the first qubit. Then the DQROM bloq overwrites the first angles with the new angles that encode the next rotation. Again, the first adder after the DQROM encodes the amplitude and the second one the phase for the second qubit. If there are more PRGAs then the final QROM would be replaced with another DQROM to merge it with the first QROM of the next PRGA, analogously for the first QROM. If this corresponds to state preparation and it is acceptable to have a register entangled with the state |ψ⟩then the last QROM can be omitted, cutting the cost of the algorithm by a third. With this it is possible to make the gate CR|ui⟩that prepares the state |ui⟩from the zero register with a control qubit. However, recall that for the refection one needs I−2|wi⟩⟨wi|=Wi(I−2|0⟩⟨0|)W† i =|ra⟩ R† |ui⟩R† |i⟩R|i⟩R|ui⟩ ,(5.8) where |ra⟩is the reflection ancilla and the XZH gates that prepare the reflection ancilla are ommited for clarity. This means that the adjoint of the circuit depicted in diagram (5.7) is needed before the normal version. This is problematic because if the last QROM is not omitted then the cost is not reduced by half (the last QROM is the larger one when preparing and un-preparing a state). Just reverting the construction for state preparation is not enough, as then the junk register would not hold the values needed (the rotation angles) to prepare the state. The solution is then to add an initial and final QROM of select size n−1. Together with the amplitude and phase merge, these QROMs bring the cost optimization close to 3.5 times less than the original, but there is another optimization that can be performed in order to get an asymptotic 4 times reduction in cost. Consider two reflections on two qubits, which will be divided in three different 63 CHAPTER 5. IMPROVEMENTS TO THE ALGORITHM Final Degree Project sections as follows |ra⟩ |input⟩R† |u0⟩R† |0⟩R|0⟩R|u0⟩R† |u1⟩R† |1⟩R|1⟩R|u1⟩ A B C . (5.9) Part C of the diagram corresponds to the prepare bloq, which requires an extra QROM with select of size n−1 to unentangle the final angles. A simplified version of the circuit shown in diagram (5.7) is used from now on to illustrate the QROM merges: QROM select targ Add Rx Add |0⟩ DQROM select targ 0 1 |ψ⟩ Add Rx Add 0QROM select targ |0⟩, (5.10) the controls on the addition have been removed from the scheme for clarity, even though they would still be needed in the real circuit, as well as the control from the reflection ancilla. The adders whose controls are surrounded by π/2 rotations on the X axis (the ones that encode the amplitude) have been labelled with an Rx. Both target lines have been merged into a single line, which includes both the register for the amplitude rotation angle and the register for the phase rotation angle, unless labelled otherwise. The numbers to the side of the select register on the QROM and DQROM indicate the equivalent size of the selection register. For example, even though the DQROM has a wire that comes from the left, the value that it is overwriting comes from the previous QROM, which has select size zero, that is, using the notation from equation (5.5) the value loaded is (a0⊕b0, a0⊕b1). Also note that the size of the select register of the underlying QROM that implements a DQROM is the maximum of the select from the left and the right. The final QROM is used to unload the junk register so that the angle register is at |0⟩and can be reused later on by other gates. Section A corresponds to the adjoint of the circuit from diagram (5.10) with an initial QROM to prepare the initial rotation angles. These two sections have an asymptotic cost superior to the objective of four times reduction, as the extra final, in the case of C, and initial, in the case of A, QROMs represent a 50% increase in T-cost with respect to the version with the entangled junk register. However, section B represents a prepare |u0⟩and unprepare |u1⟩. The schematic of these two bloqs together is |0⟩ 0 1 0 |0⟩ 1 targ select QROM targ select DQROM QROM select targ QROM select targ DQROM select targ Add Rx Add Add Rx Add Add Rx Add Rx AddAdd QROM select targ 0 R|uo⟩R† |u1⟩ . (5.11) In this circuit, the two central QROMs could be merged into a single DQROM, but another alternative that reduces the T-cost further is to remove them completely. Note 64 CHAPTER 5. IMPROVEMENTS TO THE ALGORITHM Final Degree Project that in the two central PRGAs first the amplitude of |u0⟩is loaded, then the phase, then the phase of |u1⟩is uncomputed and finally the amplitude of |u1⟩is also uncomputed. This is equivalent to having three adders with three angle registers, one for each adder, and that prepare the amplitude of |u0⟩then a single phase rotation can load the phase of |u0⟩and unload the phase of |u1⟩and a third adder to load the amplitude of |u1⟩. Then this third extra angle register can be freed after the first DQROM of |u1⟩, as it is left in the |0⟩state. The new construction looks as |0⟩ 010 |0⟩ 10QROM select targ Rx AddAddAdd Rx Add QROM select targ |0⟩ Add Rx Add Rx Add targ 0 select DQROM targ 1 targ 2 targ 2 targ 1 DQROM select targ 0 |0⟩. (5.12) In the case of a gate with kcolumns specified, all reflections except for the first and the last can use this new construction for both ends, which saves not only the initial and final QROMs but also a phase addition. 5.3 T-cost for the improved version In this section we obtain the cost of state preparation from a list of coefficients using the improved version, as well as the cost of gate compilation with this technique. Recall that the Toffoli cost of a controlled QROM on nselect qubits is 2n+c−2, and that the adder and controlled adder on bqubits both have a cost of b−1 and 2(b−1) + c−1 pairs of Toffolis respectively. For the new state preparation architecture a DQROM and two adders for each qubit are needed. The kth qubit needs an uncontrolled DQROM of select size k, with Toffoli cost 2k−2 and two adders with a single control with cost 2(b−1) each. Putting all together results CToffoli(n, b) = 2(b−1) + 1 + 2n−1 X k=0 2k−2+2·2(b−1) = 2n+ 2(2n+ 1)(b−1) −2n, (5.13) where the +1 is used to compensate the negative cost of the uncontrolled QROM on zero qubits. The cost for the version without entangled junk is obtained by adding the final QROM of size n−1 CToffoli(n, b) = 2n−1−2+2n−1 + 2(2n+ 1)(b−1) = 2n+ 2n−1+ 2(2n+ 1)(b−1) −3.(5.14) As mentioned before, this increases the cost roughly by 50%. If the state preparation is inserted into the gate decomposition bloq then there must be an extra control in the adder connected to the reflection ancilla. This changes the cost of each adder to 2(b−1) + 1. Also, as the state preparation is now controlled, the global 65 CHAPTER 5. IMPROVEMENTS TO THE ALGORITHM Final Degree Project phase turns into a relative phase which is now important. The global phase rotation requires loading an angle controlled by the reflection ancilla (zero T-cost) and performing the addition. The cost for the controlled state preparation is thus CToffoli(n, b) = 2(b−1) + 2n−1 X k=0 2k−2 + 2(2(b−1) + 1) = 2n−1 + 2(2n+ 1)(b−1). (5.15) The computation for the gate compilation results a bit more involved. The main idea is the same as before, two state preparation routines per reflection, each taking the same cost as in Eq. (5.15), to which the cost of the reflections is added, n−1 Toffolis. Also, the cost of the initial and final QROMs is also included as Toffolis 2n−1−2 each. Finally, recall that one of the phase rotations disappears when combining the preparations of the last qubit in R|ui⟩and R† |ui+1⟩. This is the same as subtracting (k−1)(2(b−1)+1) Toffolis. Combining all results in a Toffoli cost of CToffoli(n, k, b) =2k[2n−1 + 2(2n+ 1)(b−1)] + 2(2n−1−2) +k(n−1) −(k−2)(2(b−1) + 1).(5.16) Considering only the leading terms in the Toffoli cost, which dominate the asymptotic behaviour, we get that the original state preparation routine required 4 ·2nToffolis, whereas the improved one just 2nif it is acceptable to have entangled junk registers and 1.5·2notherwise. For the gate decomposition the results are also improved in a similar way, the original version requires 8k2nwhereas the optimized just 2k22. 66 Chapter 6 Numerical results and error study This chapters focuses on three aspects of the algorithm: real Toffoli and T-gate cost as compared with the expressions provided in section 5.3, approximation errors in the algorithm and probability of failure when synthesizing the gates. 6.1 Results for the algorithm cost Qualtran is capable of doing exact T-gate counting for any bloq. This feature is used here to obtain the precise number of resources needed for state preparation from a list of coefficients and for gate synthesis. The data shown in this section corresponds to T-cost, that is, the number of T gates used, in contrast to the number of Toffoli pairs that was obtained in section 2.5. As a reminder, a pair of Toffolis is equivalent to four T-gates, as depicted in equation 2.47. Let us begin by studying the cost of state preparation from a classical list of coefficients. Recall from section 2.5 that the Toffoli cost of preparing an nqubit quantum state with an angle register size of bis CToffoli(n, b) = 4(2n−1) + (n+ 1)(b−1) −2n(6.1) and for the improved version CToffoli(n, b) = 2n+ 2(2n+ 1)(b−1) −2n. (6.2) Figure 6.1 shows a comparison of the cost in terms of T-gates for the original state preparation algorithm from a classical list of coefficients (not from an MPS) and the optimized version shown in chapter 5. For each color, which corresponds to one of the different versions, there is a solid line that represents the cost function and data points for the exact T-count obtained. The implementation of the optimized version does not prepare the global phase, hence the difference in cost for the smaller states. As the number of qubits grows this difference becomes insignificant, as shown in figure 6.1. The results are as expected, the algorithm decreases the factor in the leading asymptotic term of the cost and increases the factor of the lower order terms. Thus, for smaller states the overall cost is worse than the original version. But as the number of sites grows the cost is completely dominated by that of the QROMS. 67 CHAPTER 6. NUMERICAL RESULTS AND ERROR STUDY Final Degree Project Figure 6.1: T-cost of the original and optimized state preparation algorithms with an angle register size of (a) 2, (b) 4 and (c) 10 qubits. The original algorithm performs better for smaller states, but the optimizations take over as the number of sites grow. Bigger rotation angle registers delay this effect. 68 CHAPTER 6. NUMERICAL RESULTS AND ERROR STUDY Final Degree Project Figure 6.2 shows the reduction factor for both versions of the state preparation algorithm with various state sizes. Each line corresponds to a different sizes of the rotation angle register b. The asymptotic cost improvement reaches four times less T-gates for large enough states. Also, because the new version increases the cost of the adders, whose size is determined by the size of the register that stores the angles, increasing the number of qubits of this register (such as in figure 6.1 (c)) delays the predominance of the asymptotic factor. Figure 6.2: Improvement in the cost of state preparation, measured as CT-gate orig/CT-gate optimized for various sizes of the angle register. The asymptotic four times improvement is achieved for large states, but the optimizations already improve the original algorithm for medium sized states. Regarding the cost of gate decomposition, recall from section 2.5 that the cost of decomposing a nqubit gate of which kcolumns are specified with a register to store the rotation angle of bqubits for the original version is CToffoli(n, k, b) = k(8 ·2n+n−5 + 2(n+ 1)(b−1)) (6.3) and as shown in section 5.3 after the optimizations the cost results CToffoli(n, k, b) =2k(2n−1 + 2(2n+ 1)(b−1)) + 2(2n−1−2) +k(n−1) −(k−2)(2(b−1) + 1).(6.4) Figure 6.3 shows the cost comparison of the original and optimized version of gate decomposition. All the costs correspond to complete gates (that is, gates without missing columns), so in this case k= 2n. The results also show a similar behaviour than in the case of state preparation, with an higher initial cost that tends towards an asymptotic reduction for large enough gates. However, for this algorithm the crossing point in the cost happens for a greater number of qubits than in state preparation. The cause is that not only the cost of the adders has increased but also there is the need of an initial and final QROMs of size n−1. These QROMs represent a noticeable fraction of the overall cost of the algorithm for smaller gates, thus the worse cost. 69 CHAPTER 6. NUMERICAL RESULTS AND ERROR STUDY Final Degree Project Figure 6.3: T-cost of the original and optimized gate decomposition algorithms with an angle register size of (a) 2, (b) 4 and (c) 10 qubits. An effect similar to state preparation happens here, the original algorithm is better for smaller gates but the optimizations take over as the number of sites grows. 70 CHAPTER 6. NUMERICAL RESULTS AND ERROR STUDY Final Degree Project Considering that the typical bond dimension for large MPS is in the range of the hundreds, the size of the gates that need to be decomposed for the innermost sites is roughly 7 to 10 qubits. That is already in the range close to the asymptotic improvement with respect with the original version for small and medium angle register sizes. Figure 6.4 shows the reduction factor for both versions of the gate decomposition algorithm with various gate sizes. Results show the desired four times reduction in the cost, even though the asymptotic point is reached with a greater number of qubits with respect to state preparation, as shown in figure 6.4. Figure 6.4: Improvement in the cost of gate decomposition, measured as CT-gate original/CT-gate optimized for various sizes of the angle register. As with state preparation, the four times improvement in cost is achieved for large gates, but the new version already improves the original one for medium sized gates. To conclude, until now the costs shown are for gates with all the columns, that is k= 2n. Now we study the behaviour of the algorithm when decomposing an incomplete unitary. For the original algorithm, whose cost is shown in table 2.1 and equation (6.3) it is clear that the cost is going to be completely proportional, as the number of columns kmultiplies the entire expression. However, the optimized version whose cost is shown in equation 5.16 and again in equation 6.4 is different, as it has the overhead caused by the extra QROMs, which does not depend on the number of columns implemented. Figure 6.5 shows how the cost of decomposing a partial gate with respect to the cost of the entire unitary varies. Even though the overhead for small gates is noticeable, as the size increases it quickly becomes insignificant. 6.2 Error and probability of failure The phase kickback technique explained in section 2.4 relies on the rotation angle being loaded in the register. This angle must be one of the states of the computational basis, that is, there is a discrete set of 2bavailable angles, where bis the size of this register. The discretization process induces a rounding error which impacts the state produced 71 CHAPTER 6. NUMERICAL RESULTS AND ERROR STUDY Final Degree Project Figure 6.5: Cost of implementing an incomplete gate with respect to the complete one, measured as CT-gate partial/CT-gate complete for different gate sizes and 16 qubit angle register. The new scheme adds an overhead with respect to the ideal linear case. However, as the size of the gate grows this effect becomes insignificant. and in the gates decomposed using the controlled state preparation routines. This error has two effects on the behaviour of the algorithm. The first one is that the states and gates produced do not exactly match the original. The second effect only affects the gate compilation bloq, and induces a certain probability of failure in the sense of loss of information of the original state. As is shown later, in practice this probability tends to be relatively small and it is also possible to detect whether this error has happened. In this section, we present the experimental behaviour of these errors for the original state preparation subroutine, as well as comment the available bounds. We begin by exploring the error caused by the discretization in the state preparation procedure. Let |ψ⟩denote the original state and |e ψ⟩the approximate preparation result. The error in state preparation is measured via E(ψ)=1−|⟨ψ|e ψ⟩|.(6.5) Figure 6.6 shows the worst sample and average error when preparing 105random states as a function of the size of the angle register. Recall that the number of qubits of this register determines the accuracy of the angle and thus the error. The behaviour of the maximum error trends might seem strange at first, but consider that, as the number of parameters that encode the state grows exponentially with the number of qubits, the probabilities of reaching a state that is close to the worst also decrease exponentially. A much more valuable resource to understand the behaviour of the error with the system and angle register sizes is the average, from which it is clear that increasing the system size and decreasing the qubits of the angle register both contribute to the error. In any case, the decay in error with respect to the angle register size is exponential. Regarding an error bound for this procedure, Ref. [33] gives a bound for this procedure in appendix D based on the error when producing the PRGA. Assume Uis the ideal PRGA 72 CHAPTER 7. SUSTAINABILITY Final Degree Project overall running time of the computation. This cost is very significant, as both classical and quantum computers require high amounts of energy for computing and cooling. Risks and limitations The risks associated to the improvement of quantum algorithms is the widespread adoption of such machines. The impact that this would have on the environment is two sided. On the one hand, quantum algorithms promise to optimize some calculations with respect to their classical counterparts [15, 49]. As mentioned before, this reduction has a positive impact on energy consumption. Also, more efficient supercomputers imply that less physical resources are needed (fewer supercomputers can do as much work), this also improves the total material and production waste of the hardware needed, as well as the residuals to be disposed at the end of its life cycle. On the other hand, the popularization of quantum computing and the wide use of this technology will cause higher demand for this type of hardware, which is very resource intensive to both manufacture and operate. As this technology is very recent, the real implications of this widespread are unknown, but a similar situation to what happened with the block chain network could happen, where a wide spread adoption of the technology implied a noticeable increase in energy consumption [50]. Economic impact The impact that quantum algorithms and quantum computing as a whole can have over the economy is very wide and complex. In this section, we will discuss the possible impact of this project on the economy, as well as the costs associated to it. Development What follows is a study of the cost associated with the development of the project. More precisely, the cost related to personnel and resources used. The project has been authored by five people: a bachelor student and four researchers. The closest remunerated position in academia is a first year doctoral student. The salary for such role in the Netherlands is 2770emonthly [51], to which a factor of 0.5 is added to take into account the difference. Regarding the cost of hiring four researchers, the salary for the role of senior scientific employee in the Netherlands varies considerably depending on the years of experience, but it is in the range of 5000e[51]. That amounts to 22770e monthly, 204930efor a nine month period. In addition to that, other resources used are travel expenses, electricity consumption, computer equipment and office material. The travel expenses cover the cost of traveling to the country of destination for the personnel involved in the project. The normal cost of a plane ticket between Barcelona and Amsterdam is 40eduring the months of September, December, January and May. As in the previous section, there are four trips, which amounts to 160e. Just one person needs displacement, so those are all the travel expenses. 79 CHAPTER 7. SUSTAINABILITY Final Degree Project For the electricity consumption we will only consider the variable cost of the project, ignoring the fixed cost of the electrical consumption (lights, heating, etc.). The total energy was obtained in section 7.1, which is 414.2MJ (115.05 kWh). The average electricity price in the first half of 2023 is 0.475e/kWh [52]. This results in 54.65e. The computer used for this project is a Lenovo Legion Y520 laptop. This product is not currently available in Lenovo’s official web page, as it is not in the catalog anymore, but other sources [53] set the original price at 849$(786.07ewith the actual currency change). Office material covers the cost of notebooks, writing material, paper and printing. This can be rounded to 20ein total. Table 7.1: Total cost of the project’s development Source Cost [e] Personnel 204930 Travel expenses 160 Electricity consumption 54.65 Computer equipment 849 Office material 20 Total 206013 Table 7.1 shows the overall cost of the project and all of its components, which amounts to 206013ein total. Other considerations could be added, such as opportunity cost for the researchers related to the project. Execution As the project does not have an execution on itself, it is not possible to determine the cost of it. However, if implemented in the private sector it could have benefits related to the improvement in industrial processes and optimization of routines. A clear case of this is the pharmaceutical industry [46], which is expected to be one of the most direct applications of quantum chemistry on quantum computation. The exact economical impact of this technology is still unknown. Risks and limitations Regarding the economic risks and limitations of this project, as the expenses are only related to the duration of it, the only added expense to the initial estimate is the extension of the period in which the project will be developed, or the need of replacing the computer used. Regarding the first expense, it would amount to personnel and electricity expenses. This adds up to 22770e+54.65e/9 = 22776eper month of extended period. The cost of replacing the personal computer would be the same as the initial purchase cost. Regarding the reduction of expenses, there is not much room for improvement in the costs. The budget could be reduced slightly by searching cheaper means of transport (such as a shared car) or a less expensive computer. Cutting personnel costs is not an option, as the academia salaries in the Netherlands are fixed. 80 CHAPTER 7. SUSTAINABILITY Final Degree Project Social impact In this section the impact of this project and quantum computing as a whole on society will be discussed. This is of major importance, because some of the most significant effects of this technology will be in the change it will make in people’s every day lives. Development The development of this project has been of great personal impact for me. As an entry point to academic research, it did let me see how wide and complex the field of quantum computing is. Each one of the minor improvements to any algorithm requires months of thought and hard work. It was also useful for discovering the workflow in academia and how to carry out an investigation in the field of science. The first stage in which the researcher learns about the new topic, followed by the creative part of discovery and the consolidation and checking work, which also implies the final crystallization of the new idea. All this process is carried out with the highest degree of rigor, to ensure that science is done correctly. Execution The implementation of the ideas discussed in this work can have a great impact in society, mainly for the better, but also for the worse if not used responsibly. The possible outcomes will be briefly described here, but for a more thorough discussion refer to the ethical implications section 7.2. On the positive side, some of the greatest impacts of quantum computing in society are the improvement of healthcare trough the use of quantum chemistry simulations by the pharmaceutical industry [54, 46], optimization of supply chains with new quantum optimization algorithms [49], improvements in machine learning and artificial intelligence [55], better climate modeling and material science also via quantum simulations [29], new tools for scientific discoveries and new industries and job opportunities. All these effects have a direct and indirect effect on society. On the other side, the potentially negative aspects of quantum computing in society are the security risks it will present to non-quantum resistant cryptography systems [56, 57], ethical concerns with the improvement of artificial intelligence, environmental impact of the energy consumed, the high initial cost of the technology or the inequality that could result as a consequence of improved financial investing models at the reach of the entities that can afford quantum computation. Risks and limitations The unforeseen risks of quantum computing could high, as the full potential of the technology is yet to be discovered. Thus, an exhaustive and thorough analysis is almost impossible until more capable quantum devices are mass produced and available for real commercial applications. 81 CHAPTER 7. SUSTAINABILITY Final Degree Project Regarding gender equality, it is not expected that this project will have any negative impact on gender equality. Considering the field of quantum computing as a whole, it is important to have a diverse representation, as well as any other field of science, in accordance to the reality of the society we live in. Hence, it is crucial to work towards inclusive education and training so that every person has the same opportunities no matter the gender, nationality or sexual orientation. Another potential concern regarding this topic is the presence of bias in machine learning data sets. Even though it is not the main topic of this work, quantum computing has multiple applications to machine learning, and it is crucial to have not only more powerful models, but also models that do not present any algorithmic bias. Thus, data sets must be carefully crafted to avoid such problems. 7.2 Ethical implications Even though quantum computing is a new and emerging field and there is yet to be an official code of ethics, there are already several works on the ethical and responsible use of this technology [58, 59, 60]. As practical scalable quantum computers are closer each year, it is crucial to examine the implications and effects of this technology. In the previous sections of this chapter all the main risks were already mentioned, but here a more in depth discussion of them with proposals of possible mitigation strategies will be explored. Privacy and Security One of the greatest ethical concerns about quantum computing is its potential impact on privacy. Quantum computers have the capability to break widely used cryptographic protocols [56, 57]. An example of this is how Shor’s algorithm [15] is capable of breaking RSA via integer factorization of the public modulus. This leads to concerns about the vulnerability of sensitive information stored and transmitted over the internet. In order to mitigate this effect, guidelines must be established to force the implementation of post-quantum encryption algorithms [61]. If this is not done as soon as possible, there is the risk that outdated services in the future will be prone to personal data from the users being leaked. Also, if a big leap in quantum hardware occurred, enabling the factorization of current public keys, this could let companies and entities out of time to update their services. Another reason why it is crucial that the migration to post-quantum encryption schemes is done as soon as possible is due to harvest now, decrypt later attacks [62]. These kind of attacks consist in the mass collection of encrypted messages with the hope that in the future it will be possible to break the security involved via quantum algorithms or even improvements on classical attack techniques. This could enable bad actors to reveal secrets such as personal information, passwords or banking credentials from the users in the near term future. 82 CHAPTER 7. SUSTAINABILITY Final Degree Project Economic Disparities Fields such as quantum finance and quantum market modeling could have a noticeable impact in the stock market of the future [63]. The improved prediction capabilities of these models will enable corporations with access to quantum computing an unfair advantage over the rest of the actors in the market. As any cutting edge technology, the cost of quantum computing is expected to be high in the short term future, as these machines need special cryogenic conditions and qualified personnel for its operation. For this reason, if not handled correctly, the advantage over the rest of the competitors could drastically increase inequalities and kill opportunities for new investors getting into the market due to the extreme initial cost. Environmental Impact Quantum computing, though promising, poses severe challenges related to energy consumption and environmental impact. These challenges arise from various sources. As mentioned before, many quantum computing hardware implementations rely in cryogenic temperatures to operate. This implies that refrigerating hardware is needed, which has a very high level of energy consumption. In addition to that, the manufacturing process is likely to be very energy intensive. As there is not a wide-use quantum computer yet, the amount of resources needed by this future industry is unknown, but the current production of electronic products is one of the highest sources of emissions in the countries that produce them [64]. To avoid these negative effects, it is crucial to impose environmentally friendly policies to the countries that manufacture and dispose products from these industries. Global agreements on regulations and sanctions are needed to prevent events such as the extreme energy consumption of block chain [50] or the electronics landfills in less developed countries [65]. Ethics in Artificial Intelligence As covered in section 7.1, quantum computing has many applications in the field of machine learning. This causes several ethic considerations from that field to transfer to quantum computing. The main concerns on the ethical use of artificial intelligence are the bias on data sets and the correct and non-authoritarian use of this technology. On the one hand, if data sets are gathered from a society that has biases and roles regarding gender, ethnicity or sexual orientation, these roles and biases will be carried out to the model that is being trained with the data, further perpetuating them. This is even worsened by the black-box nature of many of these models, which makes it more difficult for the operators to check the existence of such undesirable elements. On the other hand, the power that artificial intelligence brings might be used by an authoritarian entity or government to restrict the freedom of the people they are in charge of [66]. This is an unprecedented tool for mass control and surveillance whose long term consequences are yet to be known. Similarly to the environmental concerns, the only way to mitigate those effects is the 83 CHAPTER 7. SUSTAINABILITY Final Degree Project heavy regulation of these industries to ensure that they follow a strict code of conduct. This is the path that the European Union is already taking [67]. The effects that this regulation will impose to the artificial intelligence market and the society as a whole will be determined in the years following the implantation of these measures. Conclusion To summarize, as quantum computing advances at an unprecedented pace, ethical considerations become indispensable guides for the correct implementation of this transformative technology. Balancing innovation with responsibility requires a collaborative effort involving researchers, policymakers, ethicists, and society at large. By the responsible implementation of regulations for the responsible use of this technology to prevent the increase in energy usage, the rise of economical inequality, ensuring user’s privacy and reinforcing the ethical use of artificial intelligence, quantum computing has the potential to be an indispensable tool for the industry and the scientific community of the future. 7.3 Relationship with the Sustainable Development Goals The Sustainable Development Goals (SDG), also known as the agenda 2030, are a series of seventeen goals relating all aspects of society such as health, energy production, the environment and others. These goals were set and approved by the United nations at the year 2015 [68] with the objective of ending poverty, improving health and education, reducing inequality and encouraging economic growth whilst tackling climate change and the preservation of our oceans and forests. Below is a list of all the SDG. 1. No poverty 2. Zero hunger 3. Good health and well-being 4. Quality education 5. Gender equality 6. Clean water and sanitation 7. Affordable and clean energy 8. Decent work and economic growth 9. Industry, innovation and infrastructure 10. Reduced inequality 11. Sustainable cities and communities 12. Responsible consumption and production 13. Climate action 14. Life below water 15. Life on land 16. Peace, justice and strong institutions 17. Partnerships for the goals The main impact of quantum computing on these are in the fields of health and energy consumption and distribution, with the side effects of climate change action and sustain- 84 CHAPTER 7. SUSTAINABILITY Final Degree Project able cities and communities. It could also greatly impact the production of food via better fertilizers. Health and well-being The impact that quantum computing will have in the pharmaceutical industry implies that not only new medicines could be discovered, but also better and more cost effective alternatives to the ones we have today might also be available. This is a crucial step for countries where the access to healthcare is not free and universal. T-gate count is expected to be a limiting factor on those applications [69], thus a more efficient encoding process can lead to the possibility of working with bigger and more precise systems. Energy efficiency One of the most promising applications of quantum computing is the improvement over classical optimization algorithms [49]. This family of algorithms have the potential to be applied for the optimization of the power network [70]. This would result in a more efficient distribution of energy. Also, the application of quantum computing to material science has the potential to give materials with less electrical resistance that the ones used today for the power grid. Zero hunger The production of nitrogen based fertilizers has been a major contributor to the demographic rise in the last century and supports the food production for most of the world population [71]. The synthesis of such fertilizers rely in a chemical process known as the Haber process. However, the efficiency of this reaction is still relatively low, less than 50% [72]. The applications that quantum computing has on quantum chemistry could help to better understand this reaction, thus improving the production of fertilizers. This not only would increase the amount of product, but also decrease the waste. This is crucial, as this process is heavily polluting [73]. 85 Chapter 8 Conclusions and outlook The interaction between classical and quantum computers is a crucial step in many algorithms such as the time evolution of quantum systems and quantum phase estimation. But as seen in chapter 1, working with quantum states in classical computers is not an easy task due to the exponential growth in the number of coefficients with the system size. Thus, techniques such as Tensor Networks and Matrix Product States arise as ways to deal and control this exponential growth. However preparing a state encoded as an MPS in a quantum computer is not a trivial task, to which chapter 2 is devoted. There we first presented some different algorithms to accomplish this task, together with its strengths and inconveniences. Many algorithms focus on local relations between sites, with the advantage of using smaller gates and shallower circuits. But, in search of a more versatile solution, we opted for a general approach in which the sizes of the gates is not limited. Thus, we needed an efficient algorithm for decomposing arbitrarily large quantum gates. This algorithm used reflections to build the gate column-wise. The reflections also needed a routine for state preparation from a list of coefficients, which was presented in the same chapter. The state preparation routine used arrays of rotations, which can be implemented efficiently by phase kickback. This algorithm was then implemented in the Quantum Computing library Qualtran. The three main stages of the algorithm (MPS preparation, gate decomposition and state preparation) received each its own separate class, as those are useful primitives on their own. Apart from the implementation, another target of the project is to optimize the T-gate count of the algorithm. This was achieved by removing and combining QROMs, which is the most expensive gate in the algorithm. A first optimization removed the last PRGA of each state preparation, which due to being the biggest one accounted for half the cost of the algorithm. The second optimization combined sequential QROMs into a single gate that has half the cost of the two previous ones. These two cost reductions resulted in a four times reduction of the overall number of T-gates used. These theoretical results were then checked numerically in chapter 6. Regarding the number of T-gates, for smaller gates the original algorithm has less cost. But as the gate size increases the optimizations become more relevant that the overhead and the cost reaches the four times improvement. Another important feature of the algorithm that 86 CHAPTER 8. CONCLUSIONS AND OUTLOOK Final Degree Project was discussed is the probability of error. The error comes from the discretization of the angles, as those have to be picked from a list of 2bavailable options. This causes not only an approximation on the result of the produced state, but also a probability of loss of information when applying the gate. The reason is that the reflection ancilla used can become entangled with the input register. However, this kind of error can be detected though the measurement value on the reflection ancilla. Regarding future work, there are several open paths from this research. The first one is improving the error bound and giving an average error analysis of the algorithm. Even though the numerical data shows that the decay on both is exponential on the size of the rotation register, an analytical expression could help practical applications through the optimal selection of such register. Also, the only source of optimisation considered regarded the QROMs, but more work on the other T-gate sources of the algorithm could be done. Specially regarding the quantum adders, which are the cause of the cost increase of the smaller gates. Finally, here we only optimized the general MPS preparation algorithm. However, similar techniques could be used for other alternatives. The results will be different from the ones obtained here, as those tend to require a greater number of smaller quantum gates. 87 Appendix A Numerical example of an MPS In this section a full numerical example of an MPS is shown to better illustrate the theoretical concepts described in section 1.3 applied to a real case of study. A.1 Decomposing a state Consider the following (non normalized) quantum state |ψ⟩=|001⟩+|010⟩+|100⟩.(A.1) It can be rewritten as a vector of coefficients, leading to |ψ⟩=01101000.(A.2) The next step is to split the first index from the other two. The first row corresponds to the first bit being zero and the second to it being one |ψ⟩=Å0 1 1 0 1 0 0 0ã.(A.3) An SVD of this matrix yields U=Å1 0 0 1ã(A.4) S=Å√2 0 0 0 0 1 0 0ã(A.5) V=Ü0 1 0 0 1/√2 0 0 −1/√2 1/√2 0 0 1/√2 0 0 1 0 ê(A.6) (A.7) Notice that the third and fourth columns of Vdo not matter, so they can be trimmed. Also, to ease the calculations, the Smatrix will be absorbed by V. The matrix U then 88