PaddlePaddle / Quantum

Other
567 stars 176 forks source link

Importing `paddle_quantum` generates warnings that can't be silenced #45

Closed vtomole closed 1 year ago

vtomole commented 1 year ago

I have a file test.py that contains

import warnings
warnings.filterwarnings("ignore")

import sys
print(sys.version)
from importlib.metadata import version
print(f"PaddlePaddle version {version('paddlepaddle')}") 
print(f"Paddle quantum version {version('paddle_quantum')}")

import paddle

Running python test.py outputs

3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0]
PaddlePaddle version 2.4.0rc0
Paddle quantum version 2.3.0
/home/victory/paddle_quantum_venv/lib/python3.10/site-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API
  warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)
/home/victory/paddle_quantum_venv/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
/home/victory/paddle_quantum_venv/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google.logging')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
/home/victory/paddle_quantum_venv/lib/python3.10/site-packages/pkg_resources/__init__.py:2349: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(parent)
/home/victory/paddle_quantum_venv/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)

These warnings should not be here.

LeiZhang-116-4 commented 1 year ago

Hi there. I guess these warnings have something to do with your device or anaconda environment. For me, following the installation guide of Paddle Quantum (except for Python being 3.10 not 3.8), your codes in my Mac with M1 chip generate below output without warnings:

3.10.11 (main, Apr 20 2023, 13:59:00) [Clang 14.0.6 ]
PaddlePaddle version 2.3.0
Paddle quantum version 2.4.0

You may need to specific more details for us to provide further possible assistance.

PS: Yet, Paddle Quantum does output some deprecation warnings that cannot be easily igonored. Specifically, the code

import paddle_quantum

will generate three deprecation warnings raised between openfermion and scipy, and between paddle and numpy. This is a known problem and will be silenced in future updates.

PPS: Since Paddle Quantum requires dependencies that may potentially constitute conflicts, Paddle Quantum fixs its Python version as 3.8. Although Paddle Quantum has been tested to work well for Python 3.7 and higher, it is recommended to use Paddle Quantum in Python 3.8 for stability.

vtomole commented 1 year ago

When i install the paddle and paddle quantum versions you have i get

3.8.16 (default, Dec  7 2022, 01:12:06) 
[GCC 11.3.0]
PaddlePaddle version 2.3.0
Paddle quantum version 2.4.0
Error: Can not import avx core while this file exists: /home/victory/paddle_quantum_venv/lib/python3.8/site-packages/paddle/fluid/core_avx.so
Traceback (most recent call last):
  File "test.py", line 10, in <module>
    import paddle
  File "/home/victory/paddle_quantum_venv/lib/python3.8/site-packages/paddle/__init__.py", line 25, in <module>
    from .framework import monkey_patch_variable
  File "/home/victory/paddle_quantum_venv/lib/python3.8/site-packages/paddle/framework/__init__.py", line 17, in <module>
    from . import random  # noqa: F401
  File "/home/victory/paddle_quantum_venv/lib/python3.8/site-packages/paddle/framework/random.py", line 16, in <module>
    import paddle.fluid as fluid
  File "/home/victory/paddle_quantum_venv/lib/python3.8/site-packages/paddle/fluid/__init__.py", line 36, in <module>
    from . import framework
  File "/home/victory/paddle_quantum_venv/lib/python3.8/site-packages/paddle/fluid/framework.py", line 37, in <module>
    from . import core
  File "/home/victory/paddle_quantum_venv/lib/python3.8/site-packages/paddle/fluid/core.py", line 298, in <module>
    raise e
  File "/home/victory/paddle_quantum_venv/lib/python3.8/site-packages/paddle/fluid/core.py", line 256, in <module>
    from . import core_avx
ImportError: /home/victory/paddle_quantum_venv/lib/python3.8/site-packages/paddle/fluid/core_avx.so: undefined symbol: _dl_sym, version GLIBC_PRIVATE

Could it be because my system uses GCC instead of Clang?

Do you know why is paddle using pkg_resources? It's been deprecated for a while: https://setuptools.pypa.io/en/latest/pkg_resources.html

LeiZhang-116-4 commented 1 year ago

I searched and then believe this problem is related to the version of your Linux system. The error outputs in the following two posts are identical to those in yours:

  1. Compiled version of Paddle doesn't work with Ubuntu 21.10
  2. core_avx.so: undefined symbol: _dl_sym, version GLIBC_PRIVATE
vtomole commented 1 year ago

Thanks for the references. I ran pip install paddlepaddle==2.4.0rc0 as was recommended and the error went away. With regards to the warnings, that's due to https://github.com/pypa/setuptools/issues/3878. I've confirm that pip install "setuptools<=67.2.0" gets rid of all the warnings without me having to silence them.