<<

1 Circuit-based quantum random access memory for classical data with continuous amplitudes

Tiago M. L. de Veras, Ismael C. S. de Araujo, Daniel K. Park, Adenilton J. da Silva,

Abstract—Loading data in a quantum device is required in several quantum computing applications. Without an efficient loading procedure, the cost to initialize the algorithms can dominate the overall computational cost. A circuit-based quantum random access memory named FF-QRAM can load M n-bit patterns with computational cost O(CMn) to load continuous data where C depends on the data distribution. In this work, we propose a strategy to load continuous data without post-selection with computational cost O(Mn). The proposed method is based on the probabilistic quantum memory, a strategy to load binary data in quantum devices, and the FF-QRAM using standard quantum gates, and is suitable for noisy intermediate-scale quantum computers.

Index Terms—Quantum RAM, Quantum state initialization, Data loading in quantum devices !

1 INTRODUCTION The classical data can be represented as a quantum state

M−1 UANTUM computation [1], [2] has the potential to X |ψi = x |p i (2) speed up the solution of certain computational prob- k k Q k=0 lems. These speedups are due to the inherent properties of quantum mechanics, such as superposition, entangle- using n qubits. When n = log2(M), this is equivalent to ment, and interference. The power of quantum computation amplitude encoding [8], which achieves exponential data over its classical counterpart has been theoretically demon- compression. Hereinafter, we refer to the data representation strated in several problems, such as simulating quantum in the form of Eq. (2) as generalized amplitude encoding systems [2], [3], unstructured data search [4], prime factor- (GAE). The resource overhead, such as the number of ization [5], machine learning [6]. However, the development qubits and the circuit depth, for preparing the quantum of full-fledged quantum hardware capable of operating effi- data can dominate the overall computational cost due to ciently on these problems remains unsolved. the quantum measurement postulate — one often needs to A desideratum for practical and wide application of repeat the same algorithm multiple times to gather mea- quantum algorithms is the efficient means to load and surement statistics while each measurement destroys the update classical data in a quantum computer [7]. In other quantum state. Moreover, the state initialization must be words, a programmer needs to be able to encode the input carried out substantially faster than the decoherence time. data structured as Therefore, a fast algorithm for initializing the quantum data is of critical importance, and this is the problem that we ( ) X 2 n address in this manuscript. The data loading procedure D = (xk, pk)|xk ∈ C, |xk| = 1, pk ∈ {0, 1} , (1) should be designed with quantum circuit elements since the k circuit model provides systematic and efficient instructions to achieve universal quantum computation. where 0 ≤ k < M, into a quantum state efficiently. In addi- The initialization of quantum data can be achieved by tion, pk[j] denotes jth bit of a pattern pk, with 0 ≤ j < n. utilizing a quantum random access memory (QRAM). The arXiv:2011.07977v1 [quant-ph] 16 Nov 2020 bucket brigade model for QRAM introduced in Ref [9] uses © 2020 IEEE. Personal use of this material is permitted. Permission from IEEE O(M) quantum hardware components and O(log2(M)) must be obtained for all other uses, in any current or future media, including 2 reprinting/republishing this material for advertising or promotional purposes, time steps to return binary data stored in M memory cells creating new collective works, for resale or redistribution to servers or lists, or in superposition. This procedure can be expressed as reuse of any copyrighted component of this work in other works. M−1 M−1 • T. M. L. de Veras is with Centro de Inform´atica,Universidade Federal 1 X QRAM 1 X √ |ki|0i −−−−−→ √ |ki|pki. (3) de Pernambuco and Departamento de Matem´atica,Universidade Federal M M Rural de Pernambuco, Recife, Pernambuco, Brazil. k=0 k=0 • I.C.S. de Araujo is with Centro de Inform´atica,Universidade Federal de Pernambuco and the Departamento de Computa¸c˜ao,Universidade Federal Unfortunately, translating this model to the quantum circuit Rural de Pernambuco, Recife, Pernambuco, Brazil. model while retaining its advantage is difficult [10], [11]. • D. K. Park is with School of Electrical Engineering, Korea Advanced Moreover, the full state initialization requires additional Institute of Science and Technology, Daejeon, Korea. • A.J. da Silva is with Centro de Inform´atica, Universidade Federal de steps. First, controlled rotations are applied to prepare Pernambuco, Recife, Pernambuco, Brazil. M−1 E-mail: [email protected] q  1 X 2 √ |ki|pki 1 − |xk| |0i + xk|1i . (4) M k=0 2

