pymc-devs / pymc

Bayesian Modeling and Probabilistic Programming in Python
https://docs.pymc.io/
Other
8.71k stars 2.01k forks source link

pm.model_to_graphviz doesn't connect predicted likelihood to observed data if observed data is comprised entirely of ints. #6019

Closed StuartNg closed 2 years ago

StuartNg commented 2 years ago

Description of your problem

pm.model_to_graphviz fails to connect the final prediction 'obs' to the observed data if that observed data contains entirely int or np.int types.

Please provide a minimal, self-contained, and reproducible example.

test1 = [10, 20, 30, 40, 50]
test2 = [10.1, 20, 30, 40, 50]
print(type(test1[0]), type(test2[0]))

# Using test1 as the observed data
with pm.Model() as model:
    data = pm.Data("data", test1)
    eps = pm.Normal("eps", mu=0, sigma=1)
    mu = pm.Normal("mu", mu=0, sigma=1)
    obs = pm.Normal("obs", mu=mu, sigma=eps, observed=data)

pm.model_to_graphviz(model)

# Using test 2 as the observed data
with pm.Model() as model:
    data = pm.Data("data", test2)
    eps = pm.Normal("eps", mu=0, sigma=1)
    mu = pm.Normal("mu", mu=0, sigma=1)
    obs = pm.Normal("obs", mu=mu, sigma=eps, observed=data)

pm.model_to_graphviz(model)

Using test1 image Using test2 image

Versions and main components

