# Sympy suddently does not work together with TFQ

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.

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) .