Then by uncomputing |pki and post-selecting the last reg- Equation (5) can be generalized to express a gate that is ister onto |1i the amplitude encoding is completed [12]. controlled by multiple qubits. Given a quantum state |ψi, Similarly, the GAE can be achieved by uncomputing |ki containing n + 1 bits x0, x1, . . . , xn−1, xn, we use instead. CnX |ψi (6) Ref. [13] introduced a QRAM architecture that is con- (x0x1...xn−1),xn structed with the standard quantum circuit elements to to denote an n-qubit controlled-X operation, which trans- provide flexibility and compatibility with existing quantum forms the target |xni to |xn ⊕ x0 · x1 · ... · xn−1i. computing techniques. This model registers the classical This work also uses single-qubit rotations controlled by data structure D with M patterns into quantum format n n qubits, denoted by C Ra(θ), where a is one of the axes by repeating the execution of a quantum circuit consisting x, y or z. Note that a multi-qubit controlled unitary gate of O(n) qubits and O(Mn) flip-register-flop operations C can be decomposed to n − 1 Toffoli gates and a single-qubit times, and hence called flip-flop QRAM (FF-QRAM). The controlled unitary gate using n − 1 ancillae [15]. repetition is necessary to post-select the correct outcome for Similarly, a bit-flip operator controlled by a classical bit encoding continuous data (similar to explanations around can be defined as Eq. (4). When the FF-QRAM was first introduced, the extra cXx ,x (7) cost for post-selection was neglected. However, C can be a 0 1 function of M and n, depending on the given classical data. which applies X to |x1i if x0 = 1. The FF-QRAM algorithm Therefore, designing a QRAM for general classical data uses a bit-flip operator that flips the target qubit if the without the post-selection procedure, or with a minimal classical control bit is 0. In this case, we denote the operator number of repetitions, remains a critical open problem. On with an overline as cX¯ x0,x1 . the other hand, when storing a set of binary patterns into Another important operator in this work is a gate con- a quantum state with equal probability amplitudes, the trolled by classical and quantum states as follows. Given a post-selection is not necessary. The probabilistic quantum classical bit p, this operation works as memory (PQM) [14] is a viable method to achieve this. Both • | i FF-QRAM and PQM are not fully satisfactory as the former If p = 0, do X m . • If p = 1, do CX |u mi, requires expensive post-selection, and the latter can only ,m 2 encode binary data. and its quantum circuit representation is depicted in Fig- The main contribution of this work is twofold. First, we ure 1. show that the number of repetitions for post-selection in the FF-QRAM algorithm can be reduced by using the PQM as a preliminary step of the FF-QRAM and preprocessing the classical data. Second, we present a deterministic quantum data preparation algorithm based on FF-QRAM and PQM that achieves the generalized amplitude encoding without post-selection. The rest of this manuscript is structured as follows. Fig. 1: A quantum circuit representation of the classical- Section 2 gives a brief description of the main quantum quantum controlled gate that applies X to |mi if p = 0, gates used in this work. Section 3 provides a brief review and applies CX if p = 1. on FF-QRAM [13] and PQM [14], the previous works by u2,m which the current work is inspired. Section 4 shows that in the worst-case FF-QRAM has an exponential computa- The PQM algorithm uses a controlled unitary operator r tional cost due to post-selection. Section 5 presents the main denoted by CSx0,x1 , which applies results: methods to improve the post-selection probability q  r−1 √1 and to remove the need for post-selection. Section 6 presents r r r S =  q  , (8) proof-of-principle experiments to demonstrate the improve- √−1 r−1 ment achieved by our methods, and Section 7 draws the r r conclusion. where r ∈ N, to the target x1 if x0 = 1. Now, given a single-qubit unitary matrix

2 QUANTUM OPERATORS  θ iλ θ  cos 2 −e sin 2 This section is dedicated to define unitary operators that U3 =   , (9) will appear in this manuscript besides the well-known gates, iφ θ i(λ+φ) θ e sin 2 e cos 2 such as I, X and Ry(θ) [15]. For controlled unitary gates, the control and the target it is possible to obtain θ, λ and φ, such that U3 can be will be indicated by a subscript, separated by a comma, in rewritten as a matrix with two parameters, xk and γk, as which the control qubit appears first. Given a quantum state follows |ψi containing bits x0 and x1, we use q γ −|x |2  k k √xk (xk,γk) γk γk CX |ψi (5) U = ∗ . x0,x1 3  −x q γ −|x |2  (10) √ k k k γ γ to indicate a controlled-X operation, which transforms the k k target |x1i to |x1 ⊕ x0i. To obtain (10), it is necessary that: 3

q 2 q 2 θ γk−|xk| γk−|xk| (i) cos = ⇐⇒ θ = 2 arccos . where |θki = cos(θk/2)|0i + sin(θk/2)|1i. The angle θk is 2 γk γk chosen based on xk. Note that Ref. [13] does not discuss (ii) −eiλ sin θ = − (cos λ + i sin λ) sin θ = √xk . explicitly on how to find the angle. Thus, in this section 2 2 γk This admits one of the following solutions: we show the condition necessary to obtain this angle. Later, √  a  in an example, we will show how the angle can be found. a) λ = arccos − √ θ γk sin 2 Next, cX¯ is applied again on the address qubits with the √  b  controlling bits being pk. This is the flop operation that b) λ = arcsin − √ θ . γk sin 2 results in i(λ+φ) θ (iii) Therefore φ = −λ is the solution to e cos 2 . X |ψ3ik = αk|pkiB|θkiR + αt|tiB|0iR. (15) t=6 k (xk,γk) The unitary operator U3 shown in Eq. (10) is the key r We are ready to go through the algorithm again and to ingredient in this work, inspired by S , where γk = γk−1 − 2 load the next input (xk , pk ). Proceeding in a similar |xk−1| is a complex iteration variable with 1 6 k 6√M − 1, +1 +1 √ way to the previous step and applying the flip-flop oper- γ0 = 1, and M ∈ N. Furthermore, xk = a + i b is a complex number with its complex conjugate denoted by ation with pk+1 and the controlled-rotation with the angle ∗ r θ(k+1), we obtain xk. While CS can load binary data only, the controlled (x ,γ ) operation of U k k enables the loading of complex data. 3 |ψ4ik,k+1 =αk|pkiB|θkiR + αk+1|pk+1iB θ(k+1) R X + αt|tiB|0iR. (16) 3 RELATED WORKS t=6 k,k+1 In this section, we briefly review two storage algorithms Performing this procedure M times, all M inputs are that motivated this work, namely FF-QRAM and PQM. We registered in the quantum state as follows. point readers to Refs. [13] and [14], [16] for more details on M−1 FF-QRAM and PQM, respectively. X X αk|pki[cos(θk/2)|0i + sin(θk/2)|1i] + αt|ti|0iR. k=0 t=6 k 3.1 Flip-Flop Quantum RAM (17) The objective of the FF-QRAM algorithm [13] is to load To complete the generalized amplitude encoding, firstly, classical data D with M patterns shown in Eq. (1) to a we need to get rid of the terms where the register qubit is quantum state shown in Eq. (2) using a quantum circuit. in |0iR. So we must obtain a convenient θk, such that the For this, the quantum circuit must receive as the initial state probability of amplitude for state |1i is high. Then, we will of the algorithm evaluate n M−1 2 −1 X 2 X P (|1i) = α sin(θ /2) . |ψ0i = αt|tiB|0iR, (11) k k (18) t=0 k=0 where B and R indicate n address qubits and a register At this point, it is clear that the angle θk must satisfy the with one qubit, respectively, |ti is a computational basis of condition ∈ ≤ n αk sin(θk/2) n qubits, αt C, and M 2 . p = xk. (19) For the input (xk, pk), we can associate the following P (|1i) initial state: The FF-QRAM algorithm takes at least O(nM) steps for X each run of the quantum circuit, and there is an additional |ψ0ik = αk|pkiB|0iR + αt|tiB|0iR. (12) cost for post-selection [13]. If P (|1i) ≈ 1, then the desired t=6 k state shown in Eq. (2) is obtained with a high probability.

