Custom Trainable Operator

Hi, I know that with PennyLane you can implement your own operators with trainable parameters but I’m having trouble with it.
I want to define the operator exp(ialphalambda) where i is the imaginary unit, alpha is the trainable parameter and lambda is a 4x4 matrix. Since lambda is 4x4 also its exponential matrix will be and in the end I expect an operator which works on 2 qubits.
Can someone please help me?

Hi @Michele_Morelli , welcome to the Forum!

I think that what you want is the qml.evolve() function. The arguments to this function are an operator and a coefficient. Note that the function already comes with a minus sign in the exponent so you should take this into account when setting the value for your coefficient.

You can use qml.Hermitian() to construct your operator from your matrix (lambda), and set it to work with the qubits that you want (eg: wires=range(2)).

I hope this helps you!