I’ve recently started using pennylane. Thanks for the great tool!
I am trying (unsuccessfully) to build a custom Keras layer in TensorFlow 2 that includes a QNode. The goal is to use QNodes in a “standard” TensorFlow 2 workflow, i.e. define a Keras model, compile and fit. The Keras model should first process input data via a classical NN, then feed it into the parameters of a quantum circuit (all inside the model).
My first attempt failed due to
AttributeError: 'Tensor' object has no attribute 'numpy', which seems to be related to pennylane assuming eager mode but Keras assuming that layers can be both executed as a graph and in eager.
Then I tried using
dynamic=True in the layer init to tell Keras that the layer only works with eager, but this fails with
NotImplementedError: in Keras.
My attempts are on Colab:
Would you mind having a look? I am not sure if I am doing something wrong or if my use case is just not supported.