tensorflow / quantum

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

Trouble importing `tensorflow_quantum` #777

Closed hchalfin closed 1 year ago

hchalfin commented 1 year ago

I believe my issue may be similar to #771, which doesn't look like it has been resolved yet.

I am trying to install and use tensorflow-quantum but am having no luck. (For reference, I am using MacOS Ventura 13.4) Thus far, I have tried a variety of methods, none of which have worked.

Method 1: Pip package (my preferred method)

I set up and activate a virtual environment tfqenv and then followed the website instructions as closely as possible. I ran the following commands:

pip3 install --upgrade pip pip3 install tensorflow==2.11.0 pip3 install -U tensorflow-quantum

My error message is in the screenshots below. It appears there is some issue with the file _tfq_simulate_ops.so. Namely, the symbol __ZN10tensorflow12OpDefBuilder10SetShapeFnENSt3__18functionIFNS_6StatusEPNS_15shape_inference16InferenceContextEEEE cannot be found.

err_msg_screenshot_#1 err_msg_screenshot_#2 err_msg_screenshot_#3 err_msg_screenshot_#4

For reference, here are the package versions installed in my environment:

pip_list_screenshot_#1 pip_list_screenshot_#2 pip_list_screenshot_#3 pip_list_screenshot_#4 pip_list_screenshot_#5

As you can see, I am using tensorflow=2.11.0 and tensorflow-quantum=0.7.2.

Also, I am using Python version 3.8.3:

python_version_screenshot

Considering that it seems like others may have encountered similar issues recently, I am wondering if TFQ is in need of an upgrade. It looks like it hasn't been updated since July 2022.

I will post my questions about the other two methods I've tried soon. But for now, this pip package method is the one I care most about.

lockwo commented 1 year ago

The _ZN10tensor sort of error has come up multiple times, not just https://github.com/tensorflow/quantum/issues/771 but the linked issues in my responses, https://github.com/tensorflow/quantum/issues/602, https://github.com/tensorflow/quantum/issues/714, https://github.com/tensorflow/quantum/issues/180, https://github.com/tensorflow/quantum/issues/711. The solution in those cases would appear to be the same solution here. This is usually the result of a version mismatch, make sure to check the version of the associated release (since you are not installing the nightly build), TFQ 0.7.2 has TF 2.7.0 as a requirement, not 2.11 (https://github.com/tensorflow/quantum/compare/v0.7.2...master#diff-4d7c51b1efe9043e44439a949dfd92e5827321b34082903477fd04876edb7552L8). The full list of requirements is:

cirq-core==0.13.1
cirq-google==0.13.1
sympy==1.8
numpy==1.19.5  # TensorFlow can detect if it was built against other versions.
nbformat==4.4.0
pylint==2.4.4
yapf==0.28.0
tensorflow==2.7.0
# Needed for compatibility with cirq program protos.
googleapis-common-protos==1.52.0
google-api-core==1.21.0
google-auth==1.18.0
google-api-python-client==1.8.0
grpcio==1.34.1
protobuf==3.17.3

With python3.8 and a branch new environment, I can install using pip and run with no problems with TF 2.7:

Screenshot 2023-06-07 at 4 47 53 PM
hchalfin commented 1 year ago

I have implemented your suggested solution and, at least thus far, everything appears to be working very smoothly. I am feeling delighted. Thank you so much!

It turns out that sharing my questions about the two other methods would be little more than a moot point at this stage.

fabiosanger commented 7 months ago

the issue still persist, solution to install tf 2.7.0