Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tensorflow_probability.python.math conflicts with built-in math library. #179

Closed
kdexd opened this issue Oct 4, 2018 · 5 comments
Closed

Comments

@kdexd
Copy link

kdexd commented Oct 4, 2018

I tried to run the tests with this command:

bazel test --copt=-O3 --copt=-march=native //tensorflow_probability/...

They fail, at //tensorflow_probability/python:monte_carlo_test and the reason is existence of math module in that directory.

Full traceback

INFO: Analysed 363 targets (0 packages loaded).
INFO: Found 198 targets and 165 test targets...
FAIL: //tensorflow_probability/python:monte_carlo_test (see /home/kd/.cache/bazel/_bazel_kd/64170ef834acdab167cc5568fb8ed49c/execroot/tensorflow_probability/bazel-out/k8-fastbuild/testlogs/tensorflow_probability/python/monte_carlo_test/test.log)
INFO: From Testing //tensorflow_probability/python:monte_carlo_test:
==================== Test output for //tensorflow_probability/python:monte_carlo_test:
ImportError: numpy.core.multiarray failed to import
ImportError: numpy.core.multiarray failed to import
ImportError: numpy.core.umath failed to import
ImportError: numpy.core.umath failed to import
Traceback (most recent call last):
  File "/home/kd/.cache/bazel/_bazel_kd/64170ef834acdab167cc5568fb8ed49c/sandbox/linux-sandbox/28/execroot/tensorflow_probability/bazel-out/k8-fastbuild/bin/tensorflow_probability/python/monte_carlo_test.runfiles/tensorflow_probability/tensorflow_probability/python/monte_carlo_test.py", line 22, in <module>
    import numpy as np
  File "/home/kd/Documents/miniconda3/lib/python3.6/site-packages/numpy/__init__.py", line 142, in <module>
    from . import add_newdocs
  File "/home/kd/Documents/miniconda3/lib/python3.6/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/home/kd/Documents/miniconda3/lib/python3.6/site-packages/numpy/lib/__init__.py", line 3, in <module>
    import math
  File "/home/kd/Documents/probability/tensorflow_probability/python/math/__init__.py", line 21, in <module>
    from tensorflow_probability.python.math.custom_gradient import custom_gradient
  File "/home/kd/.cache/bazel/_bazel_kd/64170ef834acdab167cc5568fb8ed49c/sandbox/linux-sandbox/28/execroot/tensorflow_probability/bazel-out/k8-fastbuild/bin/tensorflow_probability/python/monte_carlo_test.runfiles/tensorflow_probability/tensorflow_probability/__init__.py", line 21, in <module>
    from tensorflow_probability.python import *  # pylint: disable=wildcard-import
  File "/home/kd/.cache/bazel/_bazel_kd/64170ef834acdab167cc5568fb8ed49c/sandbox/linux-sandbox/28/execroot/tensorflow_probability/bazel-out/k8-fastbuild/bin/tensorflow_probability/python/monte_carlo_test.runfiles/tensorflow_probability/tensorflow_probability/python/__init__.py", line 21, in <module>
    from tensorflow_probability.python import bijectors
  File "/home/kd/.cache/bazel/_bazel_kd/64170ef834acdab167cc5568fb8ed49c/sandbox/linux-sandbox/28/execroot/tensorflow_probability/bazel-out/k8-fastbuild/bin/tensorflow_probability/python/monte_carlo_test.runfiles/tensorflow_probability/tensorflow_probability/python/bijectors/__init__.py", line 23, in <module>
    from tensorflow_probability.python.bijectors.absolute_value import AbsoluteValue
  File "/home/kd/.cache/bazel/_bazel_kd/64170ef834acdab167cc5568fb8ed49c/sandbox/linux-sandbox/28/execroot/tensorflow_probability/bazel-out/k8-fastbuild/bin/tensorflow_probability/python/monte_carlo_test.runfiles/tensorflow_probability/tensorflow_probability/python/bijectors/absolute_value.py", line 21, in <module>
    import tensorflow as tf
  File "/home/kd/.local/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/home/kd/.local/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 70, in <module>
    from tensorflow.python.framework.framework_lib import *  # pylint: disable=redefined-builtin
  File "/home/kd/.local/lib/python3.6/site-packages/tensorflow/python/framework/framework_lib.py", line 25, in <module>
    from tensorflow.python.framework.ops import Graph
  File "/home/kd/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 39, in <module>
    from tensorflow.python.eager import context
  File "/home/kd/.local/lib/python3.6/site-packages/tensorflow/python/eager/context.py", line 24, in <module>
    import random
  File "/home/kd/Documents/miniconda3/lib/python3.6/random.py", line 42, in <module>
    from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
ImportError: cannot import name 'log'
================================================================================

More Proof

I added these lines in tensorflow_probability/python/math/__init__.py:

import math
log = math.log

And on executing the same command, the tests fail and I get:

AttributeError: module 'math' has no attribute 'log'

This definitely looks like a name conflict.

References

Exact same error here: https://ubuntuforums.org/showthread.php?t=897043

@kdexd
Copy link
Author

kdexd commented Oct 4, 2018

I am using Ubuntu 17.10, Python 3.6.4 and GCC 7.2.0, Bazel 0.17.2 and bleeding edge of this repo.

@csuter
Copy link
Member

csuter commented Oct 5, 2018

Hi @kdexd, can you share the output of pip list?

@kdexd
Copy link
Author

