I meet a problem when I use qml.TorchLayer. I want to use my own way to define the encoding layer. So I use the following way to encoding the inputs.
for i in range(n_qubits):
qml.RY(inputs[i], wires=i)
But I get the error as follows.
RuntimeError: shape '[5, -1]' is invalid for input of size 2
And when I use ‘qml.AngleEmbedding(inputs, wires=range(n_qubits), rotation=‘Y’)’, it works. Since I haven’t updated my pennylane. I think these two are the same things in the previous version, right? But in the latest version, it seems not. Can anybody help me with this? If I want to use my own encoding layer in the latest version, what should I do?
Would you mind sending me a minimal working version of your code that reproduces this error? And can you please post the output of qml.about() and your full error traceback?
Thank you for the code! Now, would mind send me the output of qml.about()?
I think you meant to say that by substituting RY for AngleEmbedding, the code works, right? I believe that the problem is you are trying to batch inputs/results, but not passing a proper parameter that’s supposed to do the batching for you. Make sure that the arguments (inputsweight) shapes and sizes match your circuit.
I just meant that you have to pass the arguments with proper dimensions to the functions and/or templates you would like to use. It does not mean that input and weights should have the same dimensions, you should just be careful to which functions you are passing those parameters.
On this version, pennylane didn’t have batch support, so it was basically calling the qnode several times. The problem in your code is that the for-loop in the qnode assumes it isn’t batched, that’s why you are getting the error. Try using qml.RY(inputs[…, i], wires=i)!