A divide-and-conquer algorithm for quantum state preparation

Advantages in several fields of research and industry are expected with the rise of quantum computers. However, the computational cost to load classical data in quantum computers can impose restrictions on possible quantum speedups. Known algorithms to create arbitrary quantum states require quantum circuits with depth O(N) to load an N-dimensional vector. Here, we show that it is possible to load an N-dimensional vector with a quantum circuit with polylogarithmic depth and entangled information in ancillary qubits. Results show that we can efficiently load data in quantum devices using a divide-and-conquer strategy to exchange computational time for space. We demonstrate a proof of concept on a real quantum device and present two applications for quantum machine learning. We expect that this new loading strategy allows the quantum speedup of tasks that require to load a significant volume of information to quantum devices.


Introduction
The development of quantum computers can dramatically reduce the time to solve certain computational tasks 1 . However, in practical applications, the cost to load the classical information in a quantum device can dominate the asymptotic computational cost of the quantum algorithm 2, 3 . Loading information into a device is a common task in computer science applications. For instance, deep neural networks 4 learning algorithms run in specialized hardware 5 , and the computational cost to transfer the information needs to be considered in the total computational cost as data loading can dominate the training time on large-scale systems 6 . In classical devices, we can use the loaded information several times while we do not erase it. The situation is not the same in quantum devices because of the no-cloning theorem 7 , noisy quantum operations 8 , and the decoherence of quantum information 9 . The no-cloning theorem shows that it is not possible to perform a copy of an arbitrary quantum state. When a quantum operation is applied, its input is transformed or is destroyed (collapsed). Even if we represent the information in a basis state that we can copy, the noisy operations and decoherence will corrupt the stored state, and it will be necessary to reload the information from the classical to the quantum device.
Loading an input vector x = (x 0 , · · · , x N−1 ) to the amplitudes of a quantum system corresponds to create the state with log 2 (N) quantum bits described in Eq. (1).
Here we propose a new format of data encoding. Namely, we load an N-dimensional vector in probability amplitudes of computational basis state with entangled information in ancillary qubits as where ψ j are unit vectors. We propose an algorithm to load an N-dimensional vector in a quantum state as shown in Eq.
(2) using a circuit with O(log 2 2 (N)) depth and O(N) qubits. The devised method is based on quantum forking 13,14 and (a) Binary tree angles vector generated by function gen angles with an 8-dimensional input vector.  uses a divide-and-conquer strategy 15 . The circuit depth is decreased at the cost of increasing the circuit width and creating entanglement between data register qubits and an ancillary system. Thus when the data register is considered alone (i.e. by tracing out the ancilla qubits), the resulting state is mixed and not equal to the pure state shown in Eq. (1). However, it is important to note that in Eq. (2) the classical data is still encoded as probability amplitudes of an orthonormal basis set. Useful applications can be constructed based on this, and we provide two example applications in machine learning and statistical analysis.
The divide-and-conquer paradigm is used in efficient algorithms for sorting 16 , computing the discrete Fourier transform 17 , and others 15 . The main idea is to divide a problem into subproblems of the same class and combine the solutions of the subproblems to obtain the solution of the original problem. The circuit based divide-and-conquer state preparation algorithm has computational cost O(N) and the total complexity time is is classical pre-computation time to create the quantum circuit that will load the information in the quantum device and O q (log 2 2 (N)) is the depth of the quantum circuit. With the supposition that we will load the input vector m N times, the amortized computational time to load the real vector is O q (log 2 2 (N)). The modified version of the loading problem allows an exponential advantage in the depth of the quantum circuit using O(N) qubits.
The remainder of this paper is organized into 3 sections. Section 2 reviews one of the standard methods for loading information in a quantum device using controlled rotations 10 , which we set out to modify to reduce its quantum circuit depth exponentially. Section 3 shows the main result, a quantum circuit with depth O(log 2 2 (N)), and O(N) qubits to load an N-dimensional vector in a quantum state with entangled information in the ancillary qubits. Section 4 presents the conclusion and possible future works.