To obtain the state |ψ1ik, the controlled bit-flip operator cX¯ , Otherwise, the additional cost for post-selection can be non- controlled by a classical input string pk, is applied to the negligible. We will show in Section 4 that this additional cost can compromise the efficiency of the algorithm. address qubits (indicates by B) of |ψ0ik. The cX¯ operation flips the target qubit if the control bit is 0. This is the flip The FF-QRAM algorithm is summarized in Algorithm 1, operation that results in and a quantum circuit for storing a particular data (xk, pk) is depicted in Figure 2. ⊗n X |ψ1ik = αk|1iB |0iR + αt t ⊕ pk B|0iR, (13) ⊗n |t⊕pki=6 |1i 3.2 Loading binary patterns with |¯ii being the ith negated binary string. The terms with The PQM [14], [16] initialization algorithm is based an overline means that each bit is flipped if the control bit is on [17], [18], and is capable of storing a classical binary M−1 zero. In the next step, a multi-qubit controlled operator that dataset data = ∪k=0 {pk}, where pk is an n-bit pattern (i.e. n applies Ry(θk) = cos(θk/2)I − i sin(θk/2)Y on the register pk ∈ {0, 1} ), in a quantum state as ⊗n qubit |0iR if the n-qubit address state is |1i yields the M−1 state 1 X |Mi = √ |pki, (20) ⊗n X M k=0 |ψ2ik = αk|1i |θkiR + αt t ⊕ pk |0iR, (14) ⊗n |t⊕pki=6 |1i with computational cost O(nM). 4

Fig. 2: One iteration of the FF-QRAM data storage algorithm.

Algorithm 1: FF-QRAM Algorithm 2: Probabilistic quantum memory stor- M−1 P age algorithm input : data = {(xk, pk)}k=0 , |ψ0i = t αt|ti|0i PM−1 M−1 output: |ψi = k=0 xk|pki, s input : data = {pk}k=0 1 load data |ψi M−1 ( , ): |ψi = √1 P |p i output: M k=0 k 2 foreach (xk, pk) ∈ data do Qn−1 1 load_binary (data, |ψi): 3 j=0 cX¯ pk[j],m[j]|ψi n 2 Initial state |ψ0i = |0, 0, ··· , 0; 01; 0, 0, ··· , 0i 4 C RyR,B(θk)|ψiR|0iB 3 ∈ Qn−1 foreach pk data do 5 j=0 cX¯ pk[j],m[j]|ψi 4 |ψk0 i = Load pk into quantum register |pi 6 s = measureB|ψi|Bi Qn−1 2 5 |ψk1 i = j=0 C X(pk[j]u2),mj |ψk0 i 7 return |ψi, s Qn−1 6 |ψk2 i = j=0 Xmj CXpk[j],mj |ψk1 i n 7 |ψk3 i = C Xm,u1 |ψk2 i M−k 8 | i | i ψk4 = CSu1,u2 ψk3 The storage algorithm uses three quantum registers. The n 9 |ψk5 i = C Xm,u1 |ψk4 i first register is |pi, with n qubits to which the target pattern Qn−1 10 |ψk6 i = j=0 CXpk[j],mj Xmj |ψk5 i pk is loaded in each iteration of the algorithm. The second is Qn−1 2 11 |ψk7 i = j=0 C X(pk[j]u2),mj |ψk6 i an auxiliary register |ui = |u1u2i with two qubits initialized 12 | i in state |01i. The final register of n qubits holds the memory, Unload pk from quantum register p 13 | i is denoted by |mi, and m[j] denotes jth qubit of |mi. The return ψ initial state of the total system is

|ψ0i = |0 ... 0; 01; 0,... 0i. (21) jth memory qubit state m[j] only if pk[j] and u2 are in |1i. The underlying idea of the algorithm is to split this state In the step 6, the transformation into two parts in each iteration. One corresponds to the subspaces of the total quantum state with patterns stored in n−1 Y the memory register, and another to process a new pattern. |ψk2 i = Xmj CXpk[j],m[j]|ψk1 i, (23) These two parts are distinguished by the second qubit of j=0 the auxiliary register, u2, which is 0 for the subspaces that already store patterns and 1 for the subspace to which a new yields m[j] = 1, if pk[j] = m[j], otherwise m[j] = 0. In the pattern is being loaded (are processing terms). After storing step 7, a pattern, the first qubit of the auxiliary register, |u1i, is used n |ψk3 i = C Xm,u1 |ψk2 i. (24) to apply a controlled operator on |u2i to split the state for storing the next pattern. Here, we have an operation controlled by n bits of the Algorithm 2 presents the PQM storage algorithm named memory, that is, if m[j] = 1 for all values of j, then the load_binary. In the PQM storage algorithm, we use |ψ i ki bit-flip gate X is applied to the bit u . This makes the qubit to denote the quantum state in step i of storing the pattern 1 u1 to assume the value 1 for the term in processing. Step 8, pk. In the step 5, the transformation | i M−k| i ψk4 = CSu1,u2 ψk3 , (25) n−1 Y |ψ i = C2X |ψ i, (22) k1 (pk[j]u2),mj k0 is the central operation of the storing algorithm, which j =0 separates the new pattern to be stored, with the correct copies the binary pattern pk from |pi register to the memory normalization factor. The steps 9 and 10 are the inverse register |mi. Note that these operations are applied to the operators of steps 7 and 6, respectively. These will reset the 5

