Introduction

The development of quantum computers can dramatically reduce the time to solve certain computational tasks1. However, in practical applications, the cost to load the classical information in a quantum device can dominate the asymptotic computational cost of the quantum algorithm2,3. Loading information into a device is a common task in computer science applications. For instance, deep neural networks4 learning algorithms run in specialized hardware5, 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 systems6. 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 theorem7, noisy quantum operations8, and the decoherence of quantum information9. 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 \(\vec {x}=(x_0, \ldots , 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).

$$\begin{aligned} x_0\vert {0}\rangle + \cdots + x_{N-1}\vert {N-1}\rangle \end{aligned}$$
(1)

Circuits to load an N-dimensional classical unit vector in quantum devices use \(n = \log _2(N)\) qubits and have an exponential depth in relation to the number of qubits (or polynomial in the data size)10,11,12,13.

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

$$\begin{aligned} x_0\vert {0}\rangle \vert {\psi _0}\rangle + \cdots + x_{N-1}\vert {N-1}\rangle \vert {\psi _{N-1}}\rangle , \end{aligned}$$
(2)

where \(\vert {\psi _j}\rangle \) 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 forking13,14 and uses a divide-and-conquer strategy15. 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 sorting16, computing the discrete Fourier transform17, and others15. 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 \(O_c(N) + O_q(\log _2^2(N))\), where \(O_c(N)\) 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\gg 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. “Transformation of quantum states” section reviews one of the standard methods for loading information in a quantum device using controlled rotations10, which we set out to modify to reduce its quantum circuit depth exponentially. “Divide-and-conquer loading data” section 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. “Discussion” section 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 rotations10. 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: (1) Function gen_angles (Line 1) finds angles to perform rotations that lead \(\vert {0}\rangle _n\equiv \vert {0}\rangle ^{\otimes n}\) to the state in Eq. (1), and (2) Function gen_circuit (Line 18) generates a quantum circuit from these rotations.

figure a
Figure 1
figure 1

Data representation of information in function generate angles.

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

$$\begin{aligned} (\sqrt{0.03}, \sqrt{0.07}, \sqrt{0.15}, \sqrt{0.05}, \sqrt{0.1}, \sqrt{0.3}, \sqrt{0.2}, \sqrt{0.1}) \end{aligned}$$

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 \(\theta \) such that \(\sin (\theta /2) = \frac{x[2 k+1]}{new\_x[k]}\) and \(\cos (\theta /2)=\frac{x[2k]}{new\_x[k]}\) to the vector angles. Lines 7 to 16 generate the vector angles in the recursive calls. For the input in Fig. 1b and using two decimal points the algorithm outputs angles = (1.98, 1.91, 1.43, 1.98, 1.05, 2.09, 1.23). The angles vector is used as a complete binary tree named angles-tree. For instance, with \(\alpha _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, \ldots , \log _2(N)\) is \(N/2^{k-1}\). The costs of the recursive calls to generate the angles-vector is \(1 + 2 + 2^2 + \cdots + 2^{\log _2{N}} = O(N)\).

Figure 2
figure 2

Circuit to load an 8 dimensional real vector in a quantum device.

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], \ldots , q[level(k)-1]\) are in the state \(\vert {k-(2^{level(k)}-1)}\rangle \). With \(\alpha _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 \(\vert {0}\rangle _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

$$\begin{aligned} \frac{\sqrt{0.03}}{\sqrt{0.1}}\vert {0}\rangle + \frac{\sqrt{0.07}}{\sqrt{0.1}}\vert {1}\rangle , \frac{\sqrt{0.15}}{\sqrt{0.2}}\vert {0}\rangle + \frac{\sqrt{0.05}}{\sqrt{0.2}}\vert {1}\rangle , \frac{\sqrt{0.1}}{\sqrt{0.4}}\vert {0}\rangle + \frac{\sqrt{0.3}}{\sqrt{0.4}}\vert {1}\rangle \text{ and } \frac{\sqrt{0.2}}{\sqrt{0.3}}\vert {0}\rangle + \frac{\sqrt{0.1}}{\sqrt{0.3}}\vert {1}\rangle \end{aligned}$$

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 \(\vert {\psi _l}\rangle \) representing the state in the half left part of the state-tree in Eq. (3) and the state \(\vert {\psi _r}\rangle \) representing the state in the right part of the state-tree in Eq. (4).

$$\begin{aligned} \vert {\psi _l}\rangle &= {\frac{\sqrt{0.1}}{\sqrt{0.3}}\vert {0}\rangle } \left( \frac{\sqrt{0.03}}{\sqrt{0.1}}\vert {0}\rangle + \frac{\sqrt{0.07}}{\sqrt{0.1}}\vert {1}\rangle \right) + {\frac{\sqrt{0.2}}{\sqrt{0.3}}\vert {1}\rangle } \left( \frac{\sqrt{0.15}}{\sqrt{0.2}}\vert {0}\rangle + \frac{\sqrt{0.05}}{\sqrt{0.2}}\vert {1}\rangle \right) \nonumber \\&= \frac{\sqrt{0.03}}{\sqrt{0.3}}\vert {00}\rangle + \frac{\sqrt{0.07}}{\sqrt{0.3}}\vert {01}\rangle + \frac{\sqrt{0.15}}{\sqrt{0.3}}\vert {10}\rangle + \frac{\sqrt{0.05}}{\sqrt{0.3}}\vert {11}\rangle \end{aligned}$$
(3)
$$\begin{aligned} \vert {\psi _r}\rangle & = {\frac{\sqrt{0.4}}{\sqrt{0.7}}\vert {0}\rangle } \left( \frac{\sqrt{0.1}}{\sqrt{0.4}}\vert {0}\rangle + \frac{\sqrt{0.3}}{\sqrt{0.4}}\vert {1}\rangle \right) + {\frac{\sqrt{0.3}}{\sqrt{0.7}}\vert {1}\rangle } \left( \frac{\sqrt{0.2}}{\sqrt{0.3}}\vert {0}\rangle + \frac{\sqrt{0.1}}{\sqrt{0.3}}\vert {1}\rangle \right) \nonumber \\&= \frac{\sqrt{0.1}}{\sqrt{0.7}}\vert {00}\rangle + \frac{\sqrt{0.3}}{\sqrt{0.7}}\vert {01}\rangle + \frac{\sqrt{0.2}}{\sqrt{0.7}}\vert {10}\rangle + \frac{\sqrt{0.1}}{\sqrt{0.7}}\vert {11}\rangle \end{aligned}$$
(4)

Combining states \(\vert {\psi _l}\rangle \) and \(\vert {\psi _r}\rangle \) weighted with the values of the state in the previous layer generates the desired quantum state described in Eq. (5).

$$\begin{aligned} \begin{aligned} \sqrt{0.3}\vert {\psi _l}\rangle + \sqrt{0.7}\vert {\psi _r}\rangle&= \sqrt{0.03}\vert {000}\rangle + \sqrt{0.07}\vert {001}\rangle + \sqrt{0.15}\vert {010}\rangle + \sqrt{0.05}\vert {011}\rangle \\&\quad + \sqrt{0.1}\vert {100}\rangle + \sqrt{0.3}\vert {101}\rangle + \sqrt{0.2}\vert {110}\rangle + \sqrt{0.1}\vert {111}\rangle \end{aligned} \end{aligned}$$
(5)

To load the classical data using this bottom-up approach we need to combine two m-qubits states \(\vert {\psi }\rangle , \vert {\phi }\rangle \) and one one-qubit state \(a\vert {0}\rangle +b\vert {1}\rangle \) as \(a\vert {0}\rangle \vert {\psi }\rangle + b\vert {1}\rangle \vert {\phi }\rangle \) 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\rangle |\psi \rangle + b|1\rangle |\phi \rangle \) while our method prepares \(a|0\rangle |\psi \rangle |\phi \rangle + b|1\rangle |\phi \rangle |\psi \rangle \).

Figure 3
figure 3

Combining states with controlled-swap operations.

Loading complex data

The divide-and-conquer strategy can be generalized to load a complex vector \( (|x_0|e^{i\omega _0}, |x_1|e^{i\omega _1}, \dots , |x_{N-1}|e^{i\omega _{N-1}}) \) into the probability amplitudes of a quantum state as

$$\begin{aligned} |x_0|e^{i\omega _0}\vert {0}\rangle \vert {\psi _0}\rangle +\dots + |x_{N-1}|e^{i\omega _{N-1}}\vert {N-1}\rangle \vert {\psi _{N-1}}\rangle . \end{aligned}$$
(6)

To explain the process, we introduce two parameters used in Ref.18

$$\begin{aligned} \lambda _{j,v} = \sum _{l=1}^{2^{v-1}} (\omega _{(2j-1)2^{v-1}+l} - \omega _{(2j-2)2^{v-1}+l})/2^{v-1}\text { and } \beta _{j,v} = \sqrt{\sum _{l=1}^{2^{v-1}} |a_{(2j-1)2^{v-1}+l}|^2}/ \sqrt{\sum _{l=1}^{2^{v}}|a_{(j-1)2^v+l}|^2}, \end{aligned}$$

where \(v=1,2,\dots ,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,\dots ,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

$$\begin{aligned} \vert {\psi _{j,1}}\rangle =e^{-i\frac{\lambda _{j,1}}{2}}\sqrt{1-|\beta _{j,1}|^2}\vert {0}\rangle + e^{i\frac{\lambda _{j,1}}{2}}\beta _{j,1}\vert {1}\rangle . \end{aligned}$$
(7)

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

$$\begin{aligned} \vert {\psi _{j,v}}\rangle =e^{-i\frac{\lambda _{j,v}}{2}}\sqrt{1-|\beta _{j,v}|^2}\vert {0}\rangle \vert {\psi _{2j-1,v-1}}\rangle + e^{i\frac{\lambda _{j,v}}{2}}\beta _{j,v}\vert {1}\rangle \vert {\psi _{2j,v-1}}\rangle . \end{aligned}$$
(8)

After recursively updating the state \(\vert {\psi _{j,v}}\rangle \) for \(v=2, \dots , n\) and \(j=1,2,\dots .2^{n-v}\), the desired quantum state is generated as

$$\begin{aligned} \vert {\psi _{1,n}}\rangle =|x_0|e^{i\omega _0}\vert {0}\rangle +|x_1|e^{i\omega _1}\vert {1}\rangle +\dots + |x_{N-1}|e^{i\omega _{N-1}}\vert {N-1}\rangle . \end{aligned}$$
(9)

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(\lambda _{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.

figure b

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(\alpha _k)\). After this step, the qubits with index \(k > \lfloor (N-1)/2\rfloor \) (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 \(\alpha _{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.

figure c

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 + \cdots + \log _2(N)-1)\) with an overall depth in order \(O(\log _2^2(N))\). This result is stated in Theorem 1.

Figure 4
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 \(\alpha [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).

Theorem 1

Algorithm 3 generates a quantum circuit with depth \(O(\log _2^2(N))\).

Orthonormal ancillary

The ancillary states \(\vert {\psi _0}\rangle , \dots , \vert {\psi _{N-1}}\rangle \) in Eq. (2) are not necessarily orthogonal to each other, but we can modify the divide-and-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\rangle ^{\otimes \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

$$\begin{aligned} x_0\vert {0}\rangle \vert {\psi _0}\rangle \vert {0}\rangle + \cdots + x_{N-1}\vert {N-1}\rangle \vert {\psi _{N-1}}\rangle \vert {N-1}\rangle = \sum _{k=0}^{N-1} x_k\vert {k}\rangle |{\tilde{\psi }}_k\rangle , \end{aligned}$$
(10)

where \(\lbrace |{{\tilde{\psi }}}_k\rangle \rbrace _{k=0}^{N-1} = \lbrace \vert {\psi _k}\rangle \vert {k}\rangle \rbrace _{k=0}^{N-1}\) 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 algorithms10,11 with a random input.

Proof of concept with a NISQ device

In this experiment we load a four-dimensional data into a two qubit state \(\vert {\psi }\rangle = \sqrt{0.6}\vert {00}\rangle + \sqrt{0.2}\vert {01}\rangle + \sqrt{0.1}\vert {10}\rangle +\sqrt{0.1}\vert {11}\rangle \) 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 5
figure 5

Proof of concept experiment with a IBM quantum device (ibmq_rome) on the cloud platform.

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 of11 available at19 and a non optimized version of the algorithm described in10. The proposed strategy and10 implementation are publicly available. The implementation of the proposed method shows its theoretical asymptotic time advantage to load a vector when the dimension is larger than 32. The proposed method has two main disadvantages: the linear number of qubits in relation to the logarithmic number in other methods, and the information entangled in the ancillary qubits.

Table 1 A comparison between Refs.10,11 and divide-and-conquer strategy to load a n-dimensional real vector into a quantum computer.

The higher depth of circuits using the divide-and-conquer strategy with small vectors occurs because of the use of three-qubits 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 algorithm11 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.

Example applications

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 rotations20. In the later, data is encoded in the amplitudes of an entangled state11,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 fields21,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(\theta )\), and CNOT gates, composing two-qubit unitary blocks \(CNOT\cdot (R_y(\theta _0) \otimes R_y(\theta _1))\). The single-qubit rotation angle \(\theta \) is subject to training by some optimization procedure. Examples of the resulting circuits are represented in Fig. 6a–c.

Figure 6
figure 6

TTN classifier with (a) divide-and conquer encoding, (c) amplitude encoding and (b) qubit encoding.

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(\theta )\) 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 Authentication23, and Pima Indians Diabetes24. 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.

Table 2 Mean test accuracy and one standard deviation for TTN classifiers with ten different random parameter initializations.

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 efficiently using classical techniques20. This is not true when the input data is amplitude encoded. The advantage over amplitude encoding is a lower depth encoding circuit for \(N\ge 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 test25 with \(\alpha =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 \(\sum _i x_i|i\rangle =\sum _i|{\tilde{x}}_i\rangle \) and \(\sum _j y_j|j\rangle =\sum _j|{\tilde{y}}_j\rangle \) can be calculated with the state prepared by the divide-and-conquer state preparation and the swap test. The required state is

$$\begin{aligned} |0\rangle \sum _{ij}|{\tilde{x}}_i\rangle |{\tilde{y}}_j\rangle |\psi _i\rangle |\phi _j\rangle , \end{aligned}$$
(11)

where \(\sum _i|{\tilde{x}}_i\rangle |\psi _i\rangle \) and \(\sum _j|{\tilde{y}}_i\rangle |\phi _j\rangle \) 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

$$\begin{aligned} \frac{1}{2}\left( |0\rangle \sum _{ij}\left( |{\tilde{x}}_i\rangle |{\tilde{y}}_j\rangle +|{\tilde{y}}_j\rangle |{\tilde{x}}_i\rangle \right) |\psi _i\rangle |\phi _j\rangle + |1\rangle \sum _{ij}\left( |{\tilde{x}}_i\rangle |{\tilde{y}}_j\rangle -|{\tilde{y}}_j\rangle |{\tilde{x}}_i\rangle \right) |\psi _i\rangle |\phi _j\rangle \right) . \end{aligned}$$
(12)

Now, when the \(\sigma _z\) measurement is performed on the ancilla qubit, the probability to measure \(z=\pm 1\), i.e. \(z=+1\) if the ancilla qubit is \(|0\rangle \) and \(z=-1\) if the ancilla qubit is \(|1\rangle \), is

$$\begin{aligned} \Pr (z=\pm 1)&= \frac{1}{4}\sum _{ijkl}2\left( \langle {\tilde{x}}_k|{\tilde{x}}_i\rangle \langle {\tilde{y}}_l|{\tilde{y}}_j\rangle \pm \langle {\tilde{y}}_l|{\tilde{x}}_i\rangle \langle {\tilde{x}}_k|{\tilde{y}}_j\rangle \right) \langle \psi _k|\psi _i\rangle \langle \phi _l|\phi _j\rangle \nonumber \\&= \frac{1}{2}\left( \sum _{ij}\langle {\tilde{x}}_i|{\tilde{x}}_i\rangle \langle {\tilde{y}}_j|{\tilde{y}}_j\rangle \pm |\langle {\tilde{y}}_j|{\tilde{x}}_i\rangle |^2\right) \nonumber \\&=\frac{1\pm \sum _{ij}|\langle {\tilde{y}}_j|{\tilde{x}}_i\rangle |^2}{2}. \end{aligned}$$
(13)

Therefore, measuring the expectation value of \(\sigma _z\) on the ancilla qubit yields

$$\begin{aligned} \sum _{ij}|\langle {\tilde{y}}_j|{\tilde{x}}_i\rangle |^2=\sum _{i} |x_iy_i|^2. \end{aligned}$$
(14)

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:\Omega \rightarrow {\mathbb {R}}\) with the probability \(\mathrm {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 \(\mathrm {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 \(\mathrm {Pr}(X=|x_i|^2)=\mathrm {Pr}(Y=|y_i|^2)=1/N\). This can be used with \(E(X) = \sum _i^N |x_i|^2/N = E(Y) \sum _i^N|y_i|^2/N=1/N\) to calculate the covariance, \(E(XY)-E(X)E(Y)\).

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,\ldots ,|x_{N-1}|^2)\) and \((|y_0|^2,\ldots ,|y_{N-1}|^2)\), respectively, and the probability distribution be \((p^{x}_0,\ldots ,p^{x}_{N-1})\) and \((p^{y}_0,\ldots ,p^{y}_{N-1})\), respectively. Then the divide-and-conquer algorithm can be used to prepare a state

$$\begin{aligned} |0\rangle \sum _{ijkl}|{\tilde{p}}^x_i\rangle |{\tilde{x}}_j\rangle |{\tilde{p}}^y_k\rangle |{\tilde{y}}_l\rangle |\psi _{ijkl}\rangle , \end{aligned}$$
(15)

where \(|{\tilde{p}}^x_i\rangle = \sqrt{p^x_i}|i\rangle \), \(|{\tilde{p}}^y_k\rangle = \sqrt{p^y_k}|k\rangle \), \(|{\tilde{x}}_j\rangle = x_j|j\rangle \), \(|{\tilde{y}}_l\rangle = y_l|l\rangle \), and \(|\psi _{ijkl}\rangle \) 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 \(|{\tilde{p}}^x_i\rangle |{\tilde{x}}_j\rangle |{\tilde{p}}^y_k\rangle |{\tilde{y}}_l\rangle \) to \(|{\tilde{x}}_j\rangle |{\tilde{p}}^y_k\rangle |{\tilde{y}}_l\rangle |{\tilde{p}}^x_i\rangle \) when the ancilla qubit for the swap test is \(|1\rangle \). Measuring the expectation value of the \(\sigma _z\) observable on the ancilla qubit yields

$$\begin{aligned} \sum _{ijkl}\langle {\tilde{p}}^x_i|{\tilde{x}}_j \rangle \langle {\tilde{x}}_j|{\tilde{p}}^y_k \rangle \langle {\tilde{p}}^y_k|{\tilde{y}}_l \rangle \langle {\tilde{y}}_l|{\tilde{p}}^x_i \rangle =\sum _{i} p^x_ip^y_i|x_i|^2|y_i|^2=E(XY). \end{aligned}$$
(16)

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 \({\mathbf {X}}\) and \({\mathbf {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)\).

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 state3. Most quantum algorithms do not present advantages in loading data2. 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. algorithm10 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 Figs. 4 and 5b.

Figure 7
figure 7

The transpiled circuit of the divide-and-conquer state preparation circuit in 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].

The depth of the quantum circuits for state preparations described in Table 1 is obtained using a python implementation of Algorithm 3, the qiskit implementation of11 and a non-optimized version of the algorithm10 available at the GitHub repository. For each input size we generated a random vector used for all methods. In these first two set of experiments we used qiskit version 0.14.1 and python version 3.7.7.

In “Hierarchical quantum classifier” section, simulations of the hybrid classification algorithms were performed using Xanadu’s Pennylane26 default qubit plugin state simulator. We used 2/10 of the datasets as a test set, 2/10 as a validation set, and the remaining as a training set. As preparation for qubit encoding, each data vector element of all datasets was re-scaled within the range of \([0, \pi ]\). Also, for amplitude encoding and divide-and-conquer encoding, the data vectors were normalized. Our simulation employs the Adaptative Moment Estimation (Adam) for the optimization process27 with a learning rate of 0.1 and a batch size of 1/10 of the training set size. Training stops when validation set accuracy does not increase for 30 consecutive tests or 200 iterations is reached.