qxmt.kernels.pennylane.projected_kernel module

qxmt.kernels.pennylane.projected_kernel module#

class qxmt.kernels.pennylane.projected_kernel.ProjectedKernel(device, feature_map, gamma=1.0, projection='xyz')

Bases: BaseKernel

Projected kernel class. The projected kernel is a quantum kernel that projects the quantum state to a specific basis and computes the kernel value based on the projected measurement results. Reference: https://www.nature.com/articles/s41467-021-22539-9

Parameters:
  • BaseKernel (_type_) – base class of kernel

  • device (BaseDevice)

  • feature_map (BaseFeatureMap | Callable[[ndarray], None])

  • gamma (float)

  • projection (Literal['x', 'y', 'z', 'xyz', 'xyz_sum'])

Examples

>>> import numpy as np
>>> from qxmt.kernels.pennylane.projected_kernel import ProjectedKernel
>>> 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=1000,
>>> )
>>> device = DeviceBuilder(config).build()
>>> feature_map = ZZFeatureMap(2, 2)
>>> kernel = ProjectedKernel(device, feature_map)
>>> x1 = np.random.rand(2)
>>> x2 = np.random.rand(2)
>>> kernel.compute(x1, x2)
0.86
__init__(device, feature_map, gamma=1.0, projection='xyz')

Initialize the ProjectedKernel class.

Parameters:
  • device (BaseDevice) – device instance for quantum computation

  • feature_map (BaseFeatureMap | Callable[[np.ndarray], None]) – feature map instance or function

  • gamma (float) – gamma parameter for kernel computation

  • projection (str) – projection method for kernel computation

Return type:

None

compute(x1, x2)

Compute the projected 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:

projected kernel value and probability distribution

Return type:

tuple[float, np.ndarray]