values of u1 and m to the initial values. This results in the At this point, the quantum state has two terms. The first following state: term has the auxiliary qubit u2 = 0, which indicates that √ the pattern p0 = 00 is stored in memory m. On the other k − 1 X M k hand, in the second term, u2 = 1. This means that the |ψk6 i = √ |pk; 00; psi + √ |pk; 01; pki (26) M s=1 M term is in processing and can receive the next pattern to be stored at the memory. Now, we will do a new iteration in The step 11, the algorithm to store the pattern p1 = 01. n−1 By step 4, as |ψ10 i is equal to |ψ07 i with the pattern p1 Y 2 |ψk7 i = C X(pk[j]u2),mj |ψk6 i, (27) loaded in the register, the quantum state becomes j=0 1 1 |ψ1 i = √ |01; 00; 00i + √ |01; 01; 00i. resets the memory record of the term being processed (u2 = 0 2 2 1) to to |mi = |0i. Then, by steps 5, 6 and 7, we have respectively: At this point, we are ready to store the next pattern pk+1.

To do this, define |ψk+1i from |ψk7 i with the pattern pk+1 1 1 0 √ √ |pi |ψ11 i = |01; 00; 00i + |01; 01; 01i, loaded in the register , and perform a new iteration of 2 2 the algorithm. The process is iterated until |u2i = |0i in all terms of the quantum state, indicating that all patterns 1 1 |ψ12 i = √ |01; 00; 10i + √ |01; 01; 11i, pk are stored in the memory. Note that although the loading 2 2 procedure is deterministic, memory read-out procedures are and probabilistic due to the quantum measurement postulates. 1 1 |ψ1 i = √ |01; 00; 10i + √ |01; 11; 11i. Thus this is the initialization algorithm of a probabilistic 3 2 2 quantum memory. Given that the patterns to be stored are of n bits, steps 4 Now, for k = 1, r = 1. Hence in step 8, and 12 require the same number of steps, O(n). Then for M  0 1 S1 = . patterns to be stored, the entire algorithm requires O(nM) −1 0 steps to store all patterns. The circuit corresponding to one iteration of the PQM algorithm is shown in Figure 3. Following step 8, which results in CS1|00i = |00i and In what follows, we demonstrate how to use the algo- CS1|11i = |10i, the state becomes rithm above to store an example set of patterns 1 1 |ψ14 i = √ |01; 00; 10i + √ |01; 10; 11i. data = {p0 = 00, p1 = 01}. 2 2 Applying steps 9 and 10 resets u and the memory register, First iteration stores the pattern p0 = 00. Loading the 1 pattern in the initial state by step 4 results in respectively: 1 1 |ψ00 i = |00; 01; 00i. |ψ1 i = √ |01; 00; 10i + √ |01; 00; 11i, 5 2 2 The step 5 gives |ψ0 i = |ψ0 i, and by step 6, 0 1 and | i | i 1 1 ψ02 = 00; 01; 11 . |ψ1 i = √ |01; 00; 00i + √ |01; 00; 01i. 6 2 2 By step 7, Finally, as |ψ16 i = |ψ17 i and u2 = 0 in all terms of |ψ17 i, |ψ03 i = |00; 11; 11i. there are no more processing terms and we conclude that Now, for k = 0, r = 2. Hence in step 8, the binary patterns are stored in the memory m, producing

" √1 √1 # the state S2 = 2 2 . √−1 √1 1 1 2 2 |Mi = √ |01; 00; 00i + √ |01; 00; 01i. (31) 2 2 Following step 8, which calculates CS2|11i, the state be- comes This is the quantum state desired in Eq. (20) for the example 1 1 data set. |ψ0 i = √ |00; 10; 11i + √ |00; 11; 11i. (28) 4 2 2 4 LIMITATION IN THE FF-QRAM ALGORITHM Applying steps 9 and 10 resets u1 and the memory register, obtaining, respectively: In this section, we show that the FF-QRAM algorithm 1 1 becomes inefficient if the initial state in Eq. (11) is used |ψ05 i = √ |00; 00; 11i + √ |00; 01; 11i, (29) to load v  M patterns as in the original design. More 2 2 specifically, the post-selection can make the algorithm a and non-viable choice for efficiently storing real amplitudes in 1 1 |ψ06 i = √ |00; 00; 00i + √ |00; 01; 00i. (30) a quantum state. For this, consider the following list of 2 2 continuous data: | i | i By step 11, we have ψ06 = ψ07 . n√  √ o 0.3, |000i , 0.7, |001i , 6

Fig. 3: One iteration of the PQM data storage algorithm.

