I want to know if Pennylane support the evolution of density matrix, that is, the input of the circuit is a density matrix but not a state vector.
please click the picture
you can see the full screeshot
The @qml.qnode(dev) part is very important because it’s the part that makes your circuit a quantum node (qnode). If you don’t add it then PennyLane won’t know what device to run this circuit on.
From what I can see in your code the problem is that you’re trying to put one quantum circuit into another. I would suggest that you try passing the density matrix as a parameter of the second circuit instead, and see if this fixes your problem.
Let me know if this helps!
You can use a single optimizer for both circuits but you need to have a single cost function. One reason why you may be running into problems is because you haven’t set your parameters as trainable. You can define your initial parameters ‘params’ outside of the ‘train’ function and set them as trainable by adding the “requires_grad” argument to the array like this:
params = np.array([0.1,0.2,0.3,0.2],requires_grad=True) . This will let the optimizer know that you need to optimize over these parameters. You can do the same for any other parameters that you need to train.
I also saw somewhere in your code that you have
._value. This will cause problems with the differentiation. I recommend that you try to simplify your program so that you can avoid this.
Please let me know if this helps!
pennylane has the numpy library, if we set params = np.array([0.1,0.2,0.3,0.2]), arguments will has the property, “requires_grad=True”.
You give the other suggestion, help me a lot. Here’s where the problem arose.
Thank you very much.
You are a great problems solver.
I’m glad I could help you solve your problem @shangshang_shi! And thank you for the compliment