hi, everyone,

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.

# Hi, everyone, Does the Pennylane support the evolution of density matrix? thanks

Hi @shangshang_shi,

QubitDensityMatrix allows you to prepare a density matrix on a subsystem. Is this what you were looking for? You can also use density_matrix as the measurement in your circuit.

please click the picture

you can see the full screeshot

Hi @shangshang_shi,

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!

Hi @shangshang_shi,

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!

hi ,@CatalinaAlbornoz,

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.