qxmt.feature_maps.base module#
- class qxmt.feature_maps.base.BaseFeatureMap(platform, n_qubits)
Bases:
ABC
Base class for feature map. This class is used to define the feature map for quantum machine learning. The feature map defined a quantum circuit that maps input data to quantum states. Provide a common interface within the QXMT library by absorbing differences between multiple platforms. User can define their own feature map by inheriting this class and defined in the ‘feature_map’ method.
Examples
>>> import numpy as np >>> import pennylane as qml >>> from qxmt.feature_maps.base import BaseFeatureMap >>> class CustomFeatureMap(BaseFeatureMap): ... def __init__(self, platform: str, n_qubits: int) -> None: ... super().__init__(platform, n_qubits) ... ... def feature_map(self, x: np.ndarray) -> None: ... # define quantum circuit ... qml.RX(x[0, 0], wires=0) ... >>> feature_map = CustomFeatureMap("pennylane", 2) >>> feature_map(np.random.rand(1, 2))
- Parameters:
platform (str)
n_qubits (int)
- __init__(platform, n_qubits)
Initialize the feature map class. [NOTE]: currently, only supports ‘pennylane’ platform. multi-platform support will be added in the future.
- Parameters:
platform (str) – name of quantum platform
n_qubits (int) – number of qubits
- Return type:
None
- check_input_dim_eq_nqubits(x, idx=-1)
Check if the input data dimension matches the number of qubits.
- Parameters:
x (np.ndarray) – input data
idx (int, optional) – index of the dimension of qubit. Defaults to -1.
- Raises:
InputShapeError – input data dimension does not match the number of qubits.
- Return type:
None
- draw(x=None, x_dim=None, format='default', logger=<Logger qxmt.feature_maps.base (INFO)>, **kwargs)
Draw the circuit using the platform’s draw function.
- Parameters:
x (Optional[np.ndarray], optional) – input example data for drawing the circuit. Defaults to None.
x_dim (Optional[int], optional) – dimension of input data. Defaults to None.
format (str, optional) – format of the drawing the circuit. Select “defalt” or “mpl”. Defaults to “default”.
logger (Logger, optional) – logger object. Defaults to LOGGER.
kwargs (Any)
- Raises:
NotImplementedError – not supported platform
- Return type:
None
- abstract feature_map(x)
Feature map function that maps input data to quantum states.
- Parameters:
x (np.ndarray) – input data
- Return type:
None
- class qxmt.feature_maps.base.FeatureMapFromFunc(platform, n_qubits, feature_map_func)
Bases:
BaseFeatureMap
Wrap the feature map function to the BaseFeatureMap class.
- Parameters:
platform (str)
n_qubits (int)
feature_map_func (Callable[[ndarray], None])
- feature_map(x)
Feature map function that maps input data to quantum states.
- Parameters:
x (np.ndarray) – input data
- Return type:
None