√ √ √ meaning that x0 = 0.3, x1 = 0.7, n = 3, and M = 2. To load the amplitude x1 = 0.7, the controlled rotation is ⊗3 The initial state is simply |+iB |0iR. used to produce After step 3 of the first iteration in Algorithm 1, 1 √ √  |ψ5i = √ |110i 0.7|0i + 0.3|1i 1  x0,x1 2 2 |ψ i = √ |111i + |110i + |101i + |100i 1 0 1 h θ  θ  i 2 2 + √ |111i cos 1 |0i + sin 1 |1i  2 2 +|011i + |010i + |001i + |000i |0i . (32) 2 2 R 1 X + √ |ti|0iR (37) 3 In the next step, a controlled-rotation, C Ry(θ0), is applied 2 2 |ti6=|111i,|110i to rotate the register qubit that is entangled with |111iB: √ With θ1 = 2 arcsin 0.7 = 1.1982, Eq. (37) becomes 1 h θ0  θ0  i √ √ |ψ2ix = √ |111i cos |0i + sin |1i 1   0 2 2 2 2 |ψ5i = √ |110i 0.7|0i + 0.3|1i x0,x1 2 2 1 X + √ |ti|0i (33) 1 √ √  2 2 R + √ |111i 0.3|0i + 0.7|1i |ti6=|111i 2 2 √ 1  With θ = 2 arcsin 0.3 = 1.159, Eq. (33) becomes + √ |100i + |101i + |010i 0 2 2 √ √  1   + |011i + |000i + |001i |0i . |ψ2i = √ |111i 0.7|0i + 0.3|1i R (38) x0 2 2 1  The second iteration is completed with step 5 of Algorithm + √ |110i + |101i + |100i + |011i 2 2 1, yielding a quantum state  √ √ + |010i + |001i + |000i |0i . (34) 1   R |ψ6i = √ |000i 0.7|0i + 0.3|1i x0,x1 2 2 Step 5 in Algorithm 1 completes the first iteration to produce 1 √ √  + √ |001i 0.3|0i + 0.7|1i 1 √ √  2 2 |ψ3i = √ |000i 0.7|0i + 0.3|1i 1  x0 2 2 + √ |010i + |011i + |100i 1  2 2 + √ |001i + |010i + |011i + |100i  2 2 + |101i + |110i + |111i |0iR. (39)  + |101i + |110i + |111i |0iR. (35) The efficiency of our storage will be given by the probability P (|1i). We obtain that P (|1i) = 0.125, while √  Similar procedure is followed to load 0.7, |001i . Af- P (|0i) = 0.875. This implies that after the measurement of ter repeating up to step 3 in Algorithm 1, the state becomes the state in Eq. (39), the chance of loading x0 and x1 in a quantum format as desired is 12.5% until this step of the √ √  1 algorithm. |ψ4ix ,x = √ |110i 0.7|0i + 0.3|1i 0 1 2 2 Due to the probabilistic nature of the FF-QRAM, the 1  + √ |111i + |100i + |101i + |010i post-selection procedure is necessary, which repeats the 2 2 same algorithm until the register qubit is measured onto  |1i. Theorem 1 shows that the FF-QRAM can have an + |011i + |000i + |001i |0i . (36) R exponential computational cost in the worst case. 7

⊗n M−1 Theorem 1. If |ψ0i = |+i |0i, data = {xk, pk}k=0 , then 5.1 FFP-QRAM - Combining PQM and FF-QRAM PM−1 to create a quantum state k=0 xk|pki, the FF-QRAM post- The PQM algorithm has computational cost O(Mn) for 1 selection success probability is P (|1i) = 2n . loading M n-bit binary patterns in superposition with the same amplitude. This is the same computational cost of the Proof. According to the FF-QRAM algorithm, the initial state FF-QRAM if there is no need to carry out a post-selection. can be written as If we have a quantity M of binary patterns to store in a n X 1 1 X state with n qubits and M  2 , the PQM algorithm keeps |ψ0i = √ |pki|0i + √ |ti|0i , 2n R 2n R efficient with costs associated with the number of patterns. pk∈P t/∈P On the other hand, as shown in the previous section, when trying to store M  2n patterns, the post-selection process where P = {p0, ··· , pM−1}. In each iteration of the algo- ⊗n of the FF-QRAM algorithm initialized with |+i will have rithm, the controlled rotation gate takes θk = 2 arcsin xk to satisfy Eq. (19). Thus after performing M iterations to load exponential computational cost. the desired amplitudes, we have the following state. From these two observations, we propose to combine PQM and FF-QRAM algorithms, to store the desired quan- M−1 tity of patterns as a quantum state in superposition. X 1 1 X |ψf i = √ |pki[yk|0i + xk|1i] + √ |ti|0iR. Consider an input database given by Eq. (1). Suppose we 2n 2n n k=0 t/∈P want to obtain a quantum state Eq. (2), with M  2 terms. We use Algorithm 2 to store the binary patterns p . After M PM−1 k Since we want to obtain QRAM(|ψ0i) = k=0 xk|pki, iterations of the PQM algorithm, we will have the following we need to study the probability of obtaining |1i when final state measuring the register qubit. The success probability is M−1 calculated as 1 X |ψf i = √ |pki. (40) M−1 M−1 PQM M X 1 2 1 X 2 1 k=0 P (|1i) = |xk| = |xk| = , 2n 2n 2n k=0 k=0 This final state Eq. (40) in PQM will be the initial state of the FF-QRAM that will have an increased probability of PM−1 2 since k=0 |xk| = 1 due to the normalization condition. post-selection P (|1i). However, as described in Corollary 2, P (|1i) approaches 0 when we increase the number of pat- terns M. To obtain a higher post-selection probability we The previous theorem leads to following corollaries. define a preprocessing procedure in the next section. Corollary 1. If n, the number of bits, in the quantum state 1 increases, the probability P (|1i) = 2n → 0, that is, the chance of 5.2 Improvement via Data Preprocessing success in the process decreases. The post-selection probability can also be improved with Corollary 2. If our initial state has exactly the superposition of a preprocessing strategy. The preprocessing consists of di- M computational basis of n qubits, which corresponds to P, that viding every entry in the input state by is, c = max (|xk|). M−1 X 1 0≤k

