Supervised learning with quantum enhanced feature spaces
Vojtech Havlicek, Antonio D. Córcoles, Kristan Temme, Aram W. Harrow, Abhinav Kandala, Jerry M. Chow, Jay M. Gambetta
References
Supplementary Information: Supervised learning with quantum enhanced feature spaces
Consider a classification task on a set of classes (labels) in a supervised learning scenario. In such settings, we are given a training set and a test set , both are assumed to be labeled by a map unknown to the programmer. Both sets and are provided to the programmer, but the programmer only receives the labels of the training set. So, formally, the programmer has only access to a restriction of the indexing map :
Description of the Algorithm
We consider two different learning schemes. The first is referred to as “Quantum variational classification”, the second is referred to “Quantum kernel estimation”. Both schemes construct a separating hyperplane in the state space of qubits. The classical data is mapped to this space with using a unitary circuit family starting from the reference state .
For our first classification approach we design a variational algorithm which exploits the large dimensional Hilbert space of our quantum processor to find an optimal cutting hyperplane in a similar vein as Support Vector Machines (SVM) do. The algorithm consists of two main parts: a training stage and a classification stage. For the training stage, a set of labeled data points are provided, on which the algorithm is performed. For the classification stage, we take a different set of data points and run the optimized classifying circuit on them without any label input. Then we compare the label of each data point to the output of the classifier to obtain a success ratio for the data set. For both the training and the classification stages, the quantum circuit that implements the algorithm comprises three main parts: the encoding of the feature map, the variational optimization and the measurement, Fig S1. The training phase consists of these steps.
The classification can be applied when the training phase is complete. The optimal parameters are used to decide the correct label for new input data. Again, the same circuit is applied as in Fig S1, however, this time the parameters are fixed and and the outcomes are combined to determine the label which is reported as output of the classifier.
Quantum kernel estimation
For the second classification protocol, we restrict ourselves to the binary label case, with . In this protocol we only use the quantum computer to estimate the kernel matrix . For all pairs of points in the the training data, we sample the overlap to obtain the matrix entry in the kernel. This output probability can be estimated from the circuit depicted in Fig. S5.b. by sampling the output distribution with shots and only taking the count. After the kernel matrix for the full training data has been constructed we use the conventional (classical) support vector machine classifier. The optimal hyperplane is constructed by solving the dual problem in eqn. (6), which is completely specified after we have been given the labels and have estimated the kernel . The solution of the optimization problem is given in terms of the support vectors for which .
The Relationship of variational quantum classifiers to support vector machines
The references vapnik2013nature ; burges1998tutorial provide a detailed introduction to the construction of support vector machines for pattern recognition. Support vector machines are an important tool to construct classifiers for tasks in supervised learning. We will show that the variational circuit classifier bears many similarities to a classical non-linear support vector machine.
The task in constructing a linear support vector machine (SVM) in this scenario is the following. One is looking for a hyperplane that separates the data, with the largest possible distance between the two separated sets. The perpendicular distance between the plane and two points with different labels is called a margin and such points are referred to as ‘support vectors’. This means that we want to maximize the margin by minimizing , or equivalently subject to the constraints as given in eqn. (2), for all data points in the training set . The corresponding cost function can be written as:
where are Lagrange multipliers chosen to ensure the constraints are satisfied.
These slack variables are then used to modify the objective function by . When we choose the optimization problem remains convex and a dual can be constructed. In particular, for , neither the or their Lagrange multipliers appear in the dual Lagrangian.
It is very helpful to consider the dual of the original primal problem in eqn. (4). The primal problem is a convex, quadratic programming problem, for which the Wolfe dual cost function for the Lagrange multipliers can be readily derived by variation with respect to and . The dual optimization problem is
The variables of the primal are given in terms of the dual variables by
and the bias can be computed from the Karush-Kuhn-Tucker (KKT) conditions when the corresponding Lagrange multiplier does not vanish. The optimal variables satisfy the KKT conditions and play an important role in the understanding of the SVM. They are given for primal as
Note that the condition eqn. (12) ensures that either the optimal or the corresponding constraint eqn. (12) is tight. This is a property referred to as complementary slackness, and indicates that only the vectors for which the constraint is tight give rise to non-zero . These vectors are referred to as the support vectors and we will write for their index set. The classifier in the dual picture is given by substituting from eqn. (7) and into the classifier eqn. (3). The bias is obtained for any from the equality in eqn. (12).
The method can be generalized to the case when the decision function does depend non-linearly on the data by using a trick from boser1992training and introducing a high-dimensional, non-linear feature map. The data is mapped via
It is important to note that it is in fact not necessary to construct the mapped data in explicitly. Both the training data, as well as the new data to be classified enters only through inner products, in both the optimization problem for training, c.f. eqn. (6), as well as in the classifier, eqn. (3). Hence, we can construct the SVM for arbitrarily high dimensional feature maps , if we can efficiently evaluate the inner products and , for and . In particular, if we can find a kernel that satisfies Mercer’s condition (which ensures that the kernel is positive semi-definite and can be interpreted as matrix of inner products) boser1992training ; vapnik2013nature , we can construct a classifier by setting
Variational circuit classifiers:
where we have defined the diagonal operator
In classification tasks we assign c.f. eqn. (34), the label with the highest empirical weight of the distribution . We ask whether the outcome is more likely than , or vice versa. That is, we ask, whether or whether the converse is true. This of course depends on the sign of the expectation value for the data point .
To understand how this relates to the SVM in greater detail, we need to choose an orthonormal operator basis, such as for example the Pauli group
This means that both the measurement operator in the -rotated frame as well as the state can be expanded in terms of the operator basis with only real coefficients as
This expression is identical to the conventional SVM classifier, c.f. eqn. (3), after the feature map has been applied. However, in the experiment we only have access to the probabilities through estimation. Furthermore, the are constrained to stem from the observable measured in the rotated frame.
This means, that the correct feature space, where a linearly separating hyperplane is constructed is in fact the quantum state space of density matrices, and not the Hilbert space itself. This is reasonable, since the physical states in are only defined up to a global phase . The equivalence of states up to a global phase would make it impossible to find a separating hyperplane, since both and give rise to the same physical state but can lie on either side of a separating plane.
Encoding of the data using a suitable feature map
The action of the map can be understood by a unitary circuit family denoted by that is applied to some reference state, e.g. . The resulting state is given by . The state in the feature space should depend non-linearly on the data. Let us discuss proposals for possible feature maps
There are many choices for the feature map . Let us first discuss what would happen if we were to choose a feature map that corresponds to a product input state. We assume a feature map, comprised of single qubit rotations on every qubit on the quantum circuit. The angles for every qubit can be chosen as a non-linear function into the space of Euler angles for the individual qubits, so that the full feature map can be implemented as:
One example for such an implementation is the unitary implementation of the feature map used in the context of the classical classifiers by Stoudenmire and Schwab stoudenmire2016supervised based on tensor networks. There each qubit encodes a single component of so that qubits are used. The resulting state that that is prepared is then
Non-trivial feature map with entanglement
There are many choices of feature maps, that do not suffer from the malaise of the aforementioned product state feature maps. To obtain an quantum advantage we would like these maps to give rise to a kernel that is computationally hard to estimate up to an additive polynomially small error by classical means. Otherwise the map is immediately amenable to classical analysis and we are guaranteed to have lost any conceivable quantum advantage.
Let us therefore turn to a family of feature maps, c.f. Fig S2 for which we conjecture that it is hard to estimate the overlap on a classical computer. We define the family of feature map circuit as follows
which leaves , real parameters to encode the data. In particular, we know that we have at least real numbers to encode the data. Furthermore, depending on the connectivity of the interactions, we have further parameters that can be used to encode more data or nonlinear relations of the initial data points.
This feature map encodes both the actual function of the diagonal phases, as well as the corresponding Fourier-Walsh transform at
Since we have that the variance of the random variable is bounded by since , we get an additive error that scales as . This means for a single layer, the kernel can be estimated classically.
Quantum variational classification
Following the structure of the feature map circuit, we construct the classifier part of the variational algorithm by appending layers of single-qubit unitaries and entangling gates Fig. S3.a. Each subsequent layer, or depth, contains an additional set of entanglers across all the qubits used for the algorithm. We use a coherently controllable quantum mechanical system, such as for example the superconducting chip with transmon qubits to prepare a short depth quantum circuit . In the experiment here, comprising qubits, one controlled-phase gate is added per depth. The single-qubit unitaries used in the classifier are limited to and rotations to simplify the number of parameters to be handled by the classical optimizer. Our use of controlled-phase, rather than CNOT, gates for the entanglers is justified by our aim at increased generality in our software. Using controlled-phase gates does not require to particularize this part of the algorithm for different systems topologies. A specific entangling map for a given device can then be used by our compiler to translate each controlled-phase gate into the CNOTs available in our system.
The general circuit is comprised of the following sequence of single qubit and multi-qubit gates:
We apply a circuit of repeated entanglers as depicted in Fig S3.b and interleave them with layers comprised of local single qubit rotations:
This short-depth circuit can generate any unitary if sufficiently many layers are applied. The circuit Fig. S3.a can be understood as a bang-bang controlled evolution of an Ising model Hamiltonian ,c.f. Fig. S3.b, interspersed with single qubit control pulses in on every qubit. It is known that this set of drift steps together with all single control pulses are universal, so we have that any state can be prepared this way with sufficient circuit depth d2007introduction . For a general unitary gate sequence the entangling unitary has to be effectively generated from cross resonance gates, by applying single qubit control pulses.
Choosing the cost-function for the circuit optimization
The central goal is to find an optimal classifying circuit , c..f. eqn. (31) that separates the data sets with different labels. Since we can re-run the same classifying multiple times ( shots), we may consider a ‘winner takes all’ scenario, where we assign the label according to the outcome with the largest probability. We choose a cost function, so that the optimization procedure minimizes the probability of assigning the wrong label after having constructed the distribution after shots.
There are multiple ways of performing a multi-label classification. We only need to modify the final measurement , to correspond to multiple partitions. This can be achieved by multiple strategies. For example one could choose to measure again in the computational basis, i.e. the basis in which Pauli are diagonal and then constructing classical labels form the measured samples, such as a labeling the outcome according to a function . The resulting is therefore diagonal in the computational basis. Alternatively one could construct a commuting measurement akin to the syndrome check measurement for quantum stabilizers. For this approach we choose a set of Pauli matrices that are commuting . The resulting measurement that would need to be performed is similar to that of an error correcting scheme. The measurement operators are given by . Here denotes the ’th bit in the binary representation of . In either case, the decision rule that assigns the labels can be written as
This corresponds to taking shots in order to estimate the largest outcome probability from the outcome statistics of the measurement for . Labelling the subset of samples labelled with , the overall expected misclassification rate is given by:
Binary label classification
Assume the programmer classifies into labels by taking shots for a single datapoint. She obtains an empirical estimates of probability of the datum being labeled by a label
After shots and a prior bias , she misclassifies into a label if
The probability of her misclassifying a sample according to the argmax rule is hence estimated by
Assuming large , computing this exactly may be difficult. Setting and , we can approximate the binomial CDF as an error function:
See Fig. S4. The error function can be consequently approximated with a sigmoid
as an estimate for misclassifying a sample . The cost function to optimize is then given by using this in eqn. (35).
For multiple labels, one tries to optimize
We consider the case of three labels. For samples with frequencies , drawn independently from the output probability distribution, the probability of misclassifying a sample by argmax is given by
where the last inequality is derived as follows
Hence setting , it follows that
This however still depends on , which can’t be simply eliminated. Additionally, for a general -label case, there is no simple analytic solution for . For this reason, we therefore try to estimate the above probability by simply taking . So for -label case, the cost function terms are given by
Quantum kernel estimation
For the second classification method we only use the quantum computer to estimate the kernel for all the labeled training data . Then we use the classical optimization problem as outlined again in eqn. (6) to obtain the optimal Lagrange multipliers and support vectors can be obtained. From this the classifier can be constructed, c.f .eqn. (14). To apply the classifier to a new datum the kernel between and the support vectors in has to be estimated. We discuss two methods to estimate this overlap for our setting.
The usual method of estimating the fidelity between two states is by using the swap test buhrman2001quantum . This circuit, however, is not a short depth circuit on a quantum computing architecture with geometrically local gates. It would require a sequence of controlled SWAP, also known as Fredkin gates, all conditioned on the state of the same ancilla qubit. A very nice protocol was recently developed in cincio2018learning . The authors have learned multiple ways of optimizing the conventional swap test. If only the value of the fidelity is needed, as is the case for our algorithm, the authors propose, c.f. cincio2018learning section III.C, a circuit that is constant depth if pairs of CNOT gates can be executed in parallel. This circuit, c.f. Fig S5.a, evaluates the expectation value directly. The action of the algorithm can be understood as follows:
The SWAP gate is both a unitary gate and a hermitian observable with eigenvalues . The expectation value on two product states as we said given by . Now the gate can be decomposed in to a product of two qubit swap gates that act all in parallel. To evaluate the expectation value one has to diagonalize the full gate. This is achieved by diagonalizing the individual two-qubit swap gates by observing that . Furthermore using the circuit identity , we see that is diagonalized by and has eigenvalue . For the full circuit Fig S5.a one first applies a transversal set of CNOT gates across both registers followed by a single layer of Hadamard gates on the top register. Then the output is sampled and the average of the boolean function
is reported. The output bits on the top register are labeled by , while is the output string on the lower register.
Note that the optimization problem, eqn. (6) is only concave, when the matrix is positive semi-definite. It can happen, that the shot noise and other errors in the experiment lead to a that is no longer positive semi-definite. We have indeed observed this multiple times in the experiment. A possible way of dealing with this problem is a method developed in smolin2012efficient , where an optimization problem is solved to find the closest positive semi-definite -matrix in trace norm to consistent with the constraint. In our experiments however, we have found this not to be necessary and the performance has been almost optimal without performing this method.
Device parameters
Our device is fabricated on a 720-m-thick Si substrate. A single optical lithography step is used to define all CPW structures and the qubit capacitors with Nb. The Josephson junctions are patterned via electron beam lithography and made by double-angle deposition of Al.
The dispersive readout signals are amplified by Josephson Parametric Converters Bergeal2010 (JPC). Both the quantum processor and the JPC amplifiers are thermally anchored to the mixing chamber plate of a dilution refrigerator.
The two qubit fundamental transition frequencies are GHz, with anharmonicities MHz, where . The readout resonator frequencies used are GHz, while the CPW bus resonator connecting and was unmeasured and designed to be 7.0 GHz. The dispersive shifts and line widths of the readout resonators are measured to be MHz and kHz, respectively.
The two qubit lifetimes and coherences were measured intermittently throughout our experiments. The observed mean values were , , s with
Gate characterization
Our experiments use calibrated rotations ( and ) as single-qubit unitary primitives. rotations are attained by appropiate adjustment of the pulse phases, whereas rotations are implemented via frame changes in software mckay2017efficient . A time buffer is added at the end of each physical pulse to mitigate effects from reflections and evanescent waves in the cryogenic control lines and components.
We use two sets of gate times in order to perform the Richardson extrapolation of the noise in our system temme2017error . For the first set of gate times we use 83 ns for single-qubit gates and 333 ns for each cross-resonance pulse. The buffer after each physical pulse is 6.5 ns. The single-qubit gates are gaussian shaped pulses with ns. The cross-resonance gates are flat with turn-on and -off gaussian shapes of ns. Our implementation of a CNOT has a duration of two single-qubit pulses and two cross-resonance pulses, giving a total of 858 ns for the first set of gate times, including buffers. For our second set of gate times we use the times of the first set but stretched by a factor of 1.5, including the pulses s and the buffers. This gives a total CNOT time of 1.287 s and single-qubit gates of ns.
We experimentally verified our single- and two-qubit unitaries by Randomized Benchmarking (RB) Gambetta2012 ; Corcoles2013 . The following table shows the RB results for all single-qubit gates used in our experiments, including individual and simultaneous RB.
Our two-qubit unitarias are CNOTs constructed from echo cross-resonance sequences Corcoles2013 ; Sheldon2016 . Each of the two cross-resonance pulses in a CNOT has durations of 333 and 500 ns for the two different gate lengths used in our experiments. For our two-qubit RB we obtain a CNOT error of () for the 333 (500) ns cross-resonance pulse.
Readout correction
Our readout assigned fidelity was for both qubits.
For each experiment, we run 4 () calibration sequences preparing our two qubits in their joint computational states. We gather statistics of these calibrations and create a measurement matrix where is the probability of measuring state having prepared state . We then correct the observed outcomes of our experiments by inverting this matrix and multiplying our output probability distributions by this inverse.
Support vectors
Here we show the support vectors and as calculated for each of the three datasets studied from their matrices.
Error mitigation for kernel estimation
The experimental estimation of the kernel matrices shown in Fig. S7 and in Fig. 4 in the main text involves running the experiments at different gate lengths and extrapolating the expectation value of the observable of interest to its zero-noise value. While this technique can be extremely powerful in scenarios where the noise is invariant under time rescaling, it is particularly sensitive to measurement sampling noise. In many cases it is the experimental readout assignment fidelity that determines the bound on how precisely the observable can be estimated.
Even though for our Sets I and II we attain 100 % classification success over 10 randomly drawn test sets in each case, we can quantify how close our experimentally determined separating hyperplane is to the ideal.
The optimal hyperplane for a given training set can be expressed as the linear combination (eqn. 7), where is a vector orthogonal to the optimal separating hyperplane and are the support vectors. We can therefore quantify the distance between the experimentally obtained hyperplane and the ideal hyperplane by calculating the inner product where and are the sets of experimentally obtained and ideal support vectors, respectively.
In Fig. S8 we show the inner products between the ideal and all experimental hyperplanes, including the two sets of gate times used throughout our experiments, and , as well as the error-mitigated hyperplanes.
For Sets I and II, which classify at 100 % success, it is clear that error mitigation improves our results very significantly. This is not the case for Set III, which classifies at 94.75 % success. In fact, for Set III we see that error-mitigation worsens the hyperplane, as the results are closer to the ideal for the unmitigated experiments than both Sets I and II.
A look at the calibration data taken along the direct kernel estimation experiments for each set, we see that the readout assignment fidelities of () are 96.56% (96.31%) for Set I, 95.90% (96.36%) for Set II, and 93.99% (95.47%) for Set III. The slightly worse readout fidelities for Set III could partially explain the worse classification results for this set, but other aspects of the protocol might also contribute to this, like for example some gates operating on a somewhat non-linear regime after the calibrations in this set.
Another symptom for the degree of classification success in a given set can be observed by looking at the combined weight of negative eigenvalues in the kernel matrix, , with the eigenvalues of the kernel. We obtain 1.40, 1.27 and 2.41 for Sets I, II, and III, respectively.