# Variational Quantum Circuits for Machine Learning.
## 4 Materials and Methods
### Design of a Variational Quantum Algorithm for Quantum Machine Learning  
As previously defined, a variational quantum algorithm is composed of a state preparation stage, a model circuit, and a measurement stage. The model circuit acts on a quantum state in which the input data x have been encoded. The first step is to prepare the circuit by putting the qubits in a superposition state. To do this, Hadamard gates are introduced, which create a basic 50-50 superposition. This means that, when measuring the state, a result of '0' or '1' will be obtained with a 50% probability for each of the states. The Hadamard gate maps the Z-axis to the X-axis (and vice versa). Once the quantum computer is in a superposition state, entanglement is used for state preparation Sx, which consists of embedding the classical data in a quantum state. The most common way to do this operation is amplitude encoding [62; 63; 64; 65]. As a result, the coordinates of a vector are mapped into the amplitude values of a quantum state. With this step, it is possible to map the input data in a nonlinear way into a quantum state, as can be seen in the following equation, which assumes a quantum feature map:  
\[\Phi:\overset{\rightharpoonup}{x}\in\Omega\ \rightarrow\ |\Phi(\overset{ \rightharpoonup}{x})\rangle\langle\Phi(\overset{\rightharpoonup}{x})| \tag{3}\]  
Entanglement is achieved by combining Z quantum gates and two-qubit CNOTs as can be seen in Figure 5. This circuit acts on the initial state \(\mid\!00\rangle\) and does not need to have a high depth to fulfill its function [38], and basically consists of Hadamard gates and a diagonal gate in the Pauli Z-basis [66]. The Z-gate changes the sign of the amplitude when applied to the state of the qubit \(\mid\!1\rangle\) and leaves it unchanged when operating with a qubit in the \(\mid\!0\rangle\) state. Thus, the Z-gate shifts the qubit along the interval on the Bloch sphere over the surface of the sphere from \(\mid\!0\rangle\) to \(\mid\!1\rangle\), rotating values around the z-axis. The CNOT or controlled NOT gate operates two-qubit registers. The CNOT inverts the second qubit if the first qubit has the state \(\mid\!1\rangle\). However, the CNOT does not vary the state of the second qubit if the first qubit has the state \(\mid\!1\rangle\). Once the feature map has been created and the input data are encoded in qubit amplitudes, it is necessary to apply a model circuit U\({}_{\theta}\), where \(\theta\) is a set of classical parameters belonging to R\({}^{2n(0+1)}\). The parameters \(\theta\) are optimized during the training phase. Figure 5: State preparation circuit Sx that maps the training and input data to a quantum feature map. The model circuit is composed of one-qubit quantum gates and quantum gates controlled by an additional single qubit. In this way, the algorithm retains a low depth [41]. The circuit is composed of \(l\) layers, being \(l=5\) in the experiment performed. By increasing the depth with larger \(l\), higher success rates are expected [38]. The model circuit is shown in Figure 6. If a qubit with the state \(\alpha\,|\,0\rangle+\beta\,|\,1\rangle\) is introduced at the input of a Y gate, the output will have the state \(\beta\,\mathrm{i}\,|\,0\rangle-\alpha\,\mathrm{i}\,|\,1\rangle\), so it works as a combination of gates X and Z. Once the model is executed, for a problem of classification '\(y\)' with two labels, a binary measurement is performed on the output state of the qubits. The probability of obtaining a specific outcome in the classification is described in the next equation:  
\[py(x)=2^{-1}(1+y\langle\Phi(\stackrel{{\rightarrow}}{{x}})|U^{T} (\theta)\;f\;U(\theta)|\Phi(\stackrel{{\rightarrow}}{{x}})\rangle), \tag{4}\]  
for a Boolean function f:[0,1]\({}^{n}\). For decision making, the system is executed R times to obtain an empirical distribution. An alternative to this circuit is to use a classical SVM to perform the classification instead of using a variational quantum circuit.