tensorflow / quantum

Hybrid Quantum-Classical Machine Learning in TensorFlow
https://www.tensorflow.org/quantum
Apache License 2.0
1.79k stars 574 forks source link

Arithmetic expression outside of simple scalar multiplication is currently not supported. #693

Open Gopal-Dahale opened 2 years ago

Gopal-Dahale commented 2 years ago

I created a parameterized circuit using Cirq for Amplitude Encoding as described in Supervised Learning with Quantum Computers. The parameter is an arithmetic expression involving multiple operations like division and squaring. Below is the formula used. This value is used inside the $Ry$ gate.

$$\beta{j}^{g}=2 \arcsin \left(\frac{\sqrt{\sum{l=1}^{2 g-1}\left|A{(2 j-1) 2^{g-1}+l}\right|^{2}}}{\sqrt{\sum{l=1}^{2 g}\left|A_{(j-1) 2^{g}+l}\right|^{2}}}\right).$$

Using the circuit in the tfq.layers.ControlledPQC gives the following error.

ValueError: Arithmetic expression outside of simple scalar multiplication is currently not supported. 
See serializer.py for more information.

Any hack for this?

lockwo commented 2 years ago

Hard to say the best solution without seeing the exact code causing you trouble. But based on the error I would guess you are doing some disallowed symbol operations and that it could probably be done in a custom layer. I recommend https://github.com/tensorflow/quantum/issues/565 which had the same problem/error

lockwo commented 2 years ago

Any updates on this or should it be closed?