Transformation of quantum states
In this section, we review a strategy for loading a real vector into the amplitudes of a quantum state using a sequence of controlled one-qubit rotations 10 . Given an N-dimensional vector x, where n = log 2 (N) is an integer, we can create a circuit to load this vector in a quantum computer using Algorithm 1. The task of amplitude encoding (Algorithm 1) has two parts: i) Function gen angles (Line 1) finds angles to perform rotations that lead |0 n ≡ |0 ⊗n to the state in Eq. (1), and ii) Function gen circuit (Line 18) generates a quantum circuit from these rotations.
Function gen angles (Algorithm 1, Line 1) divides the 2 n -dimensional input vector into 2 n−1 2-dimensional subvectors and creates a 2 n−1 -dimensional vector new x with the norms of the subvectors. While the size of new x is greater than 1, the new x vector is recursively passed as the input of function gen angles. This procedure is described in lines 3 to 6 of Algorithm 1. An example of the inputs in the recursive calls with the initial input is presented in the binary tree named state-tree in Fig. 1b. After the last recursive call of the function gen angles, the algorithm starts to compute the vector angles. For each k between 0 and the size of vector new x, we append an angle θ such that sin(θ /2) =  1.23). The angles vector is used as a complete binary tree named angles-tree. For instance, with α k = angles[k], the angles-tree created by gen angles with an eight-dimensional input vector is described in Fig. 1a. Each call of gen angles will perform log 2 (N) recursive calls and the cost of each call for k = 1, · · · , log 2 (N) is N/2 k−1 . The costs of the recursive calls to generate the angles-vector is 1 + 2 + 2 2 + · · · + 2 log 2 N = O(N).

3/13
Function gen circuit (Algorithm 1, Line 18) receives the N − 1 dimensional vector angles, generated by the function gen angles with input x, and outputs a quantum circuit to load the vector x in the amplitudes of a quantum state. The state in level j of the tree-state in Fig. 1b can be constructed from the state in the level j − 1 of the states-tree and controlled rotations from the level j − 1 in angles-tree. The root of the angles-tree defines the first rotation and the algorithm follows a top-down approach where the rotation of angle angle[k] is controlled by the qubits in range [0, level(k)) and is applied if the qubits q[0], · · · , q[level(k) − 1] are in the state k − (2 level(k) − 1) . With α k = angle[k], the circuit to load an eight-dimensional input vector is described in Fig. 2. The computational cost to compute the angles and to generate the circuit is O(N). The quantum circuit uses O(N) multi-controlled gates that are applied sequentially and the circuit depth is O(N). We have a O(N) cost in the classical host machine and a O(N) cost in the quantum device and spatial cost O(log 2 (N)). An amortized computational cost is O(N) if we need to load the vector several times.

Divide-and-conquer loading data
The construction of the quantum state in the previous section starts in the root of state-tree |0 n and build the states in each level of the state-tree in a top-down strategy until to build the state described by the last level of the state-tree. In this Section, we propose a divide-and-conquer load strategy, and the desired quantum state is built following a bottom-up strategy. First, we divide the input into bidimensional subvectors and load qubits corresponding to the normalized bidimensional subvectors. In the next steps, we generate the subvectors of the previous levels.
For instance, to load the state in the leafs of the state-tree in Fig. 1b, we load four one-qubit states representing the leafs of the state-tree. To load the two two-qubit states in the previous level, the single-qubit states are weighted with the value of their fathers, obtaining the state |ψ l representing the state in the half left part of the state-tree in Eq. (3) and the state |ψ r representing the state in the right part of the state-tree in Eq. (4).
Combining states |ψ l and |ψ r weighted with the values of the state in the previous layer generates the desired quantum state described in Eq. (5).
To load the classical data using this bottom-up approach we need to combine two (m − 1)-qubits states |ψ , |φ and one onequbit state a |0 + b |1 as a |0 |ψ + b |1 |φ with a circuit that does not depend on the input states. Using the circuit in Fig. 3 with m − 1 controlled-swap (CSWAP) operations, we generate the desired output in the first m qubits, but with unit entangled information in the m − 1 ancillary qubits. Namely, for the example with Fig. 3, the conventional amplitude encoding in the form of Eq. (1) would aim to prepare an m-qubit state a|0 |ψ + b|1 |φ while our method prepares a|0 |ψ |φ + b|1 |φ |ψ .

