Full text
Universidade do Minho Escola de Engenharia Departamento de Inform´ atica Jos´ e Eduardo Moreira Barros Pereira Quantum Error-Correcting Codes November 2021
Universidade do Minho Escola de Engenharia Departamento de Inform´ atica Jos´ e Eduardo Moreira Barros Pereira Quantum Error-Correcting Codes Master dissertation Master Degree in Physics Engineering Dissertation supervised by Jos´ e Carlos Bacelar Ferreira Junqueira de Almeida Jos´ e Pedro Miranda Mour˜ ao Patr´ıcio November 2021
i
ii
ACKNOWLEDGEMENTS To keep it short and sweet I would like to thank both my supervisors Prof.Jos ´ e Bacelar and Prof.Pedro Patr ´ ıcio, my parents and sister and my colleagues and friends. Without their help, this journey would have been so much more difficult. Wish you all the best, forever. iii
ABSTRACT Quantum computing is a new and exciting field of research that, using the properties of quantum mechanics, has the potential to be a disruptive technology, being able to perform certain computations faster than any classical computer, such as Shor’s factorization algorithm and Grover’s algorithm. Although there are several quantum computer with different underlying technologies, one of the main challenges of quantum computation is the occurence of errors, destroying the information and making computation impossible. Errors may have several different sources namely, thermal noise, faulty gates or incorrect measurements. The present dissertation aims to study and employ methods for reducing the effects of errors during quantum computation and correct them using Stabilizer Codes, which are a very powerful tool to produce circuit encoding networks that can, in theory, protect quantum systems from errors during transmission. A proof of concept algorithm was implemented using Qiskit, a Python based program development language for the IBM Q machines, and tested on both simulators and real systems. The algorithm is capable of, given any stabilizer in standard form, generate the circuit encoding network. Due to technological limitations associated with current quantum computers the results obtained in ibmq guadalupe fail to show the efficacy of Stabilizer Codes. Keywords— Quantum Computing, Quantum Error Correction, Stabilizer Codes, IBMQ iv
RESUMO A computa c¸˜ ao qu ˆ antica ´ e uma ´ area de investiga c¸˜ ao recente que, usando as propriedades da mec ˆ anica qu ˆ antica, tem o potencial de ser uma tecnologia disruptiva, sendo capaz de realizar alguns tipos de computa c¸˜ ao de forma mais r ´ apida do que qualquer outro computador cl ´ assico atual, tais como, o algoritmo de fatoriza c¸˜ ao de Shor e o algoritmo de procura de Grover. Apesar de j ´ a existirem v ´ arios computadores qu ˆ anticos com tecnologias de diferentes modos de opera c¸˜ ao, um dos principais desafios que a computa c¸˜ ao qu ˆ antica enfrenta ´ e a exist ˆ encia de erros, destruindo a informa c¸˜ ao presente e impossibilitando a computa c¸˜ ao. Os erros podem ser de v ´ arias fontes, nomeadamente, ru ´ ıdo t ´ ermico, opera c¸ ˜ oes deficientes ou medidas incorrectas. Esta disserta c¸˜ ao tem como objectivo estudar e aplicar m ´ etodos para reduzir os efeitos dos erros durante a computa c¸˜ ao qu ˆ antica e corrigi-los usando c ´ odigos estabilizadores, que s ˜ ao uma ferramenta poderosa para produzir circuitos que podem, em teoria, proteger sistemas qu ˆ anticos de erros ocorridos durante a transmiss ˜ ao. Foi implementado um algoritmo usando Qiskit, uma linguagem ` a base de Python usada para desenvolver programas nas m ´ aquinas da IBM, que foi testado em simuladores e em sistemas f ´ ısicos. O algoritmo ´ e capaz de, dado um estabilizador na sua forma standard, gerar o circuito codificador. Devido a limita c¸ ˜ oes da tecnologia associadas aos atuais computadores qu ˆ anticos, os resultados obtidos na m ´ aquina ibmq guadalupe n˜ ao demonstram a efic´ acia dos c´ odigos estabilizadores. Palavras-chave— Computa c¸˜ ao Qu ˆ antica, Correc c¸˜ ao de Erros Qu ˆ anticos, C ´ odigos Estabilizadores, IBMQ v
CONTENTS 1 introduction 1 2 classical information theory 2 2.1Noiseless Coding Theorem 3 2.2Noisy Coding 4 3 classical error-correcting codes 6 3.1Hamming Codes 7 3.2BCH Codes 9 4 quantum theory 16 4.1Quantum Computation 20 4.1.1Pauli Matrices 20 4.1.2Hadamard and CNOT 21 4.1.3Bloch Sphere 23 5 quantum error-correcting codes 25 5.1Properties of a Quantum Code 25 5.2Shor’s 9-qubit code 26 5.3Stabilizer Coding 28 5.3.1Xand Zoperators 28 5.3.2Encoding and Decoding Stabilizer Codes 29 5.3.3Networks for Encoding and Decoding 30 6 the 5 qubit code 32 6.1Results 34 6.1.1Qasm Simulator 34 6.1.2IBM Quantum System 36 7 conclusion 38 7.1Prospect for future work 38 a qiskit implementation 41 a.1The algorithm 41 a.2Reading the results 43 a.2.1Qasm Simulator 43 a.2.2IBMQ Guadalupe 44 vi
LIST OF FIGURES Figure 1General communication system 2 Figure 2Entropy in the case of two possibilities pand 1 −p3 Figure 3Communication in a noisy channel (from Roman (1992)) 4 Figure 4Communication system with correction 5 Figure 5Single qubit gates 22 Figure 6 Circuit representation for the CNOT. The top line represents the control qubit, the bottom line the target qubit. (from Nielsen and Chuang (2002)) 22 Figure 7Bloch sphere (from Barnett (2009)) 24 Figure 8Encoding network for the 5qubit code 33 Figure 9Reading the output 33 Figure 10 Output read after transmission, no error introduced 34 Figure 11 Results after transmission with errors on qbit[0] and qbit[1] 34 Figure 12 Results after transmission with errors on qbit[2] and qbit[3] 35 Figure 13 Results after transmission with errors on qbit[4] 35 Figure 14 Connectivity of the qubits in the IBMQ Guadalupe. 36 Figure 15 Output of the system after computation in the IBMQ Guadalupe 37 vii
2.2. Noisy Coding 5 qNoH(q) bits is required using a minimum of N0H2(q) , following a third, fourth and so on. The total number of required bits is: N=N0 1−H(q)(4) Summarizing, it is possible to faithfully enconde 2N0 messages using N=N0 1−H(q) bits for error correction. This result is Shannon’s noisy-channel coding theorem for the binary channel. Encoding different messages as bit strings, or codewords, must be made such that the messages are distinguishable after passing through the noisy channel. Examples of efficient coding schemes are shown in section 3. Figure 4: Communication system with correction
3 CLASSICAL ERROR-CORRECTING CODES A code is a set of messages called codewords that can be transmitted between two parties. An error-correcting code is a code for which it is sometimes possible to detect and correct errors that occur during transmission of the codewords. Some applications of error-correcting codes include correction of errors that occur in information transmitted via Internet, data stored in a computer, etc. A binary code is a non-empty subset of Zn 2 . It is linear if it forms a subspace of Zn 2 . It’s usually described by the parameters [n,k] , wherein n refers to the length of the codewords and k to the dimension of the vector space. To correct a received vector it’s only necessary to use the nearest neighbor policy, i.e., assume the fewest possible number of errors, and correct the received vector to the codeword from which it differs in the fewest positions. This method is limited, for there is not always a unique codeword that corrects a received vector. Definition 1Let Cbe a code in Zn 2. For any vectors x,y∈ C, the Hamming distance d(x,y)is defined as: d(x,y) = n ∑ i=1|xi−yi|, (5) where the sumation is considered over Z . The smallest Hamming distance between any two distinct codewords in a code Cis called the minimum distance of C, denoted d(C)or simply d. Definition 2For x ∈Zn 2and r ∈Z+, let Sr={y∈Zn 2|d(x,y)≤r}(6) Sr(x)is called the ball of radius r centered in x. Let C be a code with minimum distance d , and let t be the largest integer such that t<d 2 . Then St(x)∩St(y) = ∅,∀x,y∈ C,x6=y . Furthermore, if z is a received vector in Zn 2 with d(u,z)≤t for some u∈ C then z∈St(u) and z/∈St(v),∀v∈ C \{u} . That is, if a received codeword z∈Zn 2 differs from a codeword u∈ C in t or fewer positions, then every other codeword in C will differ from z in more than t positions. Thus, the nearest neighbor policy will always allow t or fewer errors to be corrected in the code. The code Cis said to be t-error correcting. The Hamming bound is an upper bound for the number of codewords in a code Hoffman et al. (1991) of length nand distance d=2t+1. 6
3.1. Hamming Codes 7 Theorem 3.0.1(Hamming Bound) Suppose Cis a t-error correcting code in Zn 2. Then: |C|· t ∑ i=0n i≤2n, (7) where |C|denotes the number of codewords. A code Cis said to be perfect if |C|·∑t i=0(n i)=2n, meaning every vector in Zn 2is correctable. Definition 3 Let C be an [n,k] linear code. A matrix H with the property that HcT=0⇐⇒ c∈ C is called the parity check matrix for C. Theorem 3.0.2 Let H be a parity check matrix for a linear code C . Then C has distance d if and only if any set of d−1 columns of H is linearly independent, and at least one set of d columns of H is linearly dependent. 3.1 hamming codes Hamming Codes are a class of perfect, linear, easy to decode, 1-error correcting codes. In order to construct a Hamming code C with parameters [n,k] , first we construct the parity check matrix H consisting of all nonzero vectors of length k. The rows of a generator matrix G are just a basis for the null space of H . Lastly, the codewords in C are formed by multiplying all binary vectors of length k by G . The resulting code is a [n,k] linear code with 2ncodewords capable of correcting one error. Example 2 Consider the construction of the [7, 4] Hamming code. The parity check matrix for this code is given by: H= 0001111 0110011 1010101 Solving the equation Hx =0yields a generator matrix G. In this case G is: G= 1110000 1001100 0101010 1101001 Finally, to construct the codewords in C we multiply all k -length binary words, ranging from (0000) to (1111), by G. For instance, the binary word (1000) is coded in Cas (1110000)=(1000)·G. Because the columns in H are the binary representations of the numbers up to 2k−1 , excluding 0 , any two columns are distinct and the minimum number of linearly dependent columns is 3 .
3.1. Hamming Codes 8 Therefore, by Theorem.3.0.2, a Hamming code has distance d=3 . For n=2k−1 and d=2t+1=3 (so t=1), |C|· t ∑ i=0n i=|C|· This proves that all Hamming codes are perfect, one error correcting codes. Hamming codes present a very simple method for detecting errors in received vectors that occur from codewords in linear codes constructed using generator matrices. For a linear code C with parity check matrix H , Hct=0⇐⇒ c∈ C . The problem of correcting errors in a received vector is also very simple for the Hamming Code. First we consider that any received vector r can be decomposed as r=c+e , where c∈ C and e refers to the error vector. Hence Hrt=Hct+Het=Het . Because Hamming codes are one-error correcting and perfect, the only type of error vector, e , we should consider are the vectors ei that contain a one in the ith position and the rest is all zeros. If r/∈C⇐⇒ Hrt6=0 , meaning Hrt is equal to one of the columns of H. Suppose it’s equal to the jth column. This means that the error in r is ej . Note that since the jth column in H is the binary expression of the number j, then the error in ris ej.
3.2. BCH Codes 9 3.2 bch codes Hamming codes are only one-error-correcting. If more than one error occurs during the transmission of a Haming codeword, the received vector will not be corrected to the sent codewod. BCH codes are linear codes and can be constructed to be multiple-error-correcting. These codes present several features that make them very important, namely: •good error-correcting properties when the length is not too big; •relatively easy encoding and correction scheme; •provide a good foundation upon which to base other families of codes Furthermore they are quite extensive, meaning, for any positive integers r and t with t≤2r−1−1 , there is a BCH code of length n=2r−1 which is t-error correcting and has dimension k>n−rt. Definition 4Cis a cyclic code if (a0a1. . . an−1)∈ C ⇐⇒ (a1. . . an−1a0)∈ C It is convenient to represent cyclic codes in terms of polynomials. A polynomial of degree n over K , where K is a field, is a polynomial a0+a1x+a2x2+···+anxn , where the coefficients a0, . . . , an,an6=0 , are elements of K . The set of all polynomials over K is denoted by K[x] and forms a ring. Elements of K[x] will be denoted by f(x),g(x),p(x) and so forth. The polynomial f(x) = a0+a1x+a2x2+···+an−1xn−1 of degree at most n−1 over K may be regarded as the codeword v=a0a1a2. . . an−1 of length n in Kn . Thus a code C of length n can be represented as a set of polynomials over Kof degree at most n−1. Lemma 3.2.1 Let C be a cyclic code and let v∈ C . Then for any polynomial a(x),c(x) = a(x)v(x)mod(1+ xn)is a codeword in C. We define the generator polynomial of a linear cyclic code C to be the unique monic polynomial of minimum degree in C. Theorem 3.2.2 Let C be a cyclic code of length n and let g(x) be the generator polynomial. If n−k= degree(g(x)) then: •Chas dimension k; •The codewords corresponding to g(x),xg(x), . . . , xk−1g(x)are a basis for C; •c(x)∈ C ⇐⇒ c(x) = a(x)g(x)∃a(x):degree(a(x)) <k Theorem 3.2.3g(x) is the generator polynomial for a linear cyclic code of length n if and only if g(x) divides 1+xn Corollary 3.2.3.1 The generator polynomial g(x) for the smallest cyclic code of length n containing the polynomial v(x)is the greatest common divisor of v(x)and 1+xn.
3.2. BCH Codes 10 The simplest generator matrix for a linear cyclic code is the matrix in which the rows are the codewords corresponding to the generator polynomial multiplied by the first k−1 powers of x. G= g(x) xg(x) x2g(x) . . . xk−1g(x) (8) Let C be a linear cyclic code [n,k] with generator polynomial g(x) . Encoding a message consists simply of polynomial multiplication; that is, the message polynomial a(x) is encoded as a(x)g(x) = c(x) , resulting in the codeword polynomial c(x). Instead of storing the entire k×n generator matrix, it is only necessary to store the generator polynomial, which is a significant improvement in terms of the complexity of encoding. Performing the inverse operation (decoding) is achieved by dividing the received codeword c(x)by g(x), yielding the original message polynomial a(x). To construct a linear cyclic code [n,k] , one must find a factor of 1+xn having degree n−k . The fact that every generator must divide 1+xn allows for the discovery of all linear cyclic codes of a given length n. A polynomial f(x) in K[x] of degree at least one is irreducible if it has degree one or is not the product of two polnomials in K[x] , both of which having a degree at least one. An irreducible polynomial over K of degree n,n>1 is said to be primitive if it is not a divisor of 1+xm for any m<2n−1 . Using a primitive polynomial to construct GF(2r) makes computing in the field much easier than using a non-primitive irreducible polynomial. To see this, let β∈Kn represent the word corresponding to xmod h(x) , where h(x) is a primitive polynomial of degree n . Then βi⇐⇒ ximod h(x) . Note that 1=xmmod h(x) =⇒0=1+xmmod h(x) and thus that h(x) divides 1+xm . Since h(x) is primitive, it does not divide 1+xm for m<2n−1 and thus βm6=1 for m<2n−1 . Since βj=βi for j6=i⇐⇒ βi=βj−iβi=⇒βj−i=1 , we conclude that Kn\{0}={βi|i=0, 1, . . . , 2n−2} . In conclusion, every non-zero word in Kn can be represented by some power of β. Definition 5An element α∈GF(2r)is primitive if am6=1for 1≤m<2r−1 An element α∈GF(2r)is said to be a root of a polynomial p(x)∈F[x]if p(α) = 0. For any element α∈GF(2r) , we define the minimal polynomial of α as the polynomial in K[x] of smallest degree having αas a root, denoted mα(x). Theorem 3.2.4Let α∈GF(2r). Let mα(x)be a minimal polynomial of α. Then: •mαis irreducible over K; •if f (x)is any polynomial over Ksuch that f (α) = 0, then mα(x)is a factor of α •the minimal polynomial is unique; •the minimal polynomial mα(x)is a factor of 1+x2r−1 Theorem 3.2.5 Let α∈GF(2r) with minimal polynomial mα(x) , then {α,α2,α4, . . . , α2r−1} is the set of all the roots of mα(x). The degree(mα(x)) is l.c.m{α,α2,α4, . . . , α2r−1}.
3.2. BCH Codes 11 To construct a BCH code of length n , we begin by letting f(x) = xn−1∈Z2[x] . Then the ring R=Z2[x]/(f(x)) can be represented by all polynomial of Z2[x] of degree less than n . The generator polynomial, g(x), is defined as : g(x) = lcm{m1(x),m2(x),m3(x), . . . , m2t(x)}(9) as the least common multiple of the minimal polynomials mi(x)in Z2[x]. Some operations like encoding and decoding require computations using polynomials, so an important fact about polynomials in Z2[x]is that: r ∑ i=1 xi2= r ∑ i=1 x2 i(10) since all cross terms will contain a multiple of 2so they disappear (2 mod 2 =0). Theorem 3.2.6 Let C be a BCH code that results from a primitive polynomial of degree n by considering the first s powers of α , and suppose c(x)∈Z2[x] has degree less than 2n−1 . Then c(x)∈ C ⇐⇒ c(αi) = 0 for i=1, . . . , s. Theorem 3.2.7Let Cbe a BCH code that results from considering the first 2t powers of α. Then Cis t-error correcting.
3.2. BCH Codes 12 Correction in BCH Let C be a BCH code that results from a primitive polynomial of degree n by considering the first 2t powers of α . Suppose c(x)∈ C is transmitted and we receive the polynomial r(x)6=c(X)∈Z2[x] of degree less than 2n−1 . Then r(x) = c(x) + e(x) for some non zero error polynomial e(x)∈Z2[x] of degree less than 2n−1 . Theorem 3.2.6implies that r(αi) = e(αi) for i=1, . . . , 2t . The values of r(αi) are called the syndromes of r(x). Supposing e(x) = xm1+xm2+···+xmp for some integer error position m1<m2<··· <mp with p≤t and mp<2n−1 . To find these error positions, we begin by computing the first 2tsyndromes of r(x), denoted r1,r2, . . . , r2t. r1=r(α) = e(α) = αm1+αm2+. . . +αmp r2=r(α2) = e(α2) = (α2)m1+ (α2)m2+. . . + (α2)mp . . . r2t=r(α2t) = e(α) = (α2t)m1+ (α2t)m2+. . . + (α2t)mp The error locator polynomial, defined as: E(z) = (z−αm1)(z−αm2). . . (z−αmp) =zp+σ1zp−1+. . . +σp is essential to error corretion. Its roots show the error positions in r(x) . To find the roots, we must find the coefficients σ1,σ2, . . . , σp of E(z). These coefficients are the elementary symmetric functions in αm1,αm2, . . . , αmp, meaning: σ1= p ∑ i=1 αmi σ2= p ∑ i,j=1 αmiαmj . . . σp=αm1. . . αmp Evaluating E(αmj) for all 1≤j≤p and multiplying each result by (αmj)i for any 1≤i≤p , since E(αmj) = 0 for all 1 ≤j≤p, yields the following system of equations for 1 ≤i≤p:
3.2. BCH Codes 13 0= (αm1)i[(αm1)p+σ1(αm1)p−1+. . . +σp] 0= (αm2)i[(αm2)p+σ1(αm2)p−1+. . . +σp] . . . 0= (αmp)i[(αmp)p+σ1(αmp)p−1+. . . +σp] By distributing the (αmj)i in the preceding equation and summing the results, we obtain the following equation for 1 ≤i≤p: 0=ri+p+σ1ri+p−1+σ2ri+p−2+. . . +σpri Since this holds for 1≤i≤p , this yields a system of p linear equations in the p unknown σ1,σ2, . . . , σpthat are equivalent to the following matrix equation. r1. . . rp . . .. . . rp. . . r2p−1 σp . . . σ1 = rp+1 . . . r2p (11) If the p×p coefficient matrix is nonsingular, then we can solve uniquely for σ1, . . . , σp , we can then form the error locator polynomial E(z) and determine αm1, . . . , αmp by trial and error as the roots of E(z). This reveals the error positions m1, . . . , mpin r(x). Since the number of errors in a received polynomial r(x) is not known before attempting to correct it, in a t-error correction BCH code it is assumed that the received polynomial contains a maximum of t errors and using the first 2t syndromes of r(x) . If it does not contain exactly t errors, then the matrix in 11 will be singular. In this case, we can simply reduce the number of assumed errors to t−1 and repeat the error correction procedure using only the first 2t−2 syndromes of r(x) . As long as produced matrix in 11 is singular, this procedure can be repeated, each time reducing the number of assumed error until the coefficient matrix in 11 is nonsingular. If the error is in r(x) , then the coefficient matrix will be nonsingular for any number of assumed errors between 1 and t. To consolidate everything said about BCH codes, their encoding and decoding, as well as error correcting, an example is presented. Example 3 Let f(x) = x15 −1 , and choose the primitive polynomial p(x) = x4+x+1 . Then for the element α=x in the field Z2[x]/((p(x)) of order 16 we list the field elements that correspond to the first 15 powers of αin the following table: Let C be the BCH code that results from considering the first six powers of α . To determine the generator polynomial g(x) for C , we must find the minimal polynomials m1(x),m2(x), . . . , m6(x) . Since p(x) is primitive and α=x then p(α) = 0 . From Theorem ..... it follows p(α2) = p(α)2=0 and p(α4) = p(α)4=0 . Thus, m1(x) = m2(x) = m4(x) = p(x). From Theorem .... f(x)can be factorized in the following manner: x15 −1= (x+1)(x2+x+1)(x4+x+1)(x4+x3+1)(x4+x3+x2+x+1).
3.2. BCH Codes 14 Power Field Element α1α α2α2 α3α3 α4α+1 α5α2+α α6α3+α2 α7α3+α+1 α8α2+1 α9α3+α α10 α2+α+1 α11 α3+α2+α α12 α3+α2+α+1 α13 α3+α2+1 α14 α3+1 α15 1 Table 1: Field Elements By substituting α3 and α5 into each of these irreducible factors, we conclude that m3(x) = x4+x3+x2+x+1 and m5(x) = x2+x+1 . Furthermore, m3(α6) = m3(α3)2=0=⇒m6(x) = m3(x) . Thus, g(x) = m1(x)m3(x)m5(x) = x10 +x8+x5+x4+x2+x+1 . The code that results from this generator polynomial is a [15,5] BCH code capable of correcting up to 3errors. Supposing a codeword in C was trasmitted and the received vector r(x)=(101111110010000) . Because g(x) does not divide r(x) , r(x)/∈C . Since C is 3-error correcting, to correct r(x) it is necessary to compute the first six syndromes of r(x) .Using the table of powers of αand the corresponding field elements in Table 1, the syndromes are computed as follows: r1=r(α) =1+α2+α3+α4+α5+α6+α7+α10 =. . . =α3 r3=r(α3) =1+α6+α9+α12 +α15 +α18 +α21 +α30 =. . . =α6 r5=r(α5) =1+α10 +α15 +α20 +α25 +α30 +α35 +α50 =. . . =α10
4.1. Quantum Computation 21 Because quantum computation is interested in manipulating and changing the state of quantum bits it’s important to understand the effects of the Pauli Matrices on simple qubits. X|0i= 0 1 1 0! 1 0!= 0 1!=|1i X|1i= 0 1 1 0! 0 1!= 1 0!=|0i Z|0i= 1 0 0−1! 1 0!= 1 0!=|0i Z|1i= 1 0 0−1! 0 1!= 0 −1!=−|1i From the equations, one concludes that X has the effect of bit-flipping, i.e., transforming a quantum state in its orthogonal state, acting as a NOT gate in classical computation; operator Z has the effect of phase-flipping. The Pauli operators, excluding ˆ I, have the following properties [σi,σj] = σiσj−σjσi=2σk {σi,σj}=σiσj+σjσi=2δi,jˆ I,δi,j= 1 if i=j 0 otherwise The first equation tells us that choosing any two dimensions of spin, their commutator yields the remaining dimension. The anticommutator of two different spin components is zero. 4.1.2Hadamard and CNOT Another essential matrix to perform quantum computation is the Hadamard matrix H=1 √2 1 1 1−1!(41) It has the effect of trasforming a qubit from the computational basis |0i or |1i , to a superposition of the two:
4.1. Quantum Computation 22 H|0i=1 √2 1 1 1−1! 1 0!=1 √2 1 1!=1 √2(|0i+|1i) = |+i H|1i=1 √2 1 1 1−1! 0 1!=1 √2 1 −1!=1 √2(|0i−|1i) = |−i Figure.5denotes the circuit representation of all the gates mentioned above. Figure 5: Single qubit gates Perhaps the most useful controlled operation is the controlled-NOT, or simply CNOT. It’s a quantum gate with two input qubits, known as control qubit |ci and target qubit |ti . The effect of this gate is to take a quantum system of the form |ci|ti→|ci|t⊕ci ; that is, if the control qubit is |1i then the target qubit is flipped, otherwise the target qubit is left alone. The matrix representation of CNOT is CNOT = 1000 0100 0001 0010 (42) Figure 6: Circuit representation for the CNOT. The top line represents the control qubit, the bottom line the target qubit. (from Nielsen and Chuang (2002))
4.1. Quantum Computation 23 Quantum computation employs the usage of multiple qubits. A state |ψi composed of n qubits, all prepared in the state |0i, is written as: |ψi=|0i⊗|0i⊗···⊗|0i2 that is, the tensor product of n|0i kets. Single-qubit operations can still be performed with ease. For example, applying the unitary operator ˆ U to the mth qubit of the state |ψi can be achieved in the following manner ˆ I⊗ˆ I⊗. . . | {z } m-1terms ⊗ˆ U⊗ˆ I⊗ˆ I⊗. . . ˆ I | {z } n-m terms |ψi=|0i⊗|0i⊗. . . | {z } m-1terms ⊗(ˆ U|0i)⊗···⊗|0i | {z } n-m terms 4.1.3Bloch Sphere Another helpful representation of a qubit is to imagine the qubits states as points on the surface of a sphere of unit radius, the Bloch sphere. Opposite points represent a pair of mutually orthogonal states. The north and south poles correspond to the states |0iand |1i. A qubit state |ψi=cosθ 2|0i+exp{iϕ}sinθ 2|1i(43) corresponds to a point with spherical polar coordinates θ and ϕ . Any single-qubit unitary operator can be written in the form ˆ U=expniαˆ I+iβ~ a·ˆ ~ σo where αand βare real constants,~ ais a unitary vector and ˆ ~ σis the vector operator (σx,σy,σz). 2 It is not always necessary to use the tensor product symbol ⊗ . For example, the state |0i⊗|0i⊗|0i can be written as |000i when there is no danger of misunderstanding. The same can’t be applied to operators. For example, ˆ σx⊗ˆ σy⊗ˆ σz is an operator applied to a 3-qubit state while ˆ σxˆ σyˆ σz denotes the three Pauli operators acting on the same qubit. Furthermore, throughout this thesis an operator can be written both as ˆ Iand I.
4.1. Quantum Computation 24 Figure 7: Bloch sphere (from Barnett (2009))
5 QUANTUM ERROR-CORRECTING CODES A noisy quantum channel can be a regular communications channel which we expect to preserve at least some degree of quantum coherence, or it can be the passage of time as a set of qubits interacts with its environment, or it can be the result of operating with a noisy gate on some qubits in a quantum computer Gottesman (1997). The channel applies a superoperator to the input density matrix. We can diagonalize this superoperator and write it as the direct sum of operators acting directly on the pure input states. If a code can correct any of the possible operators, it can correct the full superoperator. 5.1 properties of a quantum code Simillarly to classic codes, quantum codes are linear. A code to encode k qubits in n qubits will have 2k basis codeword. The encodings |ψii of the original 2k basis states form a basis for the space of codewords. When a coherent error occurs, the code states are altered by some linear transformation T: |ψii→T|ψii(44) An error-correction process can be modeled by a unitary linear transformation that entangles the erroneous states T|ψiiwith an ancilla |Aiand transforms the combination to corrected state: (T|ψii)⊗|Ai→|ψii|ATi(45) At this point, the ancilla qubit can be measured in order to restore it to its original state without disturbing the states |ψii . This process will correct the error even if the original state is a superposition of the basis states: T 2k ∑ i=1 ci|ψii!⊗|Ai→ 2k ∑ i=1 ci|ψii!⊗|ATi Definition 11 Let G be the group generated by all 3n Pauli matrices. This group G has the following properties: •M2=±1, M∈G •[A,B] = 0or {A,B}=0, A,B∈G The codewords of the quantum error-correcting code span a subspace Tof the Hilbert space. 25
5.2. Shor’s 9-qubit code 26 In order for the code to correct two errors Ea and Eb , it is necessary to be able to distiguish error Ea acting on a basis codeword |ψii from error Eb acting on a different basis codeword ψj . This can be achieved if Ea|ψiiis orthogonal to Ebψj ψiE† aEbψj=0 (46) when i6=j for correctable errors Ea and Eb . However eq.46 is insufficient to guarantee a code will work as a quantum error-correcting code. When a measurement is made, no information about the actual state of the code can be obtained. To obtain information about a superposition of the basis states means the superposition is broken. Information is obtained when measuring hψi|E† aEb|ψii . Therefore this quantity must be the same for all the basis codewords hψi|E† aEb|ψii=ψjE† aEbψj(47) Combining eq.46 and eq.47 yields ψiE† aEbψj=Cabδij (48) Now suppose E∈Gand ∃M∈S:{E,M}=0. Then ∀|ψi,|φi∈T hφ|E|ψi=hφ|EM|ψi=−hφ|ME|ψi=−hφ|E|ψi so hφ|E|ψi=0 . This implies that for two errors E and F , E|ψi and F|φi are orthogonal for all |ψi,|φi∈Twhenever F†Eanticommutes with everything in S. It is assumed that errors occur independently on different qubits, with equal probability of being a σx,σyor σzerror. 5.2 shor’s 9-qubit code In this code we wish to protect 1bit of information from all possible errors that can occur. To do this we build 1logical qubit, consisting of 9qubits, in the following manner |0i→|¯ 0i= (|000i+|111i)(|000i+|111i)(|000i+|111i |1i→|¯ 1i= (|000i−|111i)(|000i−|111i)(|000i−|111i) The data is no longer stored in a single qubit but in nine instead. To understand error detection in this code first we need to understand the effect of the operator σz⊗σz in a given state |ψi= |ψ0i⊗|ψ1i⊗···⊗|ψni≡|ψ0ψ1. . . ψni. Definition 12 Let σzibe the operator σzapplied to the ith qubit of a multiple particle system. Applying the operator σzi⊗σzj, 0 ≤i≤n, 0 ≤j≤n,i6=j, to the state |ψi yields the following eigenvalue εi,j εi,j= +1 if |ψii=ψj −1 if |ψii6=ψj
5.2. Shor’s 9-qubit code 27 Therefore, measuring the eigenvalue of this operator σzi⊗σzj is equivalent to comparing the value of two qubits without actually measuring them, since measurement would destroy the superposition. Using both σz1⊗σz2 and σz1⊗σz3 operator on |¯ 0i informs us if an error occurred in the first block of three qubits and where said error lies. If the first two qubits are the same, then ε= +1 ; otherwise, ε=−1 . Assuming the first qubit was flipped, then by comparing the first two qubits, we find they are different ( ε1,2 =−1 ), which is not allowed for any valid codeword in the code. Therefore we know an error occured, and furthermore, it flipped either the first or second qubit. Comparing the first and third qubits we again find they are different ( ε1,3 =−1 ) . This means the error occured in the first qubit and correction can be achieved simply by flipping the erroneous qubit. Similarly, to detect a sign error, we compare the signs of the first and second blocks and the first and third blocks of three qubits. This is equivalent to measuring the eigenvalues of σx1σx2σx3σx4σx5σx6 and σx1σx2σx3σx7σx8σx9 . If the signs agree, the eigenvalues will be +1 ; if they disagree, the eigenvalues will be −1 . It is also possible to have both a bit flip and a sign flip on the same qubit. However, by going through both processes described above, it is possible to fix first the bit flip then the sign flip. The set of operators that fix |¯ 0i and |¯ 1i form a group S , called the stabilizer of the code, and Mi are called the generators of this group. In order to totally correct the code, we must measure the eigenvalues of a total of eight operators, therefore, this code has 8generators. M1σzσzIIIIIII M2σzIσzIIIIII M3IIIσzσzI I I I M4IIIσzIσzIII M5IIIIIIσzσzI M6IIIIIIσzIσz M7σxσxσxσxσxσxIII M8σxσxσxIIIσxσxσx Table 2: The stabilizer for Shor’s 9-qubit code If more than one one qubit of a nine-tuple decoheres, the encoding scheme does not work Shor (1995a). If each qubit decoheres with a probability of p , then the probability that k qubits do not decohere is (1−p)k . The probability that a t-error correcting code works, that is, that less than t errors occcur is given by t ∑ i=0N N−i(1−p)N−ipi,
5.3. Stabilizer Coding 28 where N represents the length of the code, in this case N=9 and t=1 . For this code, the probability that less than two errors occur is perrors<2=9 9(1−p)9+9 8(1−p)8·p = (1−p)9+9p(1−p)8 = (1−p)8(1−p+9p) = (1−p)8(1+8p) The probability that at least two qubit in any particular nine-tuple decohere is 1−(1+8p)×(1− p)8≈36p2 , and the probability that 9k qubits can be decoded to give the original quantum state is approximately (1−36p2)k . For a probability of decoherence less than 1 36 ≈3% this encoding provides an improved storage method for quantum-coherent states of large number of qubits. 5.3 stabilizer coding Definition 13 The stabilizer S of a subspace T is defined as S ={M∈G:M|ψi=|ψi∀|ψi∈T} The stabilizer always forms a group. Since the generators must commute with each other, the stabilizer is an Abelian group. In general. if M∈S,{M,E}=0 and |ψi∈T, then ME |ψi=−EM |ψi=−M|ψi(49) Definition 14 Let Gbe a group. The normalizer of G, denoted N(G)is defined to be: N(G) = {U:UGU†=G}, 5.3.1X and Z operators Since the elements of N(S) move codewords around within T , they have a natural interpretation as encoded operations on the codewords. Since S fixes T , actually only N(S)/S will act on T nontrivially. If we pick a basis for T consisting of eigenvectors of n commuting elements of N(S) , we get an automorphism N(S)/S=⇒Gk . N(S)/S can therefore be generated by i (which we will by and large ignore) and 2k equivalence classes, which I will write Xi and Zi ( i=1 . . . k ), where Xi maps to σxi in Gk and Zi maps to σzi in Gk . They are encoded σx and σz operators for the code. If k=1 , I will write X1=Xand Z1=Z. The Xand Zoperators satisfy: [Xi,Xj] = 0 (50) [Zi,Zj] = 0 (51) [Xi,Zj] = 0(i6=j)(52) {Xi,Xj}=0 (53)
5.3. Stabilizer Coding 29 Suppose we have an X which in this language is written (u|v) = (u1u2u3|v1v2v3) , where u1 and v1 are r -dimensional vectors, u2 and v2 are (n−k−r) -dimensional vectors, and u3 and v3 are k -dimensional vectors. However, elements of N(S) are equivalent up to multiplication by elements of S . Therefore, we can also perform eliminations on X to force u1=0 and v2=0 . Then, because X is in N(S), we must satisfy: I A1A2B C1C2 0 0 0 D I E ! vT 1 0 vT 3 0 uT 2 uT 3 = vT 1+A2vT 3+C1uT 2+C2uT 3 uT 2+EuT 3!= 0 0!(54) Suppose we want to choose a complete set of k X operators. We can combine their vectors into two k×n matrices (0U2U3|V10V3). We want them to commute with each other, so U3VT 3+V3UT 3=0 . Suppose we pick U3=I . Then we can take V3=0, and by equation 54, U2=ET and V1=ETCT 1+CT 2 . The rest of the construction will assume that this choice has actually been made. Another choice of U3 and V3 will require us to perform some operation on the unencoded data to compensate. We can also pick a complete set of k Z operators, which act on the code as encoded σz operators. They are uniquely defined (up to multiplication by S , as usual) given the X operators. Given the properties stated in 50, we can bring a Zioperator into the standard form (0U0 2U0 3|V0 10V0 3). Then U0 3VT 3+V0 3UT 3=I(55) When U3=I and V3=0, V0 3=I . Since equation 54 holds for the Z operators too, U0 2=U0 3=0 and V0 1=AT 2. 5.3.2Encoding and Decoding Stabilizer Codes In order to actually encode states using a quantum code, we need to decide which states will act as basis states for the coding space. In order to do this, it is convenient to use language of binary vector spaces Cleve and Gottesman (1997). Definition 15 Let M1, . . . , Mn−k be the stabilizer generators. To represent them in a binary vector spaces, we simply write the stabilizer as a pair of (n−k)×n binary matrices, the rows corresponding to the different generators and the columns to the different qubits. The left block has a 1whenever the generator has a σx in the appropriate place. The same for the right block whenever the generator has a σz. In order to produce codewords, the stabilizer in matrix form must be converted to the standard form. This conversion will involve two types of operations: • Replacing a generator Mi with MiMj for some generator Mj,j6=i . Since the stabilizer is a group, it is unchanged by this operation. The corresponding effect on the binary matrices is to add row jto row i.
5.3. Stabilizer Coding 30 •Rearranging qubits in the code, which corresponds to reordering the columns of the matrix. Combining these two operations, we can perform Gaussian elimination, putting the code in the form: I A B C 0 0 D E Another Gaussian elimination on E yields: IA1A2BC1C2 0 0 0 D1IE2 0 0 0 D20 0 ! We can always put the code into the standard form: IA1A2BC1C2 0 0 0 D I E 5.3.3Networks for Encoding and Decoding Given a stabilizer in standard form along with the X operators in standard form, it is straightforward to produce a network to encode the corresponding code. The operation of encoding a stabilizer code can be written as: |c1. . . cki→∑ M∈S MXc1 1. . . Xck k|0 . . . 0i = (I+M1). . . (I+Mn−k)Xc1 1. . . Xck k|0 . . . 0i (56) where Mi are the generators of the stabilizer, and Xi are the encoded σx operators of the k encoded qubits. Because in standard form the first r generators Mi have a 1, corresponding to a σx , on the ith qubit, they can be written as follows: Mi≡Xi=⇒I+Mi=I+Xi=H(57) Therefore, applying the first r generators to each pivot qubit can be written as a simple Hadamard transform 41. Next, we apply each generator Mi conditioned on the ith qubit. We can do this because the control qubit has not been the target of a previous operation, therefore it hasn’t been changed. This is the importance of putting the stabilizer matrix and the operators X and Z in the standard form. We can decode a code by performing the above process in reverse. However, if we want to measure the ith encoded qubit without decoding, we can measure the eigenvalue of Zi . If the eigenvalue is +1 , the ith encoded qubit is |0i ; if it is −1 , the ith encoded qubit is |1i . In standard form, Zi is the tensor product of σz , meaning it will have eigenvalue ε= (−1)P , where P is the parity of the qubits acted on by Zi . For the 5qubit code example the decoding scheme can be achieved by the circuit in Fig.9.
6.1. Results 37 Figure 15: Output of the system after computation in the IBMQ Guadalupe computers in some areas. After that, consumers, industries and businesses will significantly alter the way that they operate, sweeping away classical computers and replacing them forever with quantum computers.
7 CONCLUSION The dissertation aimed to study quantum error correcting stabilizer codes and to present an algorithm that simulates a simple data transmission scenario with error correction. The algorithm has been evaluated both via simulation of a quantum machine, indicative of future quantum computing capabilities, and on a real quantum computer. We obtained good results in the simulator, unlike in the real quantum computer where the results were pure noise. 7.1 prospect for future work Recently, IBM announced that mid-circuit measurements will be possible, making fault-tolerant computation possible, although in the short term, due to requiring an increased gate count and circuit complexity, may be shown to not improve the error correction significantly. Having said that, better quantum gates, increased decoherence times and better qubit connectivity will improve quantum computation significantly, allowing for bigger and more complex computations. The algorithm could also be tested using a better simulator. The naive approach of hard coding the errors into the transmission could be replaced by a simulator that includes a noise evolution operator and with that, better understand the limitations of the encoding. For instance, if the noisy simulation indicates that, similarly to a real machine, a specific error is more likely to appear, then a code with better ajusted properties could be used instead. Lastly, stabilizer coding is a mathematical tool and, as such, disregards the nature of the qubits. Different error correcting methods that take into account the nature of the qubit may prove to be useful. 38
BIBLIOGRAPHY Ibm quantum, 2021. URL https://quantum-computing.ibm.com. C. Adami and N. J. Cerf. Quantum computation with linear optics. In 1st NASA Conference on Quantum Computing and Quantum Communications,2 1998. A.S.Holevo. Bounds for the quantity of information transmitted by a quantum communication channel. Probl. Peredachi Inf.,9:3–11,1973. Stephen Barnett. Quantum information, volume 16. Oxford University Press, 2009. Charles H. Bennett, Fran c¸ ois Bessette, Gilles Brassard, Louis Salvail, and John Smolin. Experimental quantum cryptography. Journal of Cryptology,5(1):3–28, Jan 1992. ISSN 1432-1378. doi: 10.1007/ BF00191318. URL https://doi.org/10.1007/BF00191318. Anasua Chatterjee, Paul Stevenson, Silvano De Franceschi, Andrea Morello, Nathalie P. de Leon, and Ferdinand Kuemmeth. Semiconductor qubits in practice. Nature Reviews Physics,3(3):157– 177, Mar 2021. ISSN 2522-5820. doi: 10.1038/s42254-021-00283-9. URL https://doi.org/10.1038/ s42254-021-00283-9. Richard Cleve and Daniel Gottesman. Efficient computations of encodings for quantum error correction. Physical Review A,56(1):76–82, Jul 1997. ISSN 1094-1622. doi: 10.1103/physreva.56.76. URL http://dx.doi.org/10.1103/PhysRevA.56.76. P. A. M. Dirac. The Principles of Quantum Mechanics. Clarendon Press, 1930. Paul Adrien Maurice Dirac. The principles of quantum mechanics. Number 27. Oxford university press, 1981. Jacques Dutka. The early history of the factorial function. Archive for History of Exact Sciences,43 (3):225–249, Sep 1991. ISSN 1432-0657. doi: 10.1007/BF00389433. URL https://doi.org/10.1007/ BF00389433. Vittorio Giovannetti, Seth Lloyd, and Lorenzo Maccone. Quantum-enhanced measurements: Beating the standard quantum limit. Science,306(5700):1330–1336,2004. ISSN 0036-8075. doi: 10.1126/ science.1104149. URL https://science.sciencemag.org/content/306/5700/1330. Daniel Gottesman. Stabilizer codes and quantum error correction, phd thesis, 1997. Daniel Gottesman. Theory of fault-tolerant quantum computation. Physical Review A,57(1):127–137, Jan 1998. ISSN 1094-1622. doi: 10.1103/physreva.57.127. URL http://dx.doi.org/10.1103/PhysRevA. 57.127. 39
bibliography 40 W. Heisenberg. ¨ Uber den anschaulichen inhalt der quantentheoretischen kinematik und mechanik. Zeitschrift f ¨ ur Physik,43(3):172–198, Mar 1927. ISSN 0044-3328. doi: 10.1007/BF01397280. URL https://doi.org/10.1007/BF01397280. D. G. Hoffman, Wal, D. A. Leonard, C. C. Lidner, K. T. Phelps, and C. A. Rodger. Coding Theory: The Essentials. Marcel Dekker, Inc., USA, 1991. ISBN 0824786114. J. Kelly, R. Barends, A. G. Fowler, A. Megrant, E. Jeffrey, T. C. White, D. Sank, J. Y. Mutus, B. Campbell, Yu Chen, and et al. State preservation by repetitive error detection in a superconducting quantum circuit. Nature,519(7541):66–69, Mar 2015. ISSN 1476-4687. doi: 10.1038/nature14270. URL http://dx.doi.org/10.1038/nature14270. H. J. Kimble. The quantum internet. Nature,453(7198):1023–1030, Jun 2008. ISSN 1476-4687. doi: 10.1038/nature07127. URL http://dx.doi.org/10.1038/nature07127. Raymond Laflamme, Cesar Miquel, Juan Pablo Paz, and Wojciech Hubert Zurek. Perfect quantum error correcting code. Phys. Rev. Lett.,77:198–201, Jul 1996. doi: 10.1103/PhysRevLett.77.198. URL https://link.aps.org/doi/10.1103/PhysRevLett.77.198. Michael A Nielsen and Isaac Chuang. Quantum computation and quantum information. Cambridge Univ. Press., 2002. Steven Roman. Coding and information theory, volume 134. Springer Science & Business Media, 1992. C. E. Shannon. A mathematical theory of communication. The Bell System Technical Journal,27(3): 379–423, July 1948. ISSN 0005-8580. doi: 10.1002/j.1538-7305.1948.tb01338.x. Peter W. Shor. Scheme for reducing decoherence in quantum computer memory. Phys. Rev. A,52: R2493–R2496, Oct 1995a. doi: 10.1103/PhysRevA.52.R2493. URL https://link.aps.org/doi/10.1103/ PhysRevA.52.R2493. Peter W. Shor. Scheme for reducing decoherence in quantum computer memory. Phys. Rev. A,52: R2493–R2496, Oct 1995b. doi: 10.1103/PhysRevA.52.R2493. URL https://link.aps.org/doi/10.1103/ PhysRevA.52.R2493. P.W. Shor. Algorithms for quantum computation: discrete logarithms and factoring. In Proceedings 35th Annual Symposium on Foundations of Computer Science, pages 124–134,1994. doi: 10.1109/SFCS. 1994.365700. P.W. Shor. Fault-tolerant quantum computation. In Proceedings of 37th Conference on Foundations of Computer Science, pages 56–65,1996. doi: 10.1109/SFCS.1996.548464. W. G. Unruh. Maintaining coherence in quantum computers. Physical Review A,51(2):992–997, Feb 1995. ISSN 1094-1622. doi: 10.1103/physreva.51.992. URL http://dx.doi.org/10.1103/PhysRevA. 51.992. W. K. Wootters and W. H. Zurek. A single quantum cannot be cloned. Nature,299(5886):802–803, Oct 1982. ISSN 1476-4687. doi: 10.1038/299802a0. URL https://doi.org/10.1038/299802a0.
A QISKIT IMPLEMENTATION a.1 the algorithm from q i s k i t import * #[ n , k , d ] quantum code n = 5 k = 1 r = n - k M1 = [ [ 1 , 0 , 0 , 0 , 1 ] , [ 1 , 1 , 0 , 1 , 1 ] ] M2 = [ [ 0 , 1 , 0 , 0 , 1 ] , [ 0 , 0 , 1 , 1 , 0 ] ] M3 = [ [ 0 , 0 , 1 , 0 , 1 ] , [ 1 , 1 , 0 , 0 , 0 ] ] M4 = [ [ 0 , 0 , 0 , 1 , 1 ] , [ 1 , 0 , 1 , 1 , 1 ] ] M = [M1,M2,M3,M4] X = [[0 ,0 ,0 ,0 ,1] ,[1 ,0 ,0 ,1 ,0]] Z = [ [ 0 , 0 , 0 , 0 , 0 ] , [ 1 , 1 , 1 , 1 , 1 ] ] def sendMessage ( message , qc , qbits , output , e r r o r b i t ) : #encoding i nto the T space f o r i in range ( r ) : qc . h( qbits [ i ] ) i f M[ i ] [ 1 ] [ i ] == 1: qc . z ( q b i t s [ i ] ) #Generators f o r i in range ( r ) : f o r j in range ( n) : #Mx i f M[ i ] [ 0 ] [ j ] and i != j : qc . cx ( qbits [ i ] , q b i t s [ j ] ) #Mz 41
A.1. The algorithm 42 i f M[ i ] [ 1 ] [ j ] and i != j : qc . cz ( qbits [ i ] , q b i t s [ j ] ) qc . b a r r i e r ( ) #Encoding the message i f ( message == 1) : f o r i in range (n) : i f X [ 0 ] [ i ] == 1: qc . x ( qbits [ i ] ) i f X [ 1 ] [ i ] == 1: qc . z ( q b i t s [ i ] ) #Random Error during transmission qc . x( qb its [ e r r o r b i t ] ) #Decoding #Generators i n r e v e r s e ord er f o r i in range ( r -1 , -1 , -1 ) : f o r j in range ( n) : #Mx i f M[ i ] [ 0 ] [ j ] and i != j : qc . cx ( qbits [ i ] , q b i t s [ j ] ) #Mz i f M[ i ] [ 1 ] [ j ] and i != j : qc . cz ( qbits [ i ] , qb i t s [ j ] ) qc . b a r r i e r ( ) #decoding out of the T space f o r i in range ( r ) : i f M[ i ] [ 1 ] [ i ] == 1: qc . z ( q b i t s [ i ] ) qc . h( qbits [ i ] ) f o r i in range (n) : qc . measure ( qbits [ i ] , output [ i ] )
A.2. Reading the results 43 a.2 reading the results The function countsToResult() , together with the function parity() , allows the user to transform the 5 qubit output that he receives and read its parity in order to know the message sent. def pa rity ( s ) : n = 0 f o r i in range ( l en ( s ) ) : n = n + i n t ( s [ i ] ) return (n%2 == 0) def countsToResult ( l ) : l = l i s t ( l ) output = – ’ 0 ’ : 0 , ’ 1 ’ : 0 ˝ f o r i in range ( len ( l ) ) : i f ( par i ty ( l [ i ] [ 0 ] ) ) : output [ ’ 0 ’ ] += l [ i ] [ 1 ] e l s e : output [ ’ 1 ’ ] += l [ i ] [ 1 ] return output #Both the message and the e r r o r b i t would change acco rding ly message = 0 e r r o r b i t = 0 qbits = QuantumRegister (n , ” qbit ” ) output = C l a s s i c a l R e g i s t e r (n , ”output ” ) qc = QuantumCircuit ( qbits , output ) sendMessage ( message , qc , qbits , output , e r r o r b i t ) a.2.1Qasm Simulator
A.2. Reading the results 44 # Use qasm˙simulator backend˙sim = BasicAer . get˙backend ( ’ qasm˙simulator ’ ) # Execute the c i r c u i t on the qasm simulator . jo b˙sim = execute ( qc , backend˙sim , shots =1000) # Grab the r e s u l t s from the job . r e s u l t ˙ s i m = job ˙sim . r e s u l t ( ) counts = r e s u l t ˙ s i m . g et˙c ounts ( qc ) from q i s k i t . t o o ls . v i s u a l i z a t i o n import p lot˙h is togr am out = countsToResult ( counts . items ( ) ) plot˙histogram(output) a.2.2IBMQ Guadalupe backend = provider . get˙backend ( ’ ibmq˙guadalupe ’ ) qobj = assemble ( t r a n s p i l e ( qc , backend=backend ) , backend=backend , shots = 1024) job = backend . run ( qobj ) r e s u l t s = job . r e s u l t () counts = r e s u l t s . g et ˙ c ounts ( ) plot˙histogram(counts)