Hi,
I applied Quantum Kernel SVM Classifier, and I got this error;
f"Weights tensor must have second dimension of length {len(wires)}; got {shape[1]}"
n_qubits = len(Xtrain[0])
n_qubits
5
Xtrain.shape
(580,5)
n_qubits = len(Xtrain[0])
n_qubits
dev_kernel = qml.device("default.qubit", wires=n_qubits)
projector = np.zeros((2**n_qubits, 2**n_qubits))
projector[0, 0] = 1
@qml.qnode(dev_kernel)
def kernel(x1, x2):
"""The quantum kernel."""
AngleEmbedding(x1, wires=range(n_qubits))
qml.StronglyEntanglingLayers(weights=x2, wires=range(n_qubits))
qml.adjoint(AngleEmbedding)(x2, wires=range(n_qubits))
return qml.expval(qml.Hermitian(projector, wires=range(n_qubits)))
def kernel_matrix(A, B):
"""Compute the matrix whose entries are the kernel
evaluated on pairwise data from sets A and B."""
return np.array([[kernel(a, b) for b in B] for a in A])
#X_train[0:]
kernel(Xtrain[0,:], Xtrain[0,:])
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-57-99a27e9473fc> in <module>()
21
22 #X_train[0:]
---> 23 kernel(Xtrain[0,:], Xtrain[0,:])
24
3 frames
/usr/local/lib/python3.7/dist-packages/pennylane/templates/layers/strongly_entangling.py in __init__(self, weights, wires, ranges, imprimitive, do_queue, id)
136 shape = qml.math.shape(weights)[-3:]
137
--> 138 if shape[1] != len(wires):
139 raise ValueError(
140 ****f"Weights tensor must have second dimension of** length {len(wires)}; got {shape[1]}"**
IndexError: tuple index out of range