kdexd commented Oct 6, 2018

Package                Version            Location                          
---------------------- ------------------ ----------------------------------
absl-py                0.5.0              
asgiref                2.3.0              
asn1crypto             0.24.0             
astor                  0.7.1              
async-timeout          2.0.1              
atomicwrites           1.1.5              
attrs                  17.4.0             
autobahn               18.4.1             
Automat                0.6.0              
autopep8               1.3.5              
backcall               0.1.0              
bleach                 2.1.4              
certifi                2018.4.16          
cffi                   1.11.5             
channels               0.17.2             
chardet                3.0.4              
cloudpickle            0.5.3              
conda                  4.5.8              
constantly             15.1.0             
cryptography           2.1.4              
cycler                 0.10.0             
Cython                 0.28.3             
daphne                 2.1.1              
dask                   0.18.1             
dbus-python            1.2.8              
decorator              4.3.0              
defusedxml             0.5.0              
Django                 1.10               
docopt                 0.6.2              
entrypoints            0.2.3              
future                 0.16.0             
gast                   0.2.0              
grpcio                 1.15.0             
gym                    0.10.5             
h5py                   2.7.1              
html5lib               1.0.1              
hyperlink              18.0.0             
idna                   2.6                
ignite                 1.1.0              
incremental            17.5.0             
ipykernel              4.9.0              
ipython                6.4.0              
ipython-genutils       0.2.0              
jedi                   0.12.0             
Jinja2                 2.10               
jsonpickle             0.9.6              
jsonschema             2.6.0              
jupyter-client         5.2.3              
jupyter-console        5.2.0              
jupyter-core           4.4.0              
jupyterlab             0.34.10            
jupyterlab-launcher    0.13.1             
Keras-Applications     1.0.6              
Keras-Preprocessing    1.0.5              
kiwisolver             1.0.1              
Markdown               3.0.1              
MarkupSafe             1.0                
matplotlib             2.2.2              
mccabe                 0.6.1              
mistune                0.8.3              
mkl-fft                1.0.0              
mkl-random             1.0.1              
more-itertools         4.2.0              
munch                  2.3.2              
nbconvert              5.4.0              
nbformat               4.4.0              
networkx               2.1                
nltk                   3.2.5              
notebook               5.6.0              
numexpr                2.6.4              
numpy                  1.15.2             
olefile                0.45.1             
pandas                 0.23.4             
pandocfilters          1.4.2              
parso                  0.2.1              
pexpect                4.6.0              
pickleshare            0.7.4              
Pillow                 5.1.0              
pip                    18.0               
pluggy                 0.6.0              
prometheus-client      0.3.1              
prompt-toolkit         1.0.15             
protobuf               3.6.1              
ptyprocess             0.5.2              
py                     1.5.4              
py-cpuinfo             4.0.0              
pycocotools            2.0.0              
pycodestyle            2.4.0              
pycosat                0.6.3              
pycparser              2.18               
pydocstyle             2.1.1              
pyflakes               2.0.0              
pyglet                 1.3.2              
Pygments               2.2.0              
pyinotify              0.9.6              
pyoitools              0.1.0              /home/kd/Documents/open-images-api
pyOpenSSL              17.5.0             
pyparsing              2.2.0              
pyperclip              1.7.0              
PySocks                1.6.7              
pytest                 3.6.3              
python-dateutil        2.7.3              
python-igraph          0.7.1.post6        
python-language-server 0.19.0             
python3-xlib           0.15               
pytz                   2018.4             
PyWavelets             0.5.2              
PyYAML                 3.12               
pyzmq                  17.1.2             
QtPy                   1.4.0              
requests               2.18.4             
rope                   0.11.0             
ruamel-yaml            0.15.35            
scikit-image           0.14.0             
scikit-learn           0.20.0             
scipy                  1.1.0              
seaborn                0.9.0              
Send2Trash             1.5.0              
setuptools             39.0.1             
simplegeneric          0.8.1              
six                    1.11.0             
sklearn                0.0                
snowballstemmer        1.2.1              
tables                 3.4.2              
tb-nightly             1.12.0a20181004    
termcolor              1.1.0              
terminado              0.8.1              
testpath               0.3.1              
tf-nightly             1.12.0.dev20181004 
tfp-nightly            0.5.0.dev20181004  
toolz                  0.9.0              
torch                  0.4.1              
torchtext              0.2.3              
torchvision            0.2.1              
tornado                5.1                
tqdm                   4.23.4             
traitlets              4.3.2              
Twisted                17.9.0             
txaio                  2.10.0             
typing                 3.6.4              
urllib3                1.22               
wcwidth                0.1.7              
webencodings           0.5.1              
Werkzeug               0.14.1             
wheel                  0.30.0             
wrapt                  1.10.11            
yapf                   0.22.0             
zope.interface         4.4.3      

@csuter
Copy link
Member

csuter commented Oct 10, 2018

Hi @kdexd, I have been unable to reproduce this. In each case, I'm running in a freshly created virtualenv with tf-nightly and other test dependencies (scipy, hypothesis, matplotlib) installed. I have tested with pythons 2.7, 3.5, and 3.6. In all cases, all tests pass.

Is there something else in your setup that might be different?

@kdexd kdexd closed this as completed Oct 17, 2018
@kdexd
Copy link
Author

kdexd commented Oct 17, 2018

Wow, it just worked for me. I don't exactly know what was wrong before. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants