Addition of 'Variable' type object

Hi! I would like to construct a circuit like this (see the image attached).
I would like the Rot gate to receive parameter W*X + B, where W is a 3x3 numpy matrix, X and B is 3x1 numpy matrix. So in the code attached, params = [W, B]

image

When I run the circuit, I got this error message:
TypeError: unsupported operand type(s) for +: ‘Variable’ and ‘Variable’

It seems PennyLane’s ‘Variable’ object does not support addition operation (‘+’). Is there any other way to do this?
Thank you!

Hi @eraraya-ricardo,

That’s a good question! Indeed, a previous limitation of PennyLane has been that trainable parameters cannot be combined within a QNode.

Luckily we have recently refactored the backend of PennyLane to now support more arbitrary variable handling. This new approach is called tape mode and can be accessed by running qml.enable_tape() just after your imports. Otherwise, no change should be required.

Hope this works, if not let us know!

It works well, thanks a lot. I never knew this ‘tape mode’ before, thanks.

1 Like