qxmt.kernels.pennylane package#
Submodules#
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]
qxmt.kernels.pennylane.projected_kernel module#
- class qxmt.kernels.pennylane.projected_kernel.ProjectedKernel(device, feature_map, gamma=1.0, projection='z')#
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'])
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=1024, >>> ) >>> 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='z')#
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]
Module contents#
- class qxmt.kernels.pennylane.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]
- class qxmt.kernels.pennylane.ProjectedKernel(device, feature_map, gamma=1.0, projection='z')#
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'])
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=1024, >>> ) >>> 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='z')#
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]