Results from conda list Name Version Build Channel aeppl 0.0.32 pyhd8ed1ab_0 conda-forge aeppl-base 0.0.32 pyhd8ed1ab_0 conda-forge aesara 2.7.7 py310hfa0c5ed_0 conda-forge aesara-base 2.7.7 py310h5588dad_0 conda-forge arviz 0.12.1 pyhd8ed1ab_1 conda-forge asttokens 2.0.5 pyhd3eb1b0_0 backcall 0.2.0 pyhd3eb1b0_0 blas 2.115 mkl conda-forge blas-devel 3.9.0 15_win64_mkl conda-forge brotli 1.0.9 h8ffe710_7 conda-forge brotli-bin 1.0.9 h8ffe710_7 conda-forge bzip2 1.0.8 h8ffe710_4 conda-forge ca-certificates 2022.6.15 h5b45459_0 conda-forge cachetools 5.0.0 pyhd8ed1ab_0 conda-forge cairo 1.16.0 h0ac17fb_1011 conda-forge certifi 2022.6.15 py310h5588dad_0 conda-forge cftime 1.6.1 py310h2873277_0 conda-forge cloudpickle 2.1.0 pyhd8ed1ab_0 conda-forge colorama 0.4.5 py310haa95532_0 cons 0.4.5 pyhd8ed1ab_0 conda-forge curl 7.83.1 h789b8ee_0 conda-forge cycler 0.11.0 pyhd8ed1ab_0 conda-forge debugpy 1.5.1 py310hd77b12b_0 decorator 5.1.1 pyhd3eb1b0_0 entrypoints 0.4 py310haa95532_0 etuples 0.3.5 pyhd8ed1ab_0 conda-forge executing 0.8.3 pyhd3eb1b0_0 expat 2.4.8 h39d44d4_0 conda-forge fastprogress 1.0.3 pyhd8ed1ab_0 conda-forge filelock 3.7.1 pyhd8ed1ab_0 conda-forge font-ttf-dejavu-sans-mono 2.37 hab24e00_0 conda-forge font-ttf-inconsolata 3.000 h77eed37_0 conda-forge font-ttf-source-code-pro 2.038 h77eed37_0 conda-forge font-ttf-ubuntu 0.83 hab24e00_0 conda-forge fontconfig 2.14.0 hce3cb01_0 conda-forge fonts-conda-ecosystem 1 0 conda-forge fonts-conda-forge 1 0 conda-forge fonttools 4.34.4 py310he2412df_0 conda-forge freetype 2.10.4 h546665d_1 conda-forge fribidi 1.0.10 h8d14728_0 conda-forge getopt-win32 0.1 h8ffe710_0 conda-forge gettext 0.19.8.1 ha2e2712_1008 conda-forge graphite2 1.3.13 1000 conda-forge graphviz 5.0.0 had6c3a3_0 conda-forge gts 0.7.6 h7c369d9_2 conda-forge harfbuzz 4.4.1 h27de254_0 conda-forge hdf4 4.2.15 h0e5069d_3 conda-forge hdf5 1.12.1 nompi_h57737ce_104 conda-forge icu 70.1 h0e60522_0 conda-forge intel-openmp 2022.1.0 h57928b3_3787 conda-forge ipykernel 6.9.1 py310haa95532_0 ipython 8.4.0 py310haa95532_0 jedi 0.18.1 py310haa95532_1 jpeg 9e h8ffe710_2 conda-forge jupyter_client 7.2.2 py310haa95532_0 jupyter_core 4.10.0 py310haa95532_0 kiwisolver 1.4.4 py310h476a331_0 conda-forge krb5 1.19.3 hc8ab02b_0 conda-forge lcms2 2.12 h2a16943_0 conda-forge lerc 3.0 h0e60522_0 conda-forge libblas 3.9.0 15_win64_mkl conda-forge libbrotlicommon 1.0.9 h8ffe710_7 conda-forge libbrotlidec 1.0.9 h8ffe710_7 conda-forge libbrotlienc 1.0.9 h8ffe710_7 conda-forge libcblas 3.9.0 15_win64_mkl conda-forge libcurl 7.83.1 h789b8ee_0 conda-forge libdeflate 1.12 h8ffe710_0 conda-forge libffi 3.4.2 h8ffe710_5 conda-forge libgd 2.3.3 h891f43f_3 conda-forge libglib 2.72.1 h3be07f2_0 conda-forge libiconv 1.16 he774522_0 conda-forge liblapack 3.9.0 15_win64_mkl conda-forge liblapacke 3.9.0 15_win64_mkl conda-forge libnetcdf 4.8.1 nompi_h1cc8e9d_102 conda-forge libpng 1.6.37 h1d00b33_3 conda-forge libpython 2.2 py310h5588dad_1 conda-forge libsodium 1.0.18 h62dcd97_0 libssh2 1.10.0 h9a1e1f7_2 conda-forge libtiff 4.4.0 h2ed3b44_1 conda-forge libwebp 1.2.3 h8ffe710_1 conda-forge libwebp-base 1.2.3 h8ffe710_2 conda-forge libxcb 1.13 hcd874cb_1004 conda-forge libzip 1.9.2 h519de47_0 conda-forge libzlib 1.2.12 h8ffe710_2 conda-forge logical-unification 0.4.5 pyhd8ed1ab_0 conda-forge lz4-c 1.9.3 h8ffe710_1 conda-forge m2w64-binutils 2.25.1 5 conda-forge m2w64-bzip2 1.0.6 6 conda-forge m2w64-crt-git 5.0.0.4636.2595836 2 conda-forge m2w64-gcc 5.3.0 6 conda-forge m2w64-gcc-ada 5.3.0 6 conda-forge m2w64-gcc-fortran 5.3.0 6 conda-forge m2w64-gcc-libgfortran 5.3.0 6 conda-forge m2w64-gcc-libs 5.3.0 7 conda-forge m2w64-gcc-libs-core 5.3.0 7 conda-forge m2w64-gcc-objc 5.3.0 6 conda-forge m2w64-gmp 6.1.0 2 conda-forge m2w64-headers-git 5.0.0.4636.c0ad18a 2 conda-forge m2w64-isl 0.16.1 2 conda-forge m2w64-libiconv 1.14 6 conda-forge m2w64-libmangle-git 5.0.0.4509.2e5a9a2 2 conda-forge m2w64-libwinpthread-git 5.0.0.4634.697f757 2 conda-forge m2w64-make 4.1.2351.a80a8b8 2 conda-forge m2w64-mpc 1.0.3 3 conda-forge m2w64-mpfr 3.1.4 4 conda-forge m2w64-pkg-config 0.29.1 2 conda-forge m2w64-toolchain 5.3.0 7 conda-forge m2w64-toolchain_win-64 2.4.0 0 conda-forge m2w64-tools-git 5.0.0.4592.90b8472 2 conda-forge m2w64-windows-default-manifest 6.4 3 conda-forge m2w64-winpthreads-git 5.0.0.4634.697f757 2 conda-forge m2w64-zlib 1.2.8 10 conda-forge matplotlib-base 3.5.2 py310h79a7439_0 conda-forge matplotlib-inline 0.1.2 pyhd3eb1b0_2 minikanren 1.0.3 pyhd8ed1ab_0 conda-forge mkl 2022.1.0 h6a75c08_874 conda-forge mkl-devel 2022.1.0 h57928b3_875 conda-forge mkl-include 2022.1.0 h6a75c08_874 conda-forge mkl-service 2.4.0 py310h3d5ec83_0 conda-forge msys2-conda-epoch 20160418 1 conda-forge multipledispatch 0.6.0 py_0 conda-forge munkres 1.1.4 pyh9f0ad1d_0 conda-forge nest-asyncio 1.5.5 py310haa95532_0 netcdf4 1.6.0 nompi_py310h5489b47_100 conda-forge numpy 1.23.1 py310h8a5b91a_0 conda-forge openjpeg 2.4.0 hb211442_1 conda-forge openssl 3.0.5 h8ffe710_0 conda-forge packaging 21.3 pyhd8ed1ab_0 conda-forge pandas 1.4.3 py310hf5e1058_0 conda-forge pango 1.50.8 h66df5b2_0 conda-forge parso 0.8.3 pyhd3eb1b0_0 pcre 8.45 h0e60522_0 conda-forge pickleshare 0.7.5 pyhd3eb1b0_1003 pillow 9.2.0 py310h767b3fd_0 conda-forge pip 22.2 pyhd8ed1ab_0 conda-forge pixman 0.40.0 h8ffe710_0 conda-forge prompt-toolkit 3.0.20 pyhd3eb1b0_0 pthread-stubs 0.4 hcd874cb_1001 conda-forge pure_eval 0.2.2 pyhd3eb1b0_0 pygments 2.11.2 pyhd3eb1b0_0 pymc 4.1.3 py310h5588dad_0 conda-forge pymc-base 4.1.3 py310h5588dad_0 conda-forge pyparsing 3.0.9 pyhd8ed1ab_0 conda-forge python 3.10.5 hcf16a7b_0_cpython conda-forge python-dateutil 2.8.2 pyhd8ed1ab_0 conda-forge python-graphviz 0.20.1 pyh22cad53_0 conda-forge python_abi 3.10 2_cp310 conda-forge pytz 2022.1 pyhd8ed1ab_0 conda-forge pywin32 302 py310h2bbff1b_2 pyzmq 23.2.0 py310hd77b12b_0 scipy 1.8.1 py310h7c00807_2 conda-forge setuptools 63.2.0 py310h5588dad_0 conda-forge six 1.16.0 pyh6c4a22f_0 conda-forge sqlite 3.39.2 h8ffe710_0 conda-forge stack_data 0.2.0 pyhd3eb1b0_0 tbb 2021.5.0 h2d74725_1 conda-forge tk 8.6.12 h8ffe710_0 conda-forge toolz 0.12.0 pyhd8ed1ab_0 conda-forge tornado 6.1 py310h2bbff1b_0 traitlets 5.1.1 pyhd3eb1b0_0 typing-extensions 4.3.0 hd8ed1ab_0 conda-forge typing_extensions 4.3.0 pyha770c72_0 conda-forge tzdata 2022a h191b570_0 conda-forge ucrt 10.0.20348.0 h57928b3_0 conda-forge unicodedata2 14.0.0 py310he2412df_1 conda-forge vc 14.2 hb210afc_6 conda-forge vs2015_runtime 14.29.30037 h902a5da_6 conda-forge wcwidth 0.2.5 pyhd3eb1b0_0 wheel 0.37.1 pyhd8ed1ab_0 conda-forge xarray 2022.6.0 pyhd8ed1ab_1 conda-forge xarray-einstats 0.3.0 pyhd8ed1ab_0 conda-forge xorg-kbproto 1.0.7 hcd874cb_1002 conda-forge xorg-libice 1.0.10 hcd874cb_0 conda-forge xorg-libsm 1.2.3 hcd874cb_1000 conda-forge xorg-libx11 1.7.2 hcd874cb_0 conda-forge xorg-libxau 1.0.9 hcd874cb_0 conda-forge xorg-libxdmcp 1.1.3 hcd874cb_0 conda-forge xorg-libxext 1.3.4 hcd874cb_1 conda-forge xorg-libxpm 3.5.13 hcd874cb_0 conda-forge xorg-libxt 1.2.1 hcd874cb_2 conda-forge xorg-xextproto 7.3.0 hcd874cb_1002 conda-forge xorg-xproto 7.0.31 hcd874cb_1007 conda-forge xz 5.2.5 h62dcd97_1 conda-forge zeromq 4.3.4 hd77b12b_0 zlib 1.2.12 h8ffe710_2 conda-forge zstd 1.5.2 h6255e5f_2 conda-forge

bherwerth commented 2 years ago

I can reproduce the issue with pymc==4.1.3 (from conda-forge). However with pymc==4.1.4 (from pypi), the graph renders as expected.

Looks like PR #6011 solved this issue.

canyon289 commented 2 years ago

it sure did! Thanks for reminding us to close this