squlearn.kernel.lowlevel_kernel
.FidelityKernel
- class squlearn.kernel.lowlevel_kernel.FidelityKernel(encoding_circuit: EncodingCircuitBase, executor: Executor, evaluate_duplicates: str = 'off_diagonal', mit_depol_noise: str | None = None, initial_parameters: ndarray | None = None, parameter_seed: int | None = 0, regularization: str | None = None, use_expectation: bool = False, caching: bool = False)
Fidelity Quantum Kernel.
The Fidelity Quantum Kernel is a based on the overlap of the quantum states. These quantum states can be defined by a parameterized quantum circuit. The Fidelity Quantum Kernel is defined as:
\[K(x,y) = |\langle \phi(x) | \phi(y) \rangle|^2\]This class wraps to the respective Quantum Kernel implementations from Qiskit Machine Learning. Depending on the choice of the backend and the choice of trainable parameters, the appropriate Quantum Kernel implementation is chosen.
- Parameters:
encoding_circuit (EncodingCircuitBase) – PQC encoding circuit.
executor (Executor) – Executor object.
evaluate_duplicates (str) – Option for evaluating duplicates (‘all’, ‘off_diagonal’, ‘none’).
mit_depol_noise (Union[str, None]) – Option for mitigating depolarizing noise (
"msplit"
or"mmean"
) after Ref. [4]. Only meaningful for FQKs computed on a real backend.initial_parameters (Union[np.ndarray, None], default=None) – Initial parameters for the encoding circuit.
parameter_seed (Union[int, None], default=0) – Seed for the random number generator for the parameter initialization, if initial_parameters is None.
regularization (Union[str, None], default=None) – Option for choosing different regularization techniques (
"thresholding"
or"tikhonov"
) after Ref. [4] for the training kernel matrix, prior to solving the linear system in thefit()
-procedure.use_expectation (bool, default=False) – Option for using the expectation value of a QNN circuit that computes the fidelity as the expectation value of the observable \(P_0 = |0\rangle\langle0|^{\otimes n}\). This is not very efficient in simulation, but allows the computation of derivatives of the kernel.
References
- assign_parameters(parameters)
Fix the training parameters of the encoding circuit to numerical values
- Parameters:
parameters (np.ndarray) – Array containing numerical values to be assigned to the trainable parameters of the encoding circuit
- evaluate(x: ndarray, y: ndarray | None = None) ndarray
Evaluates the fidelity kernel matrix.
- Parameters:
x (np.ndarray) – Vector of training or test data for which the kernel matrix is evaluated
y (np.ndarray, default=None) – Vector of training or test data for which the kernel matrix is evaluated
- Returns:
Returns the quantum kernel matrix as 2D numpy array.
- evaluate_derivatives(x: ndarray, y: ndarray = None, values: str | tuple = 'dKdx') dict
Evaluates the Fidelity Kernel and its derivatives for the given data points x and y.
- Parameters:
x (np.ndarray) – Data points x
y (np.ndarray) – Data points y, if None y = x is used
values (Union[str, tuple]) – Values to evaluate. Can be a string or a tuple of strings. Possible values are:
dKdx
,dKdy
,dKdxdx
,dKdydy
,dKdxdy
,dKdydx
,dKdp
andjacobian
.
- Returns:
Dictionary with the evaluated values
- evaluate_pairwise(x: ndarray, y: ndarray = None) float
Computes the quantum kernel matrix.
- Parameters:
x (np.ndarray) – Vector of training or test data for which the kernel matrix is evaluated
y (np.ndarray, default=None) – Vector of training or test data for which the kernel matrix is evaluated
- evaluate_with_parameters(x: ndarray, y: ndarray, parameters: ndarray) ndarray
Computes the quantum kernel matrix with assigned parameters
- Parameters:
x (np.ndarray) – Vector of training or test data for which the kernel matrix is evaluated
y (np.ndarray) – Vector of training or test data for which the kernel matrix is evaluated
parameters (np.ndarray) – Array containing numerical values to be assigned to the trainable parameters of the encoding circuit
- get_params(deep: bool = True) dict
Returns hyper-parameters and their values of the fidelity kernel.
- Parameters:
deep (bool) – If True, also the parameters for contained objects are returned (default=True).
- Returns:
Dictionary with hyper-parameters and values.
- set_params(**params)
Sets value of the fidelity kernel hyper-parameters.
- Parameters:
params – Hyper-parameters and their values, e.g.
num_qubits=2