qxmt.kernels.pennylane.fidelity_kernel module#
- class qxmt.kernels.pennylane.fidelity_kernel.FidelityKernel(device, feature_map)
Bases:
BaseKernel
Fidelity kernel class. The fidelity kernel is a quantum kernel that computes the kernel value based on the fidelity between two quantum states.
- Parameters:
BaseKernel (_type_) – base class of kernel
device (BaseDevice)
feature_map (BaseFeatureMap | Callable[[ndarray], None])
Examples
>>> import numpy as np >>> from qxmt.kernels.pennylane.fidelity_kernel import FidelityKernel >>> from qxmt.feature_maps.pennylane.defaults import ZZFeatureMap >>> from qxmt.configs import DeviceConfig >>> from qxmt.devices.builder import DeviceBuilder >>> config = DeviceConfig( ... platform="pennylane", ... name="default.qubit", ... n_qubits=2, ... shots=1024, >>> ) >>> device = DeviceBuilder(config).build() >>> feature_map = ZZFeatureMap(2, 2) >>> kernel = FidelityKernel(device, feature_map) >>> x1 = np.random.rand(2) >>> x2 = np.random.rand(2) >>> kernel.compute(x1, x2) 0.14
- __init__(device, feature_map)
Initialize the FidelityKernel class.
- Parameters:
device (BaseDevice) – device instance for quantum computation
feature_map (BaseFeatureMap | Callable[[np.ndarray], None]) – feature map instance or function
- Return type:
None
- compute(x1, x2)
Compute the fidelity kernel value between two data points.
- Parameters:
x1 (np.ndarray) – numpy array representing the first data point
x2 (np.ndarray) – numpy array representing the second data point
- Returns:
fidelity kernel value and probability distribution
- Return type:
tuple[float, np.ndarray]