Hello I am attempting to use the new Keras quantum layer feature, but I am struggling to pass the output of the LSTM into the Qnode. My attempt is below. I get the error that " TypeError: QNode must include an argument with name inputs for inputting data". Thanks for your time and help.
from pennylane.qnn import KerasLayer
# state vector simualtator
dev = qml.device('default.qubit', wires=2)
n_qubits=2
@qml.qnode(dev,interface='tf')
@qml.qnode(dev)
def circuit(inputs, weights_0, weight_1,weight_2,weight_3,weight_4,weight_5):
#qml.RX(weights_0, wires=0)
#qml.RX(weight_1, wires=1)
#qml.RY(weight_2, wires=0)
#qml.RY(weight_3, wires=1)
#qml.RZ(weight_4, wires=0)
#qml.RZ(weight_5, wires=1)
qml.RZ(inputs,wires=0)
qml.RZ(inputs,wires=1)
qml.rot(weights_0,weight_1,weight_2,wires=0)
qml.rot(weight_3,weight_4,weight_5,wires=1)
# span all quantum states and create entanglement
qml.CNOT(wires=[0, 1])
# return expectation value as output of QNode
return qml.expval(qml.PauliZ(0))
# creating a dictionary and initializing value for our quantum parameters
weight_shapes = {"weights_0": 1,"weight_1": 1,"weight_2": 1,"weight_3": 1,"weights_4": 1,"weights_5": 1 }
# now create the quantum node in keras
qlayer = qml.qnn.KerasLayer(circuit, weight_shapes, output_dim=1)
# A sequential model with LSTM layer and quantum node as output node
LSTM=keras.layers.LSTM(
units=128,
input_shape=(X_train.shape[1], X_train.shape[2])
)
clayer3=keras.layers.Dense(units=1)
model = tf.keras.models.Sequential([LSTM, qlayer, clayer3])
# Compile model and choose cost function/optimizer
model.compile(
loss='mean_squared_error',
optimizer=keras.optimizers.Adam(0.001)
)
model.summary()
print(X_train.shape[1])
# training model and choosing hyperparameters of training process
history = model.fit(
X_train, y_train,
epochs=30,
batch_size=16,
validation_split=0.1,
verbose=1,
shuffle=False
)