Hi. I am trying to run a hybrid model with Pennylane and Tensorflow. The model runs fine when I return:
return qml.expval(sum([qml.pauli.string_to_pauli_word(j) for i, j in enumerate(pauli_strings)]))
However, as soon as I introduce parameters in the measurement operator like this:
return [qml.expval(params_measurement[i] * qml.pauli.string_to_pauli_word(j)) for i, j in enumerate(pauli_strings)]
running the code gives out the following error:
in user code:
File "/qcfs/bravo/.virtualenvs/qml/lib/python3.10/site-packages/pennylane/workflow/qnode.py", line 1002, in __call__ *
self.construct(args, kwargs)
File "/qcfs/bravo/.virtualenvs/qml/lib/python3.10/site-packages/pennylane/workflow/qnode.py", line 888, in construct *
self._qfunc_output = self.func(*args, **kwargs)
File "/tmp/ipykernel_647449/1711710577.py", line 44, in circuit *
return [qml.expval(params_measurement[i] * qml.pauli.string_to_pauli_word(j)) for i, j in enumerate(pauli_strings)]
File "/qcfs/bravo/.virtualenvs/qml/lib/python3.10/site-packages/pennylane/measurements/expval.py", line 71, in expval *
if not op.is_hermitian:
File "/qcfs/bravo/.virtualenvs/qml/lib/python3.10/site-packages/pennylane/ops/op_math/sprod.py", line 203, in is_hermitian
return self.base.is_hermitian and not qml.math.iscomplex(self.scalar)
OperatorNotAllowedInGraphError: Using a symbolic `tf.Tensor` as a Python `bool` is not allowed: AutoGraph did convert this function. This might indicate you are trying to use an unsupported feature.
Call arguments received by layer "keras_layer_1" " f"(type KerasLayer):
• inputs=tf.Tensor(shape=(16, 4), dtype=float32)
Is this a limitation of qml.qnn.KerasLayer
?
The runnable code is attached, but i cannot share the dataset. You can use MNIST for the same purpose, it deals with grayscale images.
qccnn_trainable_measurement_dummy.py (6.3 KB)
qml.about()
:
Name: PennyLane
Version: 0.35.0
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: https://github.com/PennyLaneAI/pennylane
Author:
Author-email:
License: Apache License 2.0
Location: /qcfs/bravo/.virtualenvs/qml/lib/python3.10/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-v
[qccnn_trainable_measurement_dummy.py|attachment](upload://rxT1wWN85y2Nw9iLa1CH4y3JE9B.py) (6.4 KB)
ersion, toml, typing-extensions
Required-by: PennyLane-Cirq, PennyLane-qiskit, PennyLane_Lightning, PennyLane_Lightning_GPU
Platform info: Linux-5.15.0-105-generic-x86_64-with-glibc2.35
Python version: 3.10.12
Numpy version: 1.23.5
Scipy version: 1.11.3
Installed devices:
- cirq.mixedsimulator (PennyLane-Cirq-0.34.0)
- cirq.pasqal (PennyLane-Cirq-0.34.0)
- cirq.qsim (PennyLane-Cirq-0.34.0)
- cirq.qsimh (PennyLane-Cirq-0.34.0)
- cirq.simulator (PennyLane-Cirq-0.34.0)
- lightning.qubit (PennyLane_Lightning-0.35.0)
- default.clifford (PennyLane-0.35.0)
- default.gaussian (PennyLane-0.35.0)
- default.mixed (PennyLane-0.35.0)
- default.qubit (PennyLane-0.35.0)
- default.qubit.autograd (PennyLane-0.35.0)
- default.qubit.jax (PennyLane-0.35.0)
- default.qubit.legacy (PennyLane-0.35.0)
- default.qubit.tf (PennyLane-0.35.0)
- default.qubit.torch (PennyLane-0.35.0)
- default.qutrit (PennyLane-0.35.0)
- null.qubit (PennyLane-0.35.0)
- lightning.gpu (PennyLane_Lightning_GPU-0.35.0)
- qiskit.aer (PennyLane-qiskit-0.35.1)
- qiskit.basicaer (PennyLane-qiskit-0.35.1)
- qiskit.ibmq (PennyLane-qiskit-0.35.1)
- qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.35.1)
- qiskit.ibmq.sampler (PennyLane-qiskit-0.35.1)
- qiskit.remote (PennyLane-qiskit-0.35.1)