sagemath / sage

Main repository of SageMath. Now open for Issues and Pull Requests.
https://www.sagemath.org
Other
1.08k stars 394 forks source link

RuntimeWarning: networkx backend defined more than once: nx-loopback #37863

Open mkoeppe opened 2 weeks ago

mkoeppe commented 2 weeks ago

Seen in portability tests for Redhat-like systems, such as almalinux-8-python3.9-minimal https://github.com/mkoeppe/sage/actions/runs/8761823524/job/24053541285#step:11:4182

sage -t --random-seed=135671911764218086922490879021813737906 src/doc/en/thematic_tutorials/sandpile.rst
#25 608.2 **********************************************************************
#25 608.2 File "src/doc/en/thematic_tutorials/sandpile.rst", line 851, in doc.en.thematic_tutorials.sandpile
#25 608.2 Failed example:
#25 608.2     S = Sandpile(digraphs.RandomDirectedGNC(6), 0)
#25 608.2 Expected nothing
#25 608.2 Got:
#25 608.2     doctest:warning
#25 608.2       File "<doctest doc.en.thematic_tutorials.sandpile[98]>", line 1, in <module>
#25 608.2         S = Sandpile(digraphs.RandomDirectedGNC(Integer(6)), Integer(0))
#25 608.2       File "/sage/src/sage/graphs/digraph_generators.py", line 1421, in RandomDirectedGNC
#25 608.2         import networkx
#25 608.2       File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
#25 608.2       File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
#25 608.2       File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
#25 608.2       File "<frozen importlib._bootstrap_external>", line 850, in exec_module
#25 608.2       File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
#25 608.2       File "/sage/local/var/lib/sage/venv-python3.9/lib64/python3.9/site-packages/networkx/__init__.py", line 20, in <module>
#25 608.2         from networkx.utils.backends import _dispatch
#25 608.2       File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
#25 608.2       File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
#25 608.2       File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
#25 608.2       File "<frozen importlib._bootstrap_external>", line 850, in exec_module
#25 608.2       File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
#25 608.2       File "/sage/local/var/lib/sage/venv-python3.9/lib64/python3.9/site-packages/networkx/utils/backends.py", line 135, in <module>
#25 608.2         backends.update(_get_backends("networkx.backends"))
#25 608.2       File "/sage/local/var/lib/sage/venv-python3.9/lib64/python3.9/site-packages/networkx/utils/backends.py", line 110, in _get_backends
#25 608.2         warnings.warn(
#25 608.2       File "/usr/lib64/python3.9/warnings.py", line 109, in _showwarnmsg
#25 608.2         sw(msg.message, msg.category, msg.filename, msg.lineno,
#25 608.2     :
#25 608.2     RuntimeWarning: networkx backend defined more than once: nx-loopback
dcoudert commented 2 weeks ago

This has already been reported to networkx: https://github.com/networkx/networkx/issues/7101 Apparently only happens with Python 3.9.

mkoeppe commented 2 weeks ago

Shall we suppress the warnings as suggested in https://github.com/networkx/networkx/issues/7101#issuecomment-1919737867?

dcoudert commented 2 weeks ago

The proposed method suppress the warning independently of the version of Python. Isn't it risky ? Also, we will have to remember to remove that code as soon as we will stop supporting Python 3.9.

mkoeppe commented 2 weeks ago

I don't know the details, but it does not seem that whatever it is that this warning is warning about has any effect on networkx's correct functioning.

dcoudert commented 2 weeks ago

Indeed, if it's only a small warning without effect on the correct functioning, we can erase it. We just have to make sure that we will remember to remove the added code when it will no longer be necessary.

mkoeppe commented 2 weeks ago

I'll prepare a PR and make sure to include "Python 3.9" in a comment so that we find it when we drop support for that version.