AttributeError: module 'pennylane.kernels' has no attribute 'EmbeddingKernel'

Hi everyone, I tried executing the below lines of codes from the link : https://github.com/thubregtsen/qhack/blob/master/qhack2021/kernel_demonstration.ipynb

dev = qml.device(“default.qubit”, wires=5)
wires = list(range(5))
k = qml.kernels.EmbeddingKernel(lambda x, params: ansatz(x, params, wires), dev)

I am getting the error: AttributeError: module ‘pennylane.kernels’ has no attribute ‘EmbeddingKernel’ . I did all the installations correctly. Really not sure now what to do?

Hey @Manu_Chaudhary !
In other to calculate the kernel matrix you can use qml.kernels.kernel_matrix,
let me know if something doesn’t work :smile:

Somehow this code would not work by just simply putting qml.kernels.kernel_matrix in place of EmbeddingKernel. Please guide me how to make this demonstration notebook work. Thanks in advance.

Actually I just realized that that project that you sent me before is a demo that we have on the website :rocket: In that link you can find the code working on the last PennyLane version

Thank you @Guillermo_Alonso for the help. I am trying to understand the demo code. Need some help to understand it.

@qml.qnode(dev, interface= “autograd”)
def kernel_circuit(x1, x2, params):
ansatz(x1, params, wires= wires)
adjoint_ansatz(x2, params, wires= wires)
return qml.probs(wires= wires)

Please explain me a little about the “autograd”, adjoint and qml.probs. Thank you for the great help

Sure :smile:
the interface determines under which library you want the circuit to work. Autograd in this case means that numpy will be used (in differentiation as well). We are starting to suggest the “torch” interface as it is generally faster. Adjoint is the inverse operator. That is, you will send a circuit as argument and it will give you the circuit whose operation is the inverse. This is very useful in situations like this for calculating inner products. Finally probs, returns the probability of observing each of the basic states in the computational base (|000>, |001>,…).
I hope that helps!

2 Likes

Thank you @Guillermo_Alonso for the help . This topic has great potential but it is too difficult to understand. Are there any videos on youtube to understand pennylane APIs and some related mathematics?

We have many different places where you can learn :rocket: If you are interested in getting into the basics of quantum computing and PennyLane, I recommend the Xanadu Quantum Codebook. We also have many demos classified in different categories that will be of great help depending on what you want to learn. In the case of kernel methods, I am sure you will find several resources of interest in the Quantum Machine learning category :muscle:

Thank you for great great help.

3 Likes