tensorflow/quantum

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

Gopal-Dahale opened this issue · 3 comments

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?

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 #565 which had the same problem/error

Any updates on this or should it be closed?