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 into quantum states. It requires our data to be composed of 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 a relevant preprocessing step in this case but we should also pay attention to the rotation axis, \(Z\) 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 they were placed at. Assuming our data is composed of \(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, these circuits must 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 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 us to define a complete specification of Pauli rotations and entanglement layout so that one can customize the feature map to their 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 rationale behind them and are much more experimental. We can always look into the literature for relevant papers exploring the qualities of each feature map trying to find the one that could be beneficial for our project (Sim et al. 2019).
Havlíček, Vojtěch, Antonio D. Córcoles, Kristan Temme, et al. 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.