Hello! I am having trouble passing my ‘keras tensor’ into qnode. Here is the code:
#this is the input to quantum node
n_qubits = 8
n_layers = 1
dev = qml.device("default.qubit", wires=n_qubits)
tf.keras.backend.set_floatx('float32')
@qml.qnode(dev, interface = 'tf')
def circuit(inputs):
qml.AmplitudeEmbedding(features=inputs, wires=range(8), pad_with=0., normalize=True)
qml.AngleEmbedding(inputs, wires=range(n_qubits))
return qml.expval(qml.PauliZ(0))
#As my input is large, I am flattening it and taking part of input (p1[0]) to see if it works
a_cl = Flatten()(cl_input) # 'cl_input' is of type <keras tensor> & has shape (None, 73,128) ---> 'a_cl' is of type <keras tensor> & has shape (None, 73*128)
p1 = tf.split(a, num_or_size_splits=128, axis = -1)
q_input = p1[0] #<keras tensor> & has shape (None, 73)
q_out = circuit(q_input)
I am facing the following error:
File “C:\Users\vaishnavi.chandilkar\Downloads\MolNet-2\model\model.py”, line 166, in model_molnet
q_out = circuit(q_input)
File “C:\Users\vaishnavi.chandilkar\Anaconda3\envs\maus\lib\site-packages\pennylane\qnode.py”, line 800, in call
self.construct(args, kwargs)
File “C:\Users\vaishnavi.chandilkar\Anaconda3\envs\maus\lib\site-packages\pennylane\qnode.py”, line 711, in construct
self._tape = make_qscript(self.func)(*args, **kwargs)
File “C:\Users\vaishnavi.chandilkar\Anaconda3\envs\maus\lib\site-packages\pennylane\tape\qscript.py”, line 1346, in wrapper
result = fn(*args, **kwargs)
File “C:\Users\vaishnavi.chandilkar\Downloads\MolNet-2\model\model.py”, line 136, in circuit
qml.AmplitudeEmbedding(features=inputs, wires=range(8), pad_with=0., normalize=True)
File “C:\Users\vaishnavi.chandilkar\Anaconda3\envs\maus\lib\site-packages\pennylane\templates\embeddings\amplitude.py”, line 129, in init
features = self._preprocess(features, wires, pad_with, normalize)
File “C:\Users\vaishnavi.chandilkar\Anaconda3\envs\maus\lib\site-packages\pennylane\templates\embeddings\amplitude.py”, line 180, in _preprocess
batched = qml.math.ndim(features) > 1
File “C:\Users\vaishnavi.chandilkar\Anaconda3\envs\maus\lib\site-packages\autoray\autoray.py”, line 79, in do
return get_lib_fn(backend, fn)(*args, **kwargs)
File “C:\Users\vaishnavi.chandilkar\Anaconda3\envs\maus\lib\site-packages\autoray\autoray.py”, line 433, in get_lib_fn
lib_fn = import_lib_fn(backend, fn)
File “C:\Users\vaishnavi.chandilkar\Anaconda3\envs\maus\lib\site-packages\autoray\autoray.py”, line 406, in import_lib_fn
raise ImportError(
ImportError: autoray couldn’t find function ‘ndim’ for backend ‘keras’.
Why does qnode not take keras tensor? Can anyone tell me which type should i convert my data to , so that it works fine!?