Hi @Kursat_KILIC!
You’re getting this issue because the weights that go into StronglyEntanglingLayers must have the shape (L, M, 3)
, where L = # of layers and M = # of qubits. In your case, if you have a single layer, it should be of size (1, 5, 3)
.
Also, AngleEmbedding receives weights of size (N,)
where N is the number of features. The number of features needs to be equal or less than the number of qubits, which in your case is 5, so you can’t use the same weights for AngleEmbedding and for StronglyEntanglingLayers.
Finally, the adjoint needs to receive the same weight shape as AngleEmbedding.
The following code shouldn’t produce an error anymore although I’m unsure of why you had the first dimension of Xtrain being 580 (note that only the first 5 parameters are being used).
import pennylane as qml
from pennylane import numpy as np
X1train = np.random.rand(580,5)
#print(X1train[0,:].shape)
X2train = np.random.rand(580,1,5,3)
#print(X2train[0,:].shape)
n_qubits = len(Xtrain[0])
n_qubits = 5
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."""
qml.AngleEmbedding(x1, wires=range(n_qubits))
qml.StronglyEntanglingLayers(weights=x2, wires=range(n_qubits))
qml.adjoint(qml.AngleEmbedding)(x1, 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])
kernel(X1train[0,:], X2train[0,:])
Please let me know if this is clear or if you have other questions.