Weird VScode hangs on pymc v5 import on restart but not fresh install

Hi everyone,

I appreciate all the help I have gotten over on my previous question. However, it seems the issue has reoccurred. After checking multiple times it seems a fresh install of VScode (I’m using v1.93.1) will successfully import pymc and execute its scripts.

As for my computer, I am working on a MacBook air 2, m2 chip running Sonoma 14.6.1 (silicon).

This is the minimal reproducible example I have been using for testing:

import pymc as pm
print(pm.__version__)

However, whenever I restart the VScode application, this process hangs and when I use the ctrl-C keyboard interrupt I get the following traceback:

(pymc) uqamcka3@x86_64-apple-darwin13 Random % /opt/miniconda3/envs/pymc/bin/python /Users/uqamcka3/PHD/Projects/Random/multitest.
py
^CTraceback (most recent call last):
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/configparser.py", line 303, in fetch_val_for_key
    return self._pytensor_cfg.get(section, option)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/configparser.py", line 759, in get
    d = self._unify_values(section, vars)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/configparser.py", line 1132, in _unify_values
    raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'blas'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/configparser.py", line 418, in __get__
    val_str = cls.fetch_val_for_key(self.name, delete_key=delete_key)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/configparser.py", line 307, in fetch_val_for_key
    raise KeyError(key)