Loading Complex data
The divide-and-conquer strategy can be generalized to load a complex vector (|x 0 |e iω 0 , |x 1 |e iω 1 , . . . , |x N−1 |e iω N−1 ) into the probability amplitudes of a quantum state as where v = 1, 2, . . . , n is the level of the tree in reverse order (i.e. 1 for the leaf nodes and n for the root node) and j = 1, 2, . . . , 2 n−v is the qubit index in the layer v. Next, one needs N/2 one-qubit states corresponding to the leaf nodes of the state-tree (see Fig.  1b for example) to be prepared as To load the states in the previous levels (represented by v on the expression below), the states of the current level (v − 1, since v is in reverse order) are weighted with the values of their parents, obtaining the state After recursively updating the state ψ j,v for v = 2, . . . , n and j = 1, 2, . . . .2 n−v , the desired quantum state is generated as Combining two states at children nodes in the state-tree as shown in Eq. (8) is done with controlled-swap operations as explained in the previous section, and we will need N qubits with entangled auxiliary qubits to generate the state in Eq. (6). Thus the only modification in the quantum circuit is the introduction of the R z (λ j,v ) rotations to set the phases, following the R y rotations. The pseudocode for generating the angles for the R z rotations is given in Algorithm 2. Algorithm 3 presents the complete pseudocode for the divide-and-conquer state preparation algorithm. The for loop in line 2 initializes the qubit q[k] with the value R y (α k ). After this step, the qubits with index k > (N − 1)/2 (in the leaf of the angle tree) are normalized versions of the states in the leafs of the state-tree. The next subroutine with R z rotations (Line 4 to Line 5) is used to encode phase information. Line 6 calculates the index of the first angle that has a right children in the angle-tree data structure. The while loop starting at line 7 combines the states generated in the subtree rooted in the angle α actual . To combine the states, we first apply a cswap(q[actual], q[left child], q[right child]), and then we update the values of left and right child with the value of their left child and apply another cswap(q[actual], q[left child], q[right child]) while the left child and right child have valid values. With the input described by the angle-tree in Fig. 1a, Algorithm 3 generates the circuit described in Fig. 4. The process to load each state in the same layer of the state tree can be performed in parallel, because the control swap gates use different qubits. The controls are qubits in one layer of the angle-tree and targets are qubits in their subtrees. Layer with height k contributes to the depth of the circuit with the tree height minus height of the layer. The circuit will have a depth of O(1 + 2 + · · · + log 2 (N) − 1) with an overall depth in order O(log 2 2 (N)). This result is stated in Theorem 1.

Orthonormal ancillary
The ancillary states |ψ 0 , . . . , |ψ N−1 in Eq. (2) are not necessarily orthogonal to each other, but we can modify the divideand-conquer state preparation adding label qubits to ensure orthonormality of the ancillary states with the addition of label quantum register with log 2 (N) qubits. The label register is prepared in |0 ⊗ log 2 (N) , and log 2 (N) controlled-NOT (CNOT) gates are applied to the label qubits, each controlled by a data qubit. With this modification, the final state becomes where {|ψ k } N−1 k=0 = {|ψ k |k } N−1 k=0 is a set of orthonormal states.

Experiments
To evaluate the proposed method we perform two sets of experiments. In the first set of experiments, we use a quantum computing simulator and a NISQ computer to show as a proof of concept that the proposed method can be applied in near future. In the second set of experiments, we compare the depth of the circuits generated by the proposed method and other state preparation algorithms 10, 11 with a random input.