FF-QRAM 0.35 Preprocessed FF-QRAM 0.70 0.30

0.25 0.65

0.20 FFP-QRAM 0.60 Preprocessed FFP-QRAM 0.15

Estimated probabilities 0.10 Estimated probabilities 0.55

0.05 0.50

0.00

2 3 4 5 6 7 8 2 3 4 5 6 7 8 Number of qubits n Number of qubits n

Fig. 4: Comparison between the original FF-QRAM with a Fig. 5: Comparison between the original FFP-QRAM with FF-QRAM using the preprocessing strategy. The number of a FFP-QRAM using the preprocessing strategy. The number zero-valued data entries is 2n − 2, where n is the number of of zero-valued data entries is 2n − 2, where n is the number qubits represented on the x axis. of qubits. strategy. There is an improvement in the post-selection prob- ability, but in the worst case the post-selection probability amount of complex data, such as amplitudes of a state in approaches zero and the FF-QRAM will have an exponential superposition, with computational cost O(Mn) and without computational cost. a post-selection procedure. We refer to this algorithm as adapted PQM (A-PQM). In the second set of experiments,√ the input√ consists of two n-bit patterns with amplitudes 0.3 and 0.7 and we Consider the input database given by Eq. (1). We will used the FFP-QRAM. Figure 5 shows the estimated post- use Algorithm 3 to obtain the desired state in Eq. (2), whose selection probability P (|1i) in FFP-QRAM for this example initial state, according to our change, will only have n + with n = 1,..., 8, and with and without the preprocessing 2 qubits, as a consequence of the elimination of the first strategy. The FFP-QRAM has an improved post-selection register |pi of the Algorithm 2 . Thus, the A-PQM storage probability when used to prepare certain sparse vectors and algorithm has quantum states with structure has the same success probability as FF-QRAM when used to prepare a dense state. Given the improvement in the post- selection success probability, in the next sections, we only |u1u2; mi, use the FF-QRAM and FFP-QRAM with the preprocessing strategy. All quantum circuits were implemented using python where the initial state has u1 = 0, u2 = 1 and the memory programming language, with the quantum computing register |mi = |m[0]m[1]...m[n − 1]i initialized in |0i. framework Qiskit [19]. To perform the numerical simula- Under these conditions, using the PQM storage algo- tions, we used QASM simulator within Qiskit. The QASM rithm [14] and the controlled rotations adopted in [13] simulator is a backend that emulates the implemented quan- as bases, our main proposal is a deterministic algorithm, tum circuit as if it was being executed in a real quantum capable of loading complex data without the cost of post- device. To obtain answers in this kind of simulator, it is selection. The A-PQM algorithm is described in Algo- necessary to perform measurements on the qubits. Since rithm 3, and |ψki i denotes the quantum state in step i of a quantum circuit’s output is probabilistic, the simulation storing the pattern pk with the amplitude xk. must be executed several times. The number of repetitions The quantum circuit for loading xk as a complex ampli- in all simulations was 1024. tude of |pki, is depicted in Figure 6. Next, we will present a new algorithm for loading com- plex data without post-selection. Algorithm 3 works in a similar way to the Algorithm 2. That is, steps 4-8 correspond to the loading steps, and steps 12-16 correspond to the unloading steps in Algorithm 5.3 A-PQM - Adapted PQM loading procedure for stor- 2. And given that there are M complex data, each associated ing continuous data with a binary pattern of length n, O(Mn) steps are required Based on [13], [14], [20], we propose a modified ver- to store complex data in Algorithm 3. Thus, we are able to sion of the PQM storage algorithm to load patterns with encode complex data in a quantum state in a deterministic continuous amplitudes. We modify the Sr operator and way, thereby eliminating the post-selection cost of Algo- adopt the flip flop operators of the FF-QRAM algorithm. rithm 1. In the next subsection, we will make an example of The proposed algorithm is capable of storing the desired the quantum data encoding procedure using Algorithm 3. 9

Fig. 6: One iteration of the A-PQM data storage algorithm

√ √ Algorithm 3: A-PQM - Complex Data Storage Al- For input ( 0, 1 − i 0, 2, 00), as p0[0]p1[0] = 00, by step 4 gorithm we have

M−1 |ψ01 i = |01; 11i. (42) input : data = {xk, pk}k=0 M−1 P In step 9, the operator will adjust the auxiliary qubit u1 to output: |ψi = k=0 xk|pki 1, if each qubits in memory |m[0]m[1]i has a value of 1, to 1 load | i (data, ψ ): produce 2 The initial state |ψk0 i = |01; 0, ··· , 0i |ψ02 i = |11; 11i. (43) 3 foreach (xk, pk) ∈ data do 4 for j = 0 → n − 1 do Now, in step 10, we have reached the moment where our 5 if p [j] =6 0 then k algorithm differs√ from the√ one proposed by [14]. Applying 6 |ψk1 i = CXu2,mj |ψk0 i γ0 = 1 and x0 = 0, 1 − i 0, 2 in Eq. (10), we get 7 else  √ √ √  8 0, 7 0, 1 − i 0, 2 |ψk1 i = Xmj |ψk0 i (x ,γ ) n U 0 0 =   . 9 |ψk2 i = C Xm,u1 |ψk1 i 3 √ √ √ (xk,γk) − 0, 1 − i 0, 2 0, 7 10 |ψ i = CU |ψ i k3 3 u1,u2 k2 n 11 | i | i (x0,γ0) ψk4 = C Xm,u1 ψk3 |ψ i = CU |ψ i 03 3 u1,u2 02 results in 12 for j = 0 → n − 1 do 13 if pk[j] =6 0 then p p p 14 |ψk5 i = CXu2,mj |ψk4 i |ψ03 i = ( 0, 1 − i 0, 2)|10; 11i + 0, 7|11; 11i. (44) 15 else Step 11 resets the qubit u to the initial state 0, if each qubit 16 |ψk i = Xm |ψk i 1 5 j 4 | i 17 return |ψi in memory m[0]m[1] has a value of 1. Then p p p |ψ04 i = ( 0, 1 − i 0, 2)|00; 11i + 0, 7|01; 11i. (45) By step 12, we have |ψ i = X |ψ i. Then 5.3.1 Example 04 j 04

