FidelityStatevectorKernel#
- 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)[source]#
Bases:
BaseKernel
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
data
attribute of aStatevector
object 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 usingclear_cache()
. By default the cache is cleared whenevaluate()
is called, unlessauto_clear_cache
isFalse
.Shot noise emulation can also be added. If
shots
isNone
, 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
enforce_psd
set toTrue
this condition is enforced.References: [1] 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]
- Parameters:
feature_map (QuantumCircuit | None) -- Parameterized circuit to be used as the feature map. If
None
is given,ZZFeatureMap
is 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_map
quantum circuit and used to compute the fidelity kernel. This type should inherit from (and defaults to)Statevector
.cache_size (int | None) -- Maximum size of the statevector cache. When
None
this is unbounded.auto_clear_cache (bool) -- Determines whether the statevector cache is retained when
evaluate()
is called. The cache is automatically cleared by default.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 notNone
.
Attributes
- enforce_psd#
Returns
True
if the kernel matrix is required to project to the closest positive semidefinite matrix.
- feature_map#
Returns the feature map of this kernel.
- num_features#
Returns the number of features in this kernel.
Methods