Feature maps are the way in which classical data gets transformed into quantum states. A good point to start is to use existing templates from libraries like Pennylane.
Basis encoding
Basis encoding might be one of the most simplistic ways to map classical data in quantum states. It requires our data to be composed by integers and maps its binary representation to the basis state that maps the same binary string: \(n = 4, \quad b_n = 1001, \quad |b_n\rangle = |1001\rangle\).
Angle encoding takes benefit from the ability to embed rotation angles into our gates so that we can introduce our numeric data as the rotation angle of a given qubit. Example, \(x = [x_1, x_2,...,x_n]\) would be mapped to
data must be in the regime where those rotations take effect (\([0, 2\pi]\)) and may be more suitable if a cyclic nature is already present. Normalization of data may be relevant preprocessing step in this case.
import pennylane as qmlimport pennylane.numpy as npdev = qml.device('default.qubit', wires=3)@qml.qnode(dev)def feature_map(feature_vector): qml.AngleEmbedding(features=feature_vector, wires=range(3), rotation='Z')return qml.state()X = [2*np.pi,0,np.pi]print(qml.draw(feature_map, level="device")(X))
Amplitude encoding takes the probability amplitude of elements on an array and matches those to the position the where placed at. Assuming our data is composed by \(n\) values (\(X = [x_0, x_1,...,x_n]\) ) its representation would take the shape
Based on some works in the field (Havlíček et al. 2019), IQP circuit family was proposed as a potential good transformation given its hardness when it comes to classical simulation. If there is something quantum that adds to the mixture, this circuits mush be a good way to have those intrinsically added.
ZZ feature map
This is a particular version of the Pauli feature map that we will be able to find in Qiskit. It performs the same rotations we saw in the angle encoding but with an extra \(ZZ\) interaction between data points to capture the correlating observations to further boost their representation. We can also perform several repetitions of the mapping providing a more complex iteration.
Given that it uses \(Z\) rotations it is common to see Hadamard gates preceding those rotations so that by moving our \(|0\rangle\) states to \(|+\rangle\) will make sure those rotations have some meaningful effect.
from qiskit.circuit.library import ZZFeatureMapfeature_map = ZZFeatureMap(3)feature_map.draw('mpl')
feature_map.decompose().draw('mpl', fold=-1)
The general case allows to define a complete specification of Pauli rotations and entanglement layout so that one can customize the feature map to its specifications.
from qiskit.circuit.library import PauliFeatureMapfeature_map = PauliFeatureMap(3, paulis=["X", "YZ"], entanglement='linear')feature_map.decompose().draw('mpl', fold=-1)
Why is this mapping good? Or bad? How many repetitions need to be used? Well, indeed, some of the approaches have no particular rational behind and are much more experimental. We can always look into the literature relevant papers exploring the qualities of each feature map trying to find the one that could be beneficial for our project (Sim, Johnson, and Aspuru-Guzik 2019).
Havlíček, Vojtěch, Antonio D. Córcoles, Kristan Temme, Aram W. Harrow, Abhinav Kandala, Jerry M. Chow, and Jay M. Gambetta. 2019. “Supervised Learning with Quantum-Enhanced Feature Spaces.”Nature 567 (7747): 209–12. https://doi.org/10.1038/s41586-019-0980-2.
Sim, Sukin, Peter D Johnson, and Alán Aspuru-Guzik. 2019. “Expressibility and Entangling Capability of Parameterized Quantum Circuits for Hybrid Quantum-Classical Algorithms.”Advanced Quantum Technologies 2 (12): 1900070.