Let p p p |ψ05 i = ( 0, 1 − i 0, 2)|00; 00i + 0, 7|01; 00i. (46) p p p p data = {( 0, 1 − i 0, 2, 00); ( 0, 1 − i 0, 1, 01); In Algorithm 3, the qubit u2 works in the same way as in Al- p p } ( 0, 1, 10); ( 0, 4, 11) , gorithm 2. In |ψ05 i, u2 = 0 indicates that the corresponding term stores the input (x0, p0) in the memory, while u2 = 1 be an input database, determined by a list of four complex indicates that the term is being processed to store a new numbers that we want to store. The Algorithm 3 will create input. After running all iterations of the algorithm, all terms a state |ψi, as described below. must have u2 = 0 indicating that all patterns are stored, thus ending the algorithm. 3 X Now, for the second input pattern, we have |ψi = x |p i (41) k k p p p k=0 |ψ10 i = ( 0, 1 − i 0, 2)|00; 00i + 0, 7|01; 00i. (47) √ √ The initial state is given by For input ( 0, 1 − i 0, 1, 01), as p1[0] = 0 the memories m[0] will be changed by the operator X in both terms. As

|ψ00 i = |01; 00i. p1[1] = 1, only the memory m[1] of the second term will be 10

changed by the operator CXu2m[1], since only in the second term u2 = 1. Then, by proceeding from step 4, 1.0 p p p |ψ i = ( 0, 1 − i 0, 2)|00; 10i + 0, 7|01; 11i. 11 (48) 0.8

Following the subsequent steps of the algorithm, we obtain 0.6 the following state: FF-QRAM FFP-QRAM A-PQM 0.4 p p p |ψ12 i = ( 0, 1 − i 0, 2)|00; 10i + 0, 7|11; 11i. Estimated probabilities

0.2 In this iteration, we have γ1 = 01 − 0.3 = 0.7. Applying x1 and γ1 in Eq. (10), we get: 0.0 √ √ √  √0,5 0,1√−i 0,1  2 3 4 5 6 7 8 9 10 11 0,7 0,7 log2(M) (x1,γ1)   U3 =  √ √ √  , − 0√,1−i 0,1 √0,5 Fig. 7: Success probability to load M patterns into a FF- 0,7 0,7 QRAM, FFP-QRAM or A-PQM with 11 qubits, where the and amplitudes are initialized with a random uniform distribu- tion. p p p p |ψ13 i =( 0, 1 − i 0, 2)|00; 10i + ( 0, 1 − i 0, 1)|10; 11i p + 0, 5|11; 11i, 6 EXPERIMENTS

We performed experiments with the FF-QRAM, FFP- p p p p QRAM using the preprocessing strategy presented in Sec- |ψ14 i =( 0, 1 − i 0, 2)|00; 10i + ( 0, 1 − i 0, 1)|00; 11i p tion 5.2, and the adapted version of PQM (A-PQM) for + 0, 5|01; 11i, continuous amplitudes. FF-QRAM and FFP-QRAM have the computational cost of O(CMn), and A-PQM has the and computational cost of O(Mn). Through experimentation from the initialization of sparse to dense quantum states, | i p − p | i p − p | i ψ15 =( 0, 1 i 0, 2) 00; 00 + ( 0, 1 i 0, 1) 00; 01 we investigate the impact of sparsity in the computational p + 0, 5|01; 00i. cost of FF-QRAM and FFP-QRAM. In Figure 7, we verify the probability of post-selection

At this moment, in the first two terms of the state |ψ15 i, we of FF-QRAM, FFP-QRAM, and A-PQM using M 11-bit 11 have u2 = 0, indicating that the amplitudes x0 and x1 are patterns, with M = 4, 8,..., 2 , and amplitudes initialized loaded with the states p0 and p1, respectively, and the third randomly following a uniform distribution. In this case, the term with u2 = 1 will be used to load the next input pattern. FFP-QRAM has an improved post-selection probability, re- Therefore, we are ready to proceed to the next entry√ pattern. quiring only a constant number of repetitions to achieve the Following√ the same procedure for the inputs ( 0, 1, 10) desired state with high probability, and has computational and ( 0, 4, 11) in the Algorithm 3, we obtain the final states: cost O(Mn). The post-selection probability of FFP-QRAM depends on the data distribution. In Figure 8, we verify the probability p p p p |ψ25 i =( 0, 1 − i 0, 2)|00; 00i + ( 0, 1 − i 0, 1)|00; 01i of post-selection of FF-QRAM, FFP-QRAM, and A-PQM p p 11 + 0, 1|00; 10i + 0, 4|01; 00i using M 11-bit patterns, with M = 2, 4, 8,..., 2 , and with an artificial data set in which the largest amplitude and is approximately 0.99 and the rest of the data initialized randomly. In this case, the preprocessing will not improve p p p p the post-selection probability of FF-QRAM and FFP-QRAM, |ψ35 i =( 0, 1 − i 0, 2)|00; 00i + ( 0, 1 − i 0, 1)|00; 01i and they will require an exponential number of repetitions p | i p | i + 0, 1 00; 10 + 0, 4 00; 11 . to generate the desired state. In the worst case, the post-selection success probability Note that in |ψ i, u = 0 in all terms, meaning that there 35 2 of FF-QRAM and FFP-QRAM approaches 0, and it is nec- is no more term in the process. Therefore, we successfully essary to perform an exponential number of FF-QRAM or prepared the desired state shown in Eq. (41) as FFP-QRAM calls to prepare a quantum state. The A-PQM requires a polynomial number of operations to initialize a quantum state with M patterns. In the worst case, the A- | i p − p | i p − p | i ψ =( 0, 1 i 0, 2) 00 + ( 0, 1 i 0, 1) 01 PQM state preparation is exponentially faster than the FF- p p + 0, 1|10i + 0, 4|11i. (49) QRAM and FFP-QRAM. 11

