- class FidelityStatevectorKernel(*, feature_map=None, statevector_type=<class 'qiskit.quantum_info.states.statevector.Statevector'>, cache_size=None, auto_clear_cache=True, shots=None, enforce_psd=True)#
A reference implementation of the quantum kernel interface optimized for (and limited to) classically simulated statevectors.
Here, the kernel function is defined as the overlap of two simulated quantum statevectors produced by a parametrized quantum circuit (called feature map):\[K(x,y) = |\langle \phi(x) | \phi(y) \rangle|^2.\]
In this implementation, \(|\phi(y)\rangle\) is given by the
dataattribute of a
Statevectorobject or one of its subclasses. These arrays are stored in a statevector cache to avoid repeated evaluation of the quantum circuit. This cache can be cleared using
clear_cache(). By default the cache is cleared when
evaluate()is called, unless
Shot noise emulation can also be added. If
None, the exact fidelity is used. Otherwise, the mean is taken of samples drawn from a binomial distribution with probability equal to the exact fidelity. This model assumes that the fidelity is determined via the compute-uncompute method. I.e., the fidelity is given by the probability of measuring \(0\) after preparing the state \(U(x)^\dagger U(y) | 0 \rangle\).
With the addition of shot noise, the kernel matrix may no longer be positive semi-definite. With
Truethis condition is enforced.
References:  Havlíček, V., Córcoles, A. D., Temme, K., Harrow, A. W., Kandala, A., Chow, J. M., & Gambetta, J. M. (2019). Supervised learning with quantum-enhanced feature spaces. Nature, 567(7747), 209-212. arXiv:1804.11326v2 [quant-ph]
feature_map (QuantumCircuit | None) -- Parameterized circuit to be used as the feature map. If
ZZFeatureMapis used with two qubits. If there's a mismatch in the number of qubits of the feature map and the number of features in the dataset, then the kernel will try to adjust the feature map to reflect the number of features.
statevector_type (Type[SV]) -- The type of Statevector that will be instantiated using the
feature_mapquantum circuit and used to compute the fidelity kernel. This type should inherit from (and defaults to)
cache_size (int | None) -- Maximum size of the statevector cache. When
Nonethis is unbounded.
shots (int | None) -- The number of shots. If
None, the exact fidelity is used. Otherwise, the mean is taken of samples drawn from a binomial distribution with probability equal to the exact fidelity.
enforce_psd (bool) -- Project to the closest positive semidefinite matrix if
x = y. This is only used when number of shots given is not
Trueif the kernel matrix is required to project to the closest positive semidefinite matrix.
Returns the feature map of this kernel.
Returns the number of features in this kernel.
Clear the statevector cache.
- evaluate(x_vec, y_vec=None)#
Construct kernel matrix for given data.
If y_vec is None, self inner product is calculated.
x_vec (np.ndarray) -- 1D or 2D array of datapoints, NxD, where N is the number of datapoints, D is the feature dimension
y_vec (np.ndarray | None) -- 1D or 2D array of datapoints, MxD, where M is the number of datapoints, D is the feature dimension
2D matrix, NxM
- Return type: