I work with tensorflow-quantum and use sympy for parameter updating.

Suddenly, without (manually) updating or changing anything this error comes up:

  File "/home/eli/anaconda3/lib/python3.8/site-packages/tensorflow_quantum/core/serialize/serializer.py", line 93, in _symbol_extractor
    if isinstance(expr, sympy.mul.Mul):

AttributeError: module 'sympy' has no attribute 'mul'

Has anyone had this before? Do you have any suggestions for what I can try to fix this?

I am working on Ubuntu 20.04.2 LTS TFQ version 0.4.0 Sympy version 1.8

the error occurs when I build my PQC layer:

model = tf.keras.Sequential([tf.keras.layers.Input(shape=(), dtype=tf.string), 
                        tfq.layers.PQC(circuit, [cirq.Z(q) for q in builder.get_valid_outputs()]),
                        ], name = model_type)

and it worked like this a long time.


2 Answers 2


Just to add a little more context to your answer: TensorFlow-Quantum 0.4.0 has an explicit version dependency on sympy==1.5.0 in the setup.py module here, which should have been installed when you first installed TFQ. It's possible that other python pip packages may have overriden or upgraded the sympy version since then. Using something like pip list | grep sympy will show which version of sympy you have installed in case you see breakages like this going forward with sympy (or other packages + dependencies) .

Also one final note: TensorFlow Quantum 0.5.0 has been released and does also depend on sympy==1.5.0 which you can see here .


I managed to get it working with a downgrade of sympy to version 1.6.1 It seems that tfq 0.4.0 needs that corresponding version to work properly


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.