[4] Lov K Grover. Quantum mechanics helps in searching for a needle in a haystack. Physical review letters, 79(2):325, 1997. [5] Peter W Shor. Polynomial-time algorithms for prime factorization 1.0 and discrete logarithms on a quantum computer. SIAM review, 41(2):303–332, 1999. [6] Patrick Rebentrost, Masoud Mohseni, and Seth Lloyd. Quantum 0.8 support vector machine for big data classification. Physical review letters, 113(13):130503, 2014. [7] Jacob Biamonte, Peter Wittek, Nicola Pancotti, Patrick Rebentrost, 0.6 FF-QRAM Nathan Wiebe, and Seth Lloyd. Quantum machine learning. FFP-QRAM Nature, 549(7671):195, 2017. A-PQM [8] Gui-Lu Long and Yang Sun. Efficient scheme for initializing a 0.4 quantum register with an arbitrary superposed state. Physical

Estimated probabilities Review A, 64(1):014303, 2001. [9] Vittorio Giovannetti, Seth Lloyd, and Lorenzo Maccone. Quantum 0.2 random access memory. Physical Review Letters, 100(16), Apr 2008. [10] Srinivasan Arunachalam, Vlad Gheorghiu, Tomas Jochym- 0.0 O’Connor, Michele Mosca, and Priyaa Varshinee Srinivasan. On 2 3 4 5 6 7 8 9 10 11 the robustness of bucket brigade quantum RAM. New Journal of log2(M) Physics, 17(12):123010, dec 2015. [11] O. D. Matteo, V. Gheorghiu, and M. Mosca. Fault-tolerant re- Fig. 8: Success probability to load M patterns into a FF- source estimation of quantum random-access memories. IEEE Transactions on Quantum Engineering, 1:1–13, 2020. QRAM, FFP-QRAM or A-PQM with 11 qubits, where the [12] Zhikuan Zhao, Jack K. Fitzsimons, Patrick Rebentrost, Vedran maximum amplitude of the data is about 0.99 and the rest Dunjko, and Joseph F. Fitzsimons. Smooth input preparation for are chosen randomly. quantum and quantum-inspired machine learning, 2018. [13] Daniel K Park, Francesco Petruccione, and June-Koo Kevin Rhee. Circuit-based quantum random access memory for classical data. Scientific reports, 9(1):1–8, 2019. 7 CONCLUSION [14] Carlo A Trugenberger. Probabilistic quantum memories. Physical Review Letters, 87(6):067901, 2001. The ability to load data in a quantum state efficiently [15] Michael A Nielsen and Isaac Chuang. Quantum computation and is of critical importance in quantum computing. Ref. [13] quantum information. AAPT, 2002. proposed a method to load a database structured as M pairs [16] Carlo A Trugenberger. Quantum pattern recognition. Quantum n Information Processing, 1(6):471–493, 2002. of a complex number and an -bit pattern in a quantum [17] Dan Ventura and Tony Martinez. Initializing the amplitude computer with a computational cost of O(CMn), where C distribution of a quantum state. Foundations of Physics Letters, is the number of repetitions for post-selection that depends 12(6):547–559, 1999. on the distribution of the data. In this work we showed [18] Dan Ventura and Tony Martinez. Quantum associative memory. Information Sciences, 124(1-4):273–296, 2000. that C can dominate the computational cost and nullify the [19] Gadi Aleksandrowicz and et al. Qiskit: An open-source frame- efficiency of the algorithm proposed in Ref. [13]. Then we work for quantum computing, 2019. presented several strategies to circumvent this critical issue. [20] Mikko Mott¨ onen,¨ Juha J Vartiainen, Ville Bergholm, and Martti M We showed that the success probability for post-selection Salomaa. Transformation of quantum states using uniformly con- trolled rotations. Quantum Information & Computation, 5(6):467– can be improved by combining two known algorithms 473, 2005. and preprocessing the data. Then we presented a new algorithm for loading the quantum database without post-selection, thereby reducing the computational cost to O(Mn). The proposed method is based on the algorithms proposed in Refs. [13] and [14]. We also reduced the number of qubits used in the PQM algorithm from 2n + 2 to n + 2, which is favorable for using the proposed algorithm in noisy intermediate-scale quantum devices.

ACKNOWLEDGMENT This work was supported by CNPq (Grant No. 308730/ 2018-6), CAPES (Finance code 001), FACEPE (Grant No. BIC-1528-1.03/18), and the National Research Foundation of Korea (Grant No. 2019R1I1A1A01050161).

REFERENCES [1] Paul Benioff. The computer as a physical system: A microscopic quantum mechanical hamiltonian model of computers as repre- sented by turing machines. Journal of statistical physics, 22(5):563– 591, 1980. [2] Richard P Feynman. Simulating physics with computers. International journal of theoretical physics, 21(6):467–488, 1982. [3] Seth Lloyd. Universal quantum simulators. Science, 273(5278):1073–1078, 1996.