6/13
Level 2 Level 1 Level 0 Figure 4. Rotated angle-tree and a circuit generated by the divide-and-conquer strategy described in Algorithm 3. The quantum bit q[k] in the circuit is aligned with the angle α[k] in the angle-tree, this organization allows to draw the quantum gates in each layer in parallel. In this example, the desired state is stored in qubits q[0], q [1] and q [3] to generate the quantum state with entangles ancilla as in Eq. (2).
(a) Output of the circuit in Fig. 5b with 1024 runs in a simulator (blue) and ibmq rome (red).

Proof of concept with a NISQ device
In this experiment we load a four-dimensional data into a two qubit state |ψ = √ 0.6 |00 + √ 0.2 |01 + √ 0.1 |10 + √ 0.1 |11 in a NISQ device as a proof of concept. For this experimental validation, we chose dimension of data to be small to be compatible with currently available quantum devices, although the time advantage of the proposed method will manifest when a large number of qubits are required for loading high-dimensional data. We use qubits 1, 2 and 3 of the ibmq rome device. The CNOT error rates were 8.832e-3 (qubits 1 and 2) and 8.911e-3 (qubits 2 and 3). The single-qubit error was in the order of 1e-4. Figure 5a presents the output of the experiment with 1024 executions using a quantum device simulator and the Rome quantum device. The Rome NISQ device has an output very close to the expected result. The circuit used to obtain this result is described in Fig. 5b, where c is a classical register. We remove the last CNOT of the controlled operation because the qubit 2 will be discarded. The resulting circuit has 10 CNOT operators because a quantum swap was necessary to run this circuit in the real quantum device with a limited qubit connectivity. The circuit used in the quantum device is described in Fig. 7.

Circuit depth
The main difference between the divide-and-conquer state preparation and previous approaches is an exchange between circuit depth by circuit width. Table 1 presents the depth of the circuits generated using the proposed strategy, implementation of a version of 11 available at 19 and a non optimized version of the algorithm described in 10 . The proposed strategy and 10
The higher depth of circuits using the divide-and-conquer strategy with small vectors occurs because of the use of threequbits gates to combine the vectors. In other works, it is only necessary to use O(n) qubits to load a 2 n -dimensional vector while requiring sequential applications of O(2 n ) n-controlled gates. To improve the performance of the divide-and-conquer loading strategy and to reduce the number of qubits one can combine algorithm 11 with the divide-and-conquer strategy. Instead of divide the vector in parts with size 2, we can divide the vector in parts with size k (equal to a power of 2), load the normalized k-dimensional vectors using a sequential algorithm and combine the small vectors with the divide-and-conquer approach.