KeyError: 'blas__ldflags'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/uqamcka3/PHD/Projects/Random/multitest.py", line 8, in <module>
    import pymc as pm
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pymc/__init__.py", line 46, in <module>
    __set_compiler_flags()
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pymc/__init__.py", line 29, in __set_compiler_flags
    import pytensor
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/__init__.py", line 119, in <module>
    from pytensor import scalar, tensor
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/tensor/__init__.py", line 103, in <module>
    import pytensor.tensor.rewriting
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/tensor/rewriting/__init__.py", line 2, in <module>
    import pytensor.tensor.rewriting.blas
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/tensor/rewriting/blas.py", line 85, in <module>
    from pytensor.tensor.blas import (
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/tensor/blas.py", line 103, in <module>
    from pytensor.tensor.blas_headers import blas_header_text, blas_header_version
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/tensor/blas_headers.py", line 1006, in <module>
    if not config.blas__ldflags:
           ^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/configparser.py", line 422, in __get__
    val_str = self.default()
              ^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/cmodule.py", line 2875, in default_blas_ldflags
    return check_libs(
           ^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/cmodule.py", line 2794, in check_libs
    res = try_blas_flag(flags)
          ^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/cmodule.py", line 2009, in try_blas_flag
    res = GCC_compiler.try_compile_tmp(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/cmodule.py", line 2407, in try_compile_tmp
    return cls._try_compile_tmp(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/cmodule.py", line 1885, in _try_compile_tmp
    args = cls.compile_args()
           ^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/cmodule.py", line 2315, in compile_args
    compilation_result, execution_result = try_march_flag(
                                           ^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/cmodule.py", line 2044, in try_march_flag
    compilation_result, execution_result = GCC_compiler.try_compile_tmp(
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/cmodule.py", line 2407, in try_compile_tmp
    return cls._try_compile_tmp(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/cmodule.py", line 1911, in _try_compile_tmp
    out, err, p_ret = output_subprocess_Popen([exe_path])
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/utils.py", line 200, in output_subprocess_Popen
    out = p.communicate()
          ^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/subprocess.py", line 1209, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/subprocess.py", line 2115, in _communicate
    ready = selector.select(timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/selectors.py", line 415, in select
    fd_event_list = self._selector.poll(timeout)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt

checking my environment I have blas 2.123 installed through accelerate which seems to be recommended, and I have pytensor installed. I am not sure why configparser.py seems to hang on import with the VScode restart and not on a fresh install.

as before executing the code in my .zsh terminal outside of VScode will work. However, using the .zsh terminal inside VScode, it will hang with a similar traceback.

My current VScode setup isn’t so fancy I think. I only have the most current Python interpreter installed and then only the VScode default settings. I was wondering as this does not seem to be a common issue in the community what version of VScode do the users here use?

Alternatively if there are other installation instructions or recommendations I would be more than happy to try them out. I understand this is likely a VScode issue and outside the scope of the discourse page, however, if many people use VScode and do not have this issue, i’d like to reproduce someone’s steps and attempt to see if this can’t be figured out.

For completeness, I have attached my conda environment. As it is also possible that there might be some python version conflicts i.e. I am currently on python 3.12.5 but the hanging might be due to some weird dependency on pytensor which I do not know but might only like python 3.10 for example.

Perhaps the most import packages and their versions are here

blas 2.123
clang 17.0.6
libblas 3.9.0
pymc 5.16.2
pymc_base 5.16.2
pytensor 2.25.4
python 3.12.5
# packages in environment at /opt/miniconda3/envs/pymc:
#
# Name                    Version                   Build  Channel
appnope                   0.1.4              pyhd8ed1ab_0    conda-forge
arviz                     0.19.0             pyhd8ed1ab_0    conda-forge
asttokens                 2.4.1              pyhd8ed1ab_0    conda-forge
atk-1.0                   2.38.0               h4bec284_2    conda-forge
bambi                     0.14.0                   pypi_0    pypi
blas                      2.123                accelerate    conda-forge
blas-devel                3.9.0           23_osx64_accelerate    conda-forge
brotli                    1.1.0                h00291cd_2    conda-forge
brotli-bin                1.1.0                h00291cd_2    conda-forge
bzip2                     1.0.8                hfdf4475_7    conda-forge
c-ares                    1.33.1               h44e7173_0    conda-forge
ca-certificates           2024.8.30            h8857fd0_0    conda-forge
cached-property           1.5.2                hd8ed1ab_1    conda-forge
cached_property           1.5.2              pyha770c72_1    conda-forge
cachetools                5.5.0              pyhd8ed1ab_0    conda-forge
cairo                     1.18.0               h37bd5c4_3    conda-forge
cctools_osx-64            1009.2               h98e843e_0    conda-forge
certifi                   2024.8.30          pyhd8ed1ab_0    conda-forge
clang                     17.0.6          default_he371ed4_7    conda-forge
clang-17                  17.0.6          default_hb173f14_7    conda-forge
clang_impl_osx-64         17.0.6              h1af8efd_19    conda-forge
clang_osx-64              17.0.6              hb91bd55_19    conda-forge
clangxx                   17.0.6          default_he371ed4_7    conda-forge
clangxx_impl_osx-64       17.0.6              hc3430b7_19    conda-forge
clangxx_osx-64            17.0.6              hb91bd55_19    conda-forge
cloudpickle               3.0.0              pyhd8ed1ab_0    conda-forge
comm                      0.2.2              pyhd8ed1ab_0    conda-forge
compiler-rt               17.0.6               h1020d70_2    conda-forge
compiler-rt_osx-64        17.0.6               hf2b8a54_2    conda-forge
cons                      0.4.6              pyhd8ed1ab_0    conda-forge
contourpy                 1.3.0           py312hc5c4d5f_1    conda-forge
cycler                    0.12.1             pyhd8ed1ab_0    conda-forge
debugpy                   1.8.5           py312h5861a67_1    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
dm-tree                   0.1.8           py312hd13efa9_5    conda-forge
etuples                   0.3.9              pyhd8ed1ab_0    conda-forge
exceptiongroup            1.2.2              pyhd8ed1ab_0    conda-forge
executing                 2.1.0              pyhd8ed1ab_0    conda-forge
expat                     2.6.2                h73e2aa4_0    conda-forge
filelock                  3.16.0             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                 h77eed37_2    conda-forge
fontconfig                2.14.2               h5bb23bf_0    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
fonttools                 4.53.1          py312hb553811_1    conda-forge
formulae                  0.5.4                    pypi_0    pypi
freetype                  2.12.1               h60636b9_2    conda-forge
fribidi                   1.0.10               hbcb3906_0    conda-forge
gdk-pixbuf                2.42.12              ha587570_0    conda-forge
graphite2                 1.3.13            h73e2aa4_1003    conda-forge
graphviz                  12.0.0               he14ced1_0    conda-forge
gtk2                      2.24.33              h2c15c3c_5    conda-forge
gts                       0.7.6                h53e17e3_4    conda-forge
h5netcdf                  1.3.0              pyhd8ed1ab_0    conda-forge
h5py                      3.11.0          nompi_py312hfc94b03_102    conda-forge
harfbuzz                  9.0.0                h098a298_1    conda-forge
hdf5                      1.14.3          nompi_h687a608_105    conda-forge
icu                       75.1                 h120a0e1_0    conda-forge
importlib-metadata        8.4.0              pyha770c72_0    conda-forge
importlib_metadata        8.4.0                hd8ed1ab_0    conda-forge
ipykernel                 6.29.5             pyh57ce528_0    conda-forge
ipython                   8.27.0             pyh707e725_0    conda-forge
ipywidgets                8.1.2           py312hecd8cb5_0  
jedi                      0.19.1             pyhd8ed1ab_0    conda-forge
jupyter_client            8.6.2              pyhd8ed1ab_0    conda-forge
jupyter_core              5.7.2           py312hb401068_0    conda-forge
jupyterlab_widgets        3.0.10          py312hecd8cb5_0  
kiwisolver                1.4.7           py312hc5c4d5f_0    conda-forge
krb5                      1.21.3               h37d8d59_0    conda-forge
lcms2                     2.16                 ha2f27b4_0    conda-forge
ld64_osx-64               907                  h38c89e5_0    conda-forge
lerc                      4.0.0                hb486fe8_0    conda-forge
libabseil                 20240116.2      cxx17_hf036a51_1    conda-forge
libaec                    1.1.3                h73e2aa4_0    conda-forge
libblas                   3.9.0           23_osx64_accelerate    conda-forge
libbrotlicommon           1.1.0                h00291cd_2    conda-forge
libbrotlidec              1.1.0                h00291cd_2    conda-forge
libbrotlienc              1.1.0                h00291cd_2    conda-forge
libcblas                  3.9.0           23_osx64_accelerate    conda-forge
libclang-cpp17            17.0.6          default_hb173f14_7    conda-forge
libcurl                   8.10.0               h58e7537_0    conda-forge
libcxx                    18.1.8               hd876a4e_6    conda-forge
libcxx-devel              17.0.6               h8f8a49f_6    conda-forge
libdeflate                1.21                 hfdf4475_0    conda-forge
libedit                   3.1.20191231         h0678c8f_2    conda-forge
libev                     4.33                 h10d778d_2    conda-forge
libexpat                  2.6.2                h73e2aa4_0    conda-forge
libffi                    3.4.2                h0d85af4_5    conda-forge
libgd                     2.3.3               h2e77e4f_10    conda-forge
libgfortran               5.0.0           13_2_0_h97931a8_3    conda-forge
libgfortran5              13.2.0               h2873a65_3    conda-forge
libglib                   2.80.3               h736d271_2    conda-forge
libhwloc                  2.11.1          default_h456cccd_1000    conda-forge
libiconv                  1.17                 hd75f5a5_2    conda-forge
libintl                   0.22.5               hdfe23c8_3    conda-forge
libjpeg-turbo             3.0.0                h0dc2134_1    conda-forge
liblapack                 3.9.0           23_osx64_accelerate    conda-forge
liblapacke                3.9.0           23_osx64_accelerate    conda-forge
libllvm17                 17.0.6               hbedff68_1    conda-forge
libnghttp2                1.58.0               h64cf6d3_1    conda-forge
libopenblas               0.3.27          openmp_h8869122_1    conda-forge
libpng                    1.6.43               h92b6c6a_0    conda-forge
librsvg                   2.58.3               h902c40a_0    conda-forge
libsodium                 1.0.18               hbcb3906_1    conda-forge
libsqlite                 3.46.0               h1b8f9f3_0    conda-forge
libssh2                   1.11.0               hd019ec5_0    conda-forge
libtiff                   4.6.0                h603087a_4    conda-forge
libwebp-base              1.4.0                h10d778d_0    conda-forge
libxcb                    1.16                 h00291cd_1    conda-forge
libxml2                   2.12.7               heaf3512_4    conda-forge
libzlib                   1.3.1                h87427d6_1    conda-forge
llvm-openmp               18.1.8               h15ab845_1    conda-forge
llvm-tools                17.0.6               hbedff68_1    conda-forge
logical-unification       0.4.6              pyhd8ed1ab_0    conda-forge
macosx_deployment_target_osx-64 10.13                hbc8f3bb_1    conda-forge
markdown-it-py            3.0.0              pyhd8ed1ab_0    conda-forge
matplotlib-base           3.9.2           py312h30cc4df_1    conda-forge
matplotlib-inline         0.1.7              pyhd8ed1ab_0    conda-forge
mdurl                     0.1.2              pyhd8ed1ab_0    conda-forge
minikanren                1.0.3              pyhd8ed1ab_0    conda-forge
mkl                       2023.2.0         h54c2260_50500    conda-forge
mkl-service               2.4.0           py312h2402a68_1    conda-forge
multipledispatch          0.6.0              pyhd8ed1ab_1    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
ncurses                   6.5                  hf036a51_1    conda-forge
nest-asyncio              1.6.0              pyhd8ed1ab_0    conda-forge
numpy                     1.26.4          py312he3a82b2_0    conda-forge
openblas                  0.3.27          openmp_hba01982_1    conda-forge
openjpeg                  2.5.2                h7310d3a_0    conda-forge
openssl                   3.3.2                hd23fc13_0    conda-forge
packaging                 24.1               pyhd8ed1ab_0    conda-forge
pandas                    2.2.2           py312h1171441_1    conda-forge
pango                     1.54.0               h115fe74_2    conda-forge
parso                     0.8.4              pyhd8ed1ab_0    conda-forge
pcre2                     10.44                h7634a1b_2    conda-forge
pexpect                   4.9.0              pyhd8ed1ab_0    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    10.4.0          py312h683ea77_1    conda-forge
pip                       24.2               pyh8b19718_1    conda-forge
pixman                    0.43.4               h73e2aa4_0    conda-forge
platformdirs              4.2.2              pyhd8ed1ab_0    conda-forge
prompt-toolkit            3.0.47             pyha770c72_0    conda-forge
psutil                    6.0.0           py312hbd25219_0    conda-forge
pthread-stubs             0.4               hc929b4f_1001    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pure_eval                 0.2.3              pyhd8ed1ab_0    conda-forge
pygments                  2.18.0             pyhd8ed1ab_0    conda-forge
pymc                      5.16.2               hd8ed1ab_0    conda-forge
pymc-base                 5.16.2             pyhd8ed1ab_0    conda-forge
pyparsing                 3.1.4              pyhd8ed1ab_0    conda-forge
pytensor                  2.25.4          py312h9592d4c_0    conda-forge
pytensor-base             2.25.4          py312h81f2e74_0    conda-forge
python                    3.12.5          h37a9e06_0_cpython    conda-forge
python-dateutil           2.9.0              pyhd8ed1ab_0    conda-forge
python-graphviz           0.20.3             pyh717bed2_0    conda-forge
python-tzdata             2024.1             pyhd8ed1ab_0    conda-forge
python_abi                3.12                    5_cp312    conda-forge
pytz                      2024.2             pyhd8ed1ab_0    conda-forge
pyzmq                     26.2.0          py312h54d5c6a_0    conda-forge
qhull                     2020.2               h3c5361c_5    conda-forge
readline                  8.2                  h9e318b2_1    conda-forge
rich                      13.8.1             pyhd8ed1ab_0    conda-forge
scipy                     1.14.1          py312he82a568_0    conda-forge
setuptools                72.2.0             pyhd8ed1ab_0    conda-forge
sigtool                   0.1.3                h88f4db0_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
tapi                      1300.6.5             h390ca13_0    conda-forge
tbb                       2021.13.0            h37c8870_0    conda-forge
threadpoolctl             3.5.0              pyhc1e730c_0    conda-forge
tk                        8.6.13               h1abcd95_1    conda-forge
toolz                     0.12.1             pyhd8ed1ab_0    conda-forge
tornado                   6.4.1           py312hb553811_1    conda-forge
traitlets                 5.14.3             pyhd8ed1ab_0    conda-forge
typing-extensions         4.12.2               hd8ed1ab_0    conda-forge
typing_extensions         4.12.2             pyha770c72_0    conda-forge
tzdata                    2024a                h8827d51_1    conda-forge
wcwidth                   0.2.13             pyhd8ed1ab_0    conda-forge
wheel                     0.44.0             pyhd8ed1ab_0    conda-forge
widgetsnbextension        4.0.10          py312hecd8cb5_0  
xarray                    2024.9.0           pyhd8ed1ab_0    conda-forge
xarray-einstats           0.7.0              pyhd8ed1ab_0    conda-forge
xorg-libxau               1.0.11               h0dc2134_0    conda-forge
xorg-libxdmcp             1.1.3                h35c211d_0    conda-forge
xz                        5.2.6                h775f41a_0    conda-forge
zeromq                    4.3.5                hde137ed_4    conda-forge
zipp                      3.20.1             pyhd8ed1ab_0    conda-forge
zlib                      1.3.1                h87427d6_1    conda-forge
zstd                      1.5.6                h915ae27_0    conda-forge

Small update here.

It seems I am able to get pymc to successfully import by changing a pytensor environment variable as follows within my active conda environment:

conda env config vars set PYTENSOR_FLAGS="blas__ldflags=-framework Accelerate"

This is great as now my test script will print out the pymc version I am using. However, it not gets stuck on sampling with pm.sample(). It’s hard for me to know if this is a hang because of another unset or weirdly set environment variable but here is the following traceback:

(pymc) uqamcka3@x86_64-apple-darwin13 Random % /opt/miniconda3/envs/pymc/bin/p
ython /Users/uqamcka3/PHD/Projects/Random/scripts/multitest.py
*** Start script ***
*** Start pymc import ***
*** Start Model script ***
pymc: v. 5.16.2
^CTraceback (most recent call last):
  File "/Users/uqamcka3/PHD/Projects/Random/scripts/multitest.py", line 35, in <module>
    trace = pm.sample(chains=1, cores=1, random_seed=SEED)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pymc/sampling/mcmc.py", line 716, in sample
    step = assign_step_methods(model, step, methods=pm.STEP_METHODS, step_kwargs=kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pymc/sampling/mcmc.py", line 237, in assign_step_methods
    return instantiate_steppers(model, steps, selected_steps, step_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pymc/sampling/mcmc.py", line 138, in instantiate_steppers
    step = step_class(vars=vars, model=model, **args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pymc/step_methods/hmc/nuts.py", line 180, in __init__
    super().__init__(vars, **kwargs)
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pymc/step_methods/hmc/base_hmc.py", line 109, in __init__
    super().__init__(vars, blocked=blocked, model=self._model, dtype=dtype, **pytensor_kwargs)
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pymc/step_methods/arraystep.py", line 163, in __init__
    func = model.logp_dlogp_function(vars, dtype=dtype, **pytensor_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pymc/model/core.py", line 620, in logp_dlogp_function
    ip = self.initial_point(0)
         ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pymc/model/core.py", line 1094, in initial_point
    fn = make_initial_point_fn(model=self, return_transformed=True)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pymc/initial_point.py", line 152, in make_initial_point_fn
    func = compile_pymc(inputs=[], outputs=initial_values, mode=pytensor.compile.mode.FAST_COMPILE)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pymc/pytensorf.py", line 1039, in compile_pymc
    pytensor_function = pytensor.function(
                        ^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/compile/function/__init__.py", line 318, in function
    fn = pfunc(
         ^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/compile/function/pfunc.py", line 465, in pfunc
    return orig_function(
           ^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/compile/function/types.py", line 1750, in orig_function
    m = Maker(
        ^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/compile/function/types.py", line 1523, in __init__
    self.prepare_fgraph(inputs, outputs, found_updates, fgraph, mode, profile)
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/compile/function/types.py", line 1411, in prepare_fgraph
    rewriter_profile = rewriter(fgraph)
                       ^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/graph/rewriting/basic.py", line 125, in __call__
    return self.rewrite(fgraph)
           ^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/graph/rewriting/basic.py", line 121, in rewrite
    return self.apply(fgraph, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/graph/rewriting/basic.py", line 291, in apply
    sub_prof = rewriter.apply(fgraph)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/graph/rewriting/basic.py", line 2443, in apply
    sub_prof = grewrite.apply(fgraph)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/graph/rewriting/basic.py", line 2027, in apply
    nb += self.process_node(fgraph, node)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/graph/rewriting/basic.py", line 1909, in process_node
    replacements = node_rewriter.transform(fgraph, node)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/graph/rewriting/basic.py", line 1081, in transform
    return self.fn(fgraph, node)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/tensor/rewriting/basic.py", line 1122, in constant_folding
    thunk = node.op.make_thunk(node, storage_map, compute_map, no_recycling=[])
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/op.py", line 119, in make_thunk
    return self.make_c_thunk(node, storage_map, compute_map, no_recycling)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/op.py", line 84, in make_c_thunk
    outputs = cl.make_thunk(
              ^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/basic.py", line 1182, in make_thunk
    cthunk, module, in_storage, out_storage, error_storage = self.__compile__(
                                                             ^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/basic.py", line 1103, in __compile__
    thunk, module = self.cthunk_factory(
                    ^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/basic.py", line 1614, in cthunk_factory
    key = self.cmodule_key()
          ^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/basic.py", line 1266, in cmodule_key
    compile_args=self.compile_args(),
                 ^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/basic.py", line 952, in compile_args
    ret += c_compiler.compile_args()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/cmodule.py", line 2315, in compile_args
    compilation_result, execution_result = try_march_flag(
                                           ^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/cmodule.py", line 2044, in try_march_flag
    compilation_result, execution_result = GCC_compiler.try_compile_tmp(
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/cmodule.py", line 2407, in try_compile_tmp
    return cls._try_compile_tmp(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/link/c/cmodule.py", line 1911, in _try_compile_tmp
    out, err, p_ret = output_subprocess_Popen([exe_path])
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/site-packages/pytensor/utils.py", line 200, in output_subprocess_Popen
    out = p.communicate()
          ^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/subprocess.py", line 1209, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/subprocess.py", line 2115, in _communicate
    ready = selector.select(timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/pymc/lib/python3.12/selectors.py", line 415, in select
    fd_event_list = self._selector.poll(timeout)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt

I am unsure what to make of this, the main thing I can conclude is that it at least gets stuck before the initiation of the NUTS sampler. I have also tried importing pytensor and manually setting my clang path as in this issue, which didn’t seem to help.

this is the test script I am running:

#%%
print('*** Start script ***')
import numpy as np
import pandas as pd
import arviz as az
#%%
print('*** Start pymc import ***')
import pymc as pm

print('*** Start Model script ***')
print(f'{pm.__name__}: v. {pm.__version__}')

if __name__ == '__main__':
    SEED = 20180730
    np.random.seed(SEED)

    # Generate data
    mu_real = 0
    sd_real = 1
    n_samples = 1000
    y = np.random.normal(loc=mu_real, scale=sd_real, size=n_samples)

    # Bayesian modelling
    with pm.Model() as model:
    
        mu = pm.Normal('mu', mu=0, sigma=10)
        sd = pm.HalfNormal('sd', sigma=10)
    
        # Likelihood
        likelihood = pm.Normal('likelihood', mu=mu, sigma=sd, observed=y)    
        trace = pm.sample(chains=1, cores=1, random_seed=SEED)

    print('Done!')

    az.plot_trace(trace, figsize=(10,7)) 
# %%

Hopefully, this might be a bit more helpful for troubleshooting. Let me know if there is anything else I can provide to make troubleshooting easier

Band-aid solution found. based on this comment here, it seems after setting the PyTensor flag, if I add the following to my script:

import pytensor
pytensor.config.cxx = '' //empty string

The code will sample although very slowly. I believe there is some weird issue in VScode as when I attempt to set the path to '/opt/miniconda3/envs/pymc_env/bin/clang++' I get stuck as before, despite this being the exact path that works and is used when I run the script in the native mac terminal without setting a path

I think I found the solution to my issue in particular. I’m not sure for what reason but after much chatgpt and comparing flags and environment variables, changing pytensor.config.gcc__cxxflags seems to work for me. Restarting VScode no longer hangs on pm.sample()

pytensor.config.gcc__cxxflags = '-L/opt/miniconda3/envs/pymc_env/lib -march=native'

2 Likes