Hierarchical Quantum Classifier
This section compares the divide-and-conquer algorithm with two other approaches in which input data encoding in a quantum state can be achieved to initialize a quantum circuit, namely qubit encoding and amplitude encoding. In the former, data is encoded in the amplitudes of individual qubits in a fully separable state, performed using single-qubit rotations 20 . In the later, data is encoded in the amplitudes of an entangled state 11,18 , similarly to the divide-and-conquer. We use the accuracy of a quantum variational classifier as a metric to evaluate the state preparations. The divide-and-conquer algorithm is expected to produce results similar to the amplitude encoding. The results of the classifier using qubit encoding are also presented for completeness, albeit our main objective is to compare the divide-and-conquer and amplitude encoding schemes.
The classifier is based on a tree-like circuit known as tree tensor network (TTN) 20 . This choice is based on the fact that tensor networks can represent both neural networks and quantum circuits, acting as a link between these fields 21,22 . Initially, it applies a set of two-qubit unitaries to each pair of qubits from the initial state, discarding one output from each unitary, leaving half the number of qubits left for the next layer. The process is repeated until only one qubit remains. Multiple measurements are carried on this last qubit to approximate the expectation value.
Following Grant et al. 20 , we built the circuits using single-qubit rotations around the y-axis of the Bloch sphere, denoted by R y (θ ), and CNOT gates, composing two-qubit unitary blocks CNOT · (R y (θ 0 ) ⊗ R y (θ 1 )). The single-qubit rotation angle θ is subject to training by some optimization procedure. Examples of the resulting circuits are represented in Figs. 6a, 6b, and 6c.
We follow the general classical-quantum hybrid approach in which the optimization procedure is processed on a classical computer to determine a set of parameters, i.e. rotation angles for the R y (θ ) operation, for the parametrized quantum circuit. The quantum device prepares a quantum state as prescribed by the circuit pipeline and performs measurements. The measurement outcomes are processed by a classical device to generate a forecast, using it to update the model parameters via a learning algorithm. This whole process is repeated towards the goal.
Four datasets were used in this work: Iris, Haberman's Survival, Banknote Authentication 23 , and Pima Indians Diabetes 24 . Three binary datasets were extracted from the original Iris dataset (paired combinations of the original three classes). Mean test accuracy and one standard deviation are computed on ten random initializations for each dataset and encoding. The simulation results are presented in Table 2, where the test accuracy of the qubit and amplitude encodings are compared against the results obtained using the divide-and-conquer encoding.
The results show similar classification accuracy for all encodings, favoring qubit encoding due to the greater number of circuit parameters for the optimization. The main advantage of divide-and-conquer encoding over qubit encoding is the representation of encoded data in a quantum state of a reduced number of qubits, log 2 (N), compared to the initial state N − 1. This also results in a lower depth classifier. Moreover, when the data is given by qubit encoding, TTN circuits can be evaluated (a) TTN classifier using divide-and-conquer encoding. Gates in the highlighted area encode each element of a length 3 classical data vector in the amplitudes of the entangled state composed by the first two qubits. |0  efficiently using classical techniques 20 . This is not true when the input data is amplitude encoded. The advantage over amplitude encoding is a lower depth encoding circuit for N ≥ 64 (Table 1).
To verify that the above comparison of the models is appropriate, a nonparametric statistical test was employed. We used the Wilcoxon paired signed-rank test 25 with α = 0.05 to check whether there exist significant differences between the classification performances of compared encoders over the chosen datasets. As expected, we verified that amplitude encoding and divide-and-conquer encoding are statistically equivalent for all datasets.

Swap Test
Some metric between two data set encoded as ∑ i x i |i = ∑ i |x i and ∑ j y j | j = ∑ j |ỹ j can be calculated with the state prepared by the divide-and-conquer state preparation and the swap test. The required state is where ∑ i |x i |ψ i and ∑ j |ỹ j |φ j are prepared by the encoding scheme explained in Sec. 3.2 so as to make the ancillary states orthonormal.
After applying the swap test circuit to the above state, i.e. the Hadamard on the first (ancilla) qubit, the swap operation between the test register and the data register controlled by the ancilla qubit, and the Hamadard on the first qubit, one obtains Now, when the σ z measurement is performed on the ancilla qubit, the probability to measure z = ±1, i.e. z = +1 if the ancilla qubit is |0 and z = −1 if the ancilla qubit is |1 , is Therefore, measuring the expectation value of σ z on the ancilla qubit yields Several measures in statistics can be derived from the above result. First, by setting |x i | 2 to be the possible values of a discrete random variable X : Ω → R with the probability Pr(X = |x i | 2 ) = |y i | 2 , the above equation becomes an expectation value of the random variable X. The above equation can be also viewed as the second moment of a discrete random variable X, i.e. E(X 2 ), with the probability Pr(X = x i ) = |y i | 2 . This can be used to calculate the variance of X given E(X) 2 . Alternatively, the above equation can be viewed as E(XY ) of two uniformly-distributed discrete random variables X and Y that satisfy Pr(X = |x i | 2 ) = Pr(Y = |y i | 2 ) = 1/N. This can be used with The idea above can be extended for calculating the covariance of two discrete random variables X and Y with any known probability distribution. Let possible outcomes of X and Y be (|x 0 | 2 , . . . , |x N−1 | 2 ) and (|y 0 | 2 , . . . , |y N−1 | 2 ), respectively, and the probability distribution be (p x 0 , . . . , p x N−1 ) and (p y 0 , . . . , p y N−1 ), respectively. Then the divide-and-conquer algorithm can be used to prepare a state where |p x i = p x i |i , |p y k = p y k |k , |x j = x j | j , |ỹ l = y l |l , and |ψ i jkl is the orthonormal ancillary state as before. Now, the swap test circuit is applied with a small modification such that 3n controlled-swap gates are applied to transform |p x i |x j |p y k |ỹ l to |x j |p y k |ỹ l |p x i when the ancilla qubit for the swap test is |1 . Measuring the expectation value of the σ z observable on the ancilla qubit yields E(X) and E(Y ) can be calculated from the swap test algorithm presented in the beginning of this section, which provided Eq. (14), by choosing the input vectors appropriately. The total time complexity for the aforementioned quantum algorithms is still O q (log 2 2 (N)), since the swap test only requires additional O(log 2 (N)) controlled-swap gates. The quantum speedup can be manifested when constructing a covariance matrix for two multivariate random variables X and Y, each containing m discrete random variables of size N. Since there are m 2 entries in the matrix, the classical time cost is O c (Nm 2 ), while the quantum approach requires O c (N) + O q (log 2 2 (N)m 2 ).

10/13 4 Discussion
One of the major open problems for practical applications of quantum computing is to develop an efficient means to encode classical data in a quantum state 3 . Most quantum algorithms do not present advantages in loading data 2 . The method proposed in this work fills this gap by proposing a new quantum state preparation paradigm, which can complement or enhance the known methods, such as qubit encoding and amplitude encoding. Our approach was based on the Möttönen et al. algorithm 10 and a divide-and-conquer approach using controlled swap gates and ancilla qubits. With this modification, we obtain an exponential quantum speedup in time to load a N-dimensional real vector in the amplitude of a quantum state with a quantum circuit of depth O(log 2 2 (N)) and space O(N). The exponential speedup to load data in quantum devices has a potential impact on speeding up the solution of problems in quantum machine learning and other quantum algorithms that need to load data from classical devices.
The speedup is achieved at the cost of using ancilla qubits that are entangled to the data register qubits. However, we showed that some interesting problems such as quantum supervised machine learning and statistical analysis can be performed with the input quantum state given by our method. The tradeoff between time and space complexities that our method provides is favorable when increasing the circuit width is easier than increasing the circuit depth, which is a likely scenario to occur during the development of near-term quantum devices.
We demonstrated the proof-of-principle using the IBM quantum cloud platform to verify the validity and the feasibility of our method. Furthermore, the numerical experiments showed that the new encoding method offers advantages, reducing complexity and computational resources when applied in conjunction with existing algorithms. Our perspective is that these advantages will extend to other cases.
This work leaves some open questions. What are other problems that can be solved with a divide-and-conquer quantum strategy? What are the implications to efficiently load a quantum vector with entangled information in the ancillary qubits for machine learning? And how to combine sequential with parallel strategies to create a robust algorithm with respect to input size? Also, finding an efficient means to uncompute the ancillary information remains as an interesting future work that will broaden the applicability of our method.

Methods
We performed the proof of concept experiment with a publicly available IBM quantum device consisting of five superconducting qubits, named as ibmq rome. The quantum circuit used in this experiment is depicted in Fig. 5b. The circuit in Fig. 5b is compiled to the physical qubit layout of ibmq rome and the resulting circuit is depicted in Fig. 7 that is executed 1024 times to obtain the data used to generate Fig. 5a. We used the quantum information science kit (qiskit). Python implementation of gen angles and Algorithm 3 are used to generate the quantum circuit in Figures 4 and 5b.  Fig. 5b in accordance with the physical qubit layout of the ibmq rome device. The gates U 1 , U 2 , and U 3 are physical single-qubit gates of IBM Quantum Experience that take in one, two, and three parameters, respectively. The measurement outcomes are stored in classical registers denoted by c[0] and c [1].