PyMC3 on Apple M1-chip

I bit the bullet and got one. I used pip to install pymc (contra the instructions). My simple “hello world” model samples quite briskly, but a more complicated model is raising exceptions when I try to sample in parallel (serial sampling works). Identical code worked, in parallel, on my Intel-based MacBook.
I’m going to try installing from conda and/or creating a minimal working example.

Nice, let me know how it goes - keen to move on from windows - Weird coincidence, just trying out your example of a statespace model in pymc aha, which ironically doesn’t work in parallel for on my build aha.

I just installed pymc 5.0.1 using mambaforge and my model sampled in parallel successfully. It took half the time as on my Intel-based MacBook Pro and with infinitely less fan action. :slight_smile:

3 Likes

good stuff!

Thank you very much. The installation worked flawlessly, but quite a lot tests in the test suite FAIL. Any ideas if this ok in an M1?

======================================================= 55 failed, 25 passed, 1 xfailed, 2 warnings, 6 errors in 47.21s =======================================================

How did the tests fail? There are some test-only dependencies that must be installed separately from the main PyMC installation.

Overnight windows updates and turned off/on and it seems to sample in parallel now. peculiar aha

Hi. Thanks for the reply. I have installed the required dependencies and run

pytest -v pymc/tests/test_model.py

A few test pass, but many don’t.
Running pymc 5.0.1 with pytensor 2.8.11 (the only dependency I could not correctly install).

The installed packages are in the list below. Please let me know what other information could I provide.

# Name                    Version                   Build  Channel
alabaster                 0.7.13             pyhd8ed1ab_0    conda-forge
algopy                    0.5.7                      py_0    conda-forge
appdirs                   1.4.4              pyh9f0ad1d_0    conda-forge
appnope                   0.1.3              pyhd8ed1ab_0    conda-forge
arviz                     0.14.0             pyhd8ed1ab_0    conda-forge
asttokens                 2.2.1              pyhd8ed1ab_0    conda-forge
attrs                     22.2.0             pyh71513ae_0    conda-forge
babel                     2.11.0             pyhd8ed1ab_0    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                pyhd8ed1ab_3    conda-forge
backports.functools_lru_cache 1.6.4              pyhd8ed1ab_0    conda-forge
beautifulsoup4            4.11.2             pyha770c72_0    conda-forge
blas                      2.116                  openblas    conda-forge
blas-devel                3.9.0           16_osxarm64_openblas    conda-forge
bleach                    6.0.0              pyhd8ed1ab_0    conda-forge
brotli                    1.0.9                h1a8c8d9_8    conda-forge
brotli-bin                1.0.9                h1a8c8d9_8    conda-forge
brotlipy                  0.7.0           py311he2be06e_1005    conda-forge
bzip2                     1.0.8                h3422bc3_4    conda-forge
c-ares                    1.18.1               h3422bc3_0    conda-forge
c-compiler                1.5.2                h5008568_0    conda-forge
ca-certificates           2022.12.7            h4653dfc_0    conda-forge
cached-property           1.5.2                hd8ed1ab_1    conda-forge
cached_property           1.5.2              pyha770c72_1    conda-forge
cachetools                5.3.0              pyhd8ed1ab_0    conda-forge
cctools                   973.0.1             hcbb26d4_11    conda-forge
cctools_osx-arm64         973.0.1             hef52d2f_11    conda-forge
certifi                   2022.12.7          pyhd8ed1ab_0    conda-forge
cffi                      1.15.1          py311hae827db_3    conda-forge
cfgv                      3.3.1              pyhd8ed1ab_0    conda-forge
cftime                    1.6.2           py311h4add359_1    conda-forge
charset-normalizer        2.1.1              pyhd8ed1ab_0    conda-forge
clang                     14.0.6               hce30654_0    conda-forge
clang-14                  14.0.6          default_h81a5282_0    conda-forge
clang_osx-arm64           14.0.6               h15773ab_4    conda-forge
clangxx                   14.0.6          default_hb7ecf47_0    conda-forge
clangxx_osx-arm64         14.0.6               he29aa18_4    conda-forge
click                     8.1.3           unix_pyhd8ed1ab_2    conda-forge
cloudpickle               2.2.1              pyhd8ed1ab_0    conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
comm                      0.1.2              pyhd8ed1ab_0    conda-forge
compiler-rt               14.0.6               h30b49de_0    conda-forge
compiler-rt_osx-arm64     14.0.6               h48302dc_0    conda-forge
cons                      0.4.5              pyhd8ed1ab_0    conda-forge
contourpy                 1.0.7           py311hd6ee22a_0    conda-forge
coverage                  7.1.0           py311he2be06e_0    conda-forge
cryptography              39.0.1          py311h507f6e9_0    conda-forge
curl                      7.88.1               h9049daf_0    conda-forge
cxx-compiler              1.5.2                hffc8910_0    conda-forge
cycler                    0.11.0             pyhd8ed1ab_0    conda-forge
debugpy                   1.6.6           py311ha397e9f_0    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
defusedxml                0.7.1              pyhd8ed1ab_0    conda-forge
distlib                   0.3.6              pyhd8ed1ab_0    conda-forge
docutils                  0.17.1                   pypi_0    pypi
entrypoints               0.4                pyhd8ed1ab_0    conda-forge
etuples                   0.3.8              pyhd8ed1ab_0    conda-forge
exceptiongroup            1.1.0              pyhd8ed1ab_0    conda-forge
executing                 1.2.0              pyhd8ed1ab_0    conda-forge
fastprogress              1.0.3              pyhd8ed1ab_0    conda-forge
filelock                  3.9.0              pyhd8ed1ab_0    conda-forge
fonttools                 4.38.0          py311he2be06e_1    conda-forge
freetype                  2.12.1               hd633e50_1    conda-forge
greenlet                  2.0.2           py311ha397e9f_0    conda-forge
h5py                      3.8.0           nompi_py311hf81d9a4_100    conda-forge
hdf4                      4.2.15               h1a38d6a_5    conda-forge
hdf5                      1.12.2          nompi_ha7af310_101    conda-forge
icu                       70.1                 h6b3803e_0    conda-forge
identify                  2.5.18             pyhd8ed1ab_0    conda-forge
idna                      3.4                pyhd8ed1ab_0    conda-forge
imagesize                 1.4.1              pyhd8ed1ab_0    conda-forge
importlib-metadata        6.0.0              pyha770c72_0    conda-forge
importlib_metadata        6.0.0                hd8ed1ab_0    conda-forge
importlib_resources       5.12.0             pyhd8ed1ab_0    conda-forge
iniconfig                 2.0.0              pyhd8ed1ab_0    conda-forge
ipykernel                 6.21.2             pyh736e0ef_0    conda-forge
ipython                   8.10.0             pyhd1c38e8_0    conda-forge
ipywidgets                8.0.4              pyhd8ed1ab_0    conda-forge
jedi                      0.18.2             pyhd8ed1ab_0    conda-forge
jinja2                    3.1.2              pyhd8ed1ab_1    conda-forge
jpeg                      9e                   h1a8c8d9_3    conda-forge
jsonschema                4.17.3             pyhd8ed1ab_0    conda-forge
jupyter-cache             0.5.0              pyhd8ed1ab_0    conda-forge
jupyter-sphinx            0.4.0              pyhd8ed1ab_0    conda-forge
jupyter_client            8.0.3              pyhd8ed1ab_0    conda-forge
jupyter_core              5.2.0           py311h267d04e_0    conda-forge
jupyterlab_pygments       0.2.2              pyhd8ed1ab_0    conda-forge
jupyterlab_widgets        3.0.5              pyhd8ed1ab_0    conda-forge
kiwisolver                1.4.4           py311hd6ee22a_1    conda-forge
krb5                      1.20.1               h69eda48_0    conda-forge
lcms2                     2.14                 h481adae_1    conda-forge
ld64                      609                 h619f069_11    conda-forge
ld64_osx-arm64            609                 h7167370_11    conda-forge
lerc                      4.0.0                h9a09cb3_0    conda-forge
libaec                    1.0.6                hb7217d7_1    conda-forge
libblas                   3.9.0           16_osxarm64_openblas    conda-forge
libbrotlicommon           1.0.9                h1a8c8d9_8    conda-forge
libbrotlidec              1.0.9                h1a8c8d9_8    conda-forge
libbrotlienc              1.0.9                h1a8c8d9_8    conda-forge
libcblas                  3.9.0           16_osxarm64_openblas    conda-forge
libclang-cpp14            14.0.6          default_h81a5282_0    conda-forge
libcurl                   7.88.1               h9049daf_0    conda-forge
libcxx                    14.0.6               h2692d47_0    conda-forge
libdeflate                1.17                 h1a8c8d9_0    conda-forge
libedit                   3.1.20191231         hc8eb9b7_2    conda-forge
libev                     4.33                 h642e427_1    conda-forge
libffi                    3.4.2                h3422bc3_5    conda-forge
libgfortran               5.0.0           11_3_0_hd922786_28    conda-forge
libgfortran5              11.3.0              hdaf2cc0_28    conda-forge
libiconv                  1.17                 he4db4b2_0    conda-forge
liblapack                 3.9.0           16_osxarm64_openblas    conda-forge
liblapacke                3.9.0           16_osxarm64_openblas    conda-forge
libllvm14                 14.0.6               hf6e71e7_1    conda-forge
libnetcdf                 4.9.1           nompi_h66d6d65_100    conda-forge
libnghttp2                1.51.0               hae82a92_0    conda-forge
libopenblas               0.3.21          openmp_hc731615_3    conda-forge
libpng                    1.6.39               h76d750c_0    conda-forge
libsodium                 1.0.18               h27ca646_1    conda-forge
libsqlite                 3.40.0               h76d750c_0    conda-forge
libssh2                   1.10.0               h7a5bd25_3    conda-forge
libtiff                   4.5.0                h5dffbdd_2    conda-forge
libwebp-base              1.2.4                h57fd34a_0    conda-forge
libxcb                    1.13              h9b22ae9_1004    conda-forge
libxml2                   2.10.3               h87b0503_0    conda-forge
libzip                    1.9.2                h76ab92c_1    conda-forge
libzlib                   1.2.13               h03a7124_4    conda-forge
llvm-openmp               15.0.7               h7cfbb63_0    conda-forge
llvm-tools                14.0.6               hf6e71e7_1    conda-forge
logical-unification       0.4.5              pyhd8ed1ab_0    conda-forge
markdown-it-py            2.1.0              pyhd8ed1ab_0    conda-forge
markupsafe                2.1.2           py311he2be06e_0    conda-forge
matplotlib-base           3.7.0           py311h99a5f44_0    conda-forge
matplotlib-inline         0.1.6              pyhd8ed1ab_0    conda-forge
mdit-py-plugins           0.3.3              pyhd8ed1ab_0    conda-forge
mdurl                     0.1.0              pyhd8ed1ab_0    conda-forge
minikanren                1.0.3              pyhd8ed1ab_0    conda-forge
mistune                   2.0.5              pyhd8ed1ab_0    conda-forge
multipledispatch          0.6.0                      py_0    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
mypy                      0.990           py311he2be06e_3    conda-forge
mypy_extensions           1.0.0              pyha770c72_0    conda-forge
myst-nb                   0.17.1             pyhd8ed1ab_0    conda-forge
myst-parser               0.18.1             pyhd8ed1ab_0    conda-forge
nbclient                  0.5.13             pyhd8ed1ab_0    conda-forge
nbconvert                 7.2.9              pyhd8ed1ab_0    conda-forge
nbconvert-core            7.2.9              pyhd8ed1ab_0    conda-forge
nbconvert-pandoc          7.2.9              pyhd8ed1ab_0    conda-forge
nbformat                  5.7.3              pyhd8ed1ab_0    conda-forge
ncurses                   6.3                  h07bb92c_1    conda-forge
nest-asyncio              1.5.6              pyhd8ed1ab_0    conda-forge
netcdf4                   1.6.2           nompi_py311h40498cf_101    conda-forge
nodeenv                   1.7.0              pyhd8ed1ab_0    conda-forge
numdifftools              0.9.41             pyhd8ed1ab_0    conda-forge
numpy                     1.24.2          py311h60f8152_0    conda-forge
numpydoc                  1.5.0              pyhd8ed1ab_0    conda-forge
openblas                  0.3.21          openmp_hf78f355_3    conda-forge
openjpeg                  2.5.0                hbc2ba62_2    conda-forge
openssl                   3.0.8                h03a7124_0    conda-forge
packaging                 23.0               pyhd8ed1ab_0    conda-forge
pandas                    1.5.3           py311h4eec4a9_0    conda-forge
pandoc                    2.19.2               hce30654_1    conda-forge
pandocfilters             1.5.0              pyhd8ed1ab_0    conda-forge
parso                     0.8.3              pyhd8ed1ab_0    conda-forge
patsy                     0.5.3              pyhd8ed1ab_0    conda-forge
pexpect                   4.8.0              pyh1a96a4e_2    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    9.4.0           py311h627eb56_1    conda-forge
pip                       23.0.1             pyhd8ed1ab_0    conda-forge
pkgutil-resolve-name      1.3.10             pyhd8ed1ab_0    conda-forge
platformdirs              3.0.0              pyhd8ed1ab_0    conda-forge
pluggy                    1.0.0              pyhd8ed1ab_5    conda-forge
polyagamma                1.3.4           py311h4add359_2    conda-forge
pooch                     1.6.0              pyhd8ed1ab_0    conda-forge
pre-commit                3.0.4           py311h267d04e_0    conda-forge
prompt-toolkit            3.0.36             pyha770c72_0    conda-forge
psutil                    5.9.4           py311he2be06e_0    conda-forge
pthread-stubs             0.4               h27ca646_1001    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pydata-sphinx-theme       0.12.0                   pypi_0    pypi
pygments                  2.14.0             pyhd8ed1ab_0    conda-forge
pymc                      5.0.1                hd8ed1ab_0    conda-forge
pymc-base                 5.0.1              pyhd8ed1ab_0    conda-forge
pymc-sphinx-theme         0.1                      pypi_0    pypi
pyopenssl                 23.0.0             pyhd8ed1ab_0    conda-forge
pyparsing                 3.0.9              pyhd8ed1ab_0    conda-forge
pyrsistent                0.19.3          py311he2be06e_0    conda-forge
pysocks                   1.7.1              pyha2e5f31_6    conda-forge
pytensor                  2.8.11          py311h8a3c2de_1    conda-forge
pytensor-base             2.8.11          py311h267d04e_1    conda-forge
pytest                    7.2.1              pyhd8ed1ab_0    conda-forge
pytest-cov                4.0.0              pyhd8ed1ab_0    conda-forge
python                    3.11.0          h3ba56d0_1_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python-fastjsonschema     2.16.2             pyhd8ed1ab_0    conda-forge
python_abi                3.11                    3_cp311    conda-forge
pytz                      2022.7.1           pyhd8ed1ab_0    conda-forge
pyyaml                    6.0             py311he2be06e_5    conda-forge
pyzmq                     25.0.0          py311h0f351f6_0    conda-forge
readline                  8.1.2                h46ed386_0    conda-forge
requests                  2.28.2             pyhd8ed1ab_0    conda-forge
scipy                     1.10.0          py311h0bcca16_2    conda-forge
setuptools                67.3.2             pyhd8ed1ab_0    conda-forge
sigtool                   0.1.3                h44b9a77_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
snowballstemmer           2.2.0              pyhd8ed1ab_0    conda-forge
soupsieve                 2.3.2.post1        pyhd8ed1ab_0    conda-forge
sphinx                    5.3.0              pyhd8ed1ab_0    conda-forge
sphinx-copybutton         0.5.0              pyhd8ed1ab_0    conda-forge
sphinx-design             0.3.0              pyhd8ed1ab_0    conda-forge
sphinx-notfound-page      0.8.3              pyhd8ed1ab_0    conda-forge
sphinx-remove-toctrees    0.0.3              pyhd8ed1ab_0    conda-forge
sphinxcontrib-applehelp   1.0.4              pyhd8ed1ab_0    conda-forge
sphinxcontrib-devhelp     1.0.2                      py_0    conda-forge
sphinxcontrib-htmlhelp    2.0.1              pyhd8ed1ab_0    conda-forge
sphinxcontrib-jsmath      1.0.1                      py_0    conda-forge
sphinxcontrib-qthelp      1.0.3                      py_0    conda-forge
sphinxcontrib-serializinghtml 1.1.5              pyhd8ed1ab_2    conda-forge
sphinxext-rediraffe       0.2.7              pyhd8ed1ab_0    conda-forge
sqlalchemy                1.4.46          py311he2be06e_0    conda-forge
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
statsmodels               0.13.5          py311h4add359_2    conda-forge
tabulate                  0.9.0              pyhd8ed1ab_1    conda-forge
tapi                      1100.0.11            he4954df_0    conda-forge
tinycss2                  1.2.1              pyhd8ed1ab_0    conda-forge
tk                        8.6.12               he1e0b03_0    conda-forge
toml                      0.10.2             pyhd8ed1ab_0    conda-forge
tomli                     2.0.1              pyhd8ed1ab_0    conda-forge
toolz                     0.12.0             pyhd8ed1ab_0    conda-forge
tornado                   6.2             py311he2be06e_1    conda-forge
traitlets                 5.9.0              pyhd8ed1ab_0    conda-forge
types-cachetools          5.3.0.0            pyhd8ed1ab_0    conda-forge
typing-extensions         4.4.0                hd8ed1ab_0    conda-forge
typing_extensions         4.4.0              pyha770c72_0    conda-forge
tzdata                    2022g                h191b570_0    conda-forge
ukkonen                   1.0.1           py311hd6ee22a_3    conda-forge
urllib3                   1.26.14            pyhd8ed1ab_0    conda-forge
virtualenv                20.19.0            pyhd8ed1ab_0    conda-forge
watermark                 2.3.1              pyhd8ed1ab_1    conda-forge
wcwidth                   0.2.6              pyhd8ed1ab_0    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.38.4             pyhd8ed1ab_0    conda-forge
widgetsnbextension        4.0.5              pyhd8ed1ab_0    conda-forge
xarray                    2023.2.0           pyhd8ed1ab_0    conda-forge
xarray-einstats           0.5.1              pyhd8ed1ab_0    conda-forge
xorg-libxau               1.0.9                h27ca646_0    conda-forge
xorg-libxdmcp             1.1.3                h27ca646_0    conda-forge
xz                        5.2.6                h57fd34a_0    conda-forge
yaml                      0.2.5                h3422bc3_2    conda-forge
zeromq                    4.3.4                hbdafb3b_1    conda-forge
zipp                      3.14.0             pyhd8ed1ab_0    conda-forge
zlib                      1.2.13               h03a7124_4    conda-forge
zstd                      1.5.2                hf913c23_6    conda-forge

Can you share one of the tracebacks of the failing tests?

Here is the full output for the entire suite. I’ve gone through it to see if I could spot something, but I am afraid I’m not proficient enough. Certainly pytensor and the link module seem to be causing some of the issues.

Please, let me know if I can provide anything more useful than this.
And thanks a lot for your help.
pymc_tests.txt (1.2 MB)

UPDATE: following this post, I decided to give the test a try preappending /usr/bin to my PATH, and magically now only two tests fail! It seems that the system compilers are required on my M1. Is this reasonable?

1 Like

Yes that’s reasonable

Hi,
I have to admit that I am not a professional programmer. Still I would like to use pymc as a data analysis tool!
I have tried to use miniforg environments to run pymc scripts but did not succeed.
Can you maybe make a more detailed tutorial how to install and make pymc run on M1 chip macs? That would be much appreciated by me and certainly others!!!
Very Best!

I installed pymc this morning on my 16" M1 Mac, latest gen.

Make a virtual environment using either conda or venv. Run pip install pymc. That’s it.

Here’s my terminal code should you want to copy it:

mkdir pymc-test # make a folder to contain our virtual environment
cd pymc-test/ # enter it
python -m venv .venv # make a python virtual environment to keep our packages clean
source .venv/bin/activate # activate this environment so that "python" points to that environment
pip install pymc # install pymc
python -c 'import pymc' # this should run without any output

If you also want e.g. jupyter notebook or other packages, you would add them during the “pip install” section. To use pymc in vscode’s notebook, you would do;

pip install pymc ipykernel
1 Like

Hi. Same thing, got an M2 and ran into all kinds of problems. You seemed to have the only workable solution so far (for a beginer like me), but I can’t make it work either, some dependencies still break.

Are you aware of a more structured solution? Or is the solution so obvious that no one evert posts is back?

Thanks!

These days I am using conda to install pymc, not pip, because I’ve been encountering slowness with the latter. I’m pretty sure I followed the instructions, and just did conda install pymc. What errors do you get when going this route?

2 Likes

Can you give us some specifics on the kind of errors you experienced?

Hi. I’ve started too many threads on this - I’ve already replied here: Installation issues v5.9 macOS - #11 by salvador_v

But to your question, the installation works fine, but all breaks when I try to install theano. I’ll paste it here for reference too:

I’ll appreciate any insight on this. Thanks!

Theano is not maintained and is not compatible with recent python releases, as the error message shows. Why are you installing it? PyMC doesn’t use it.

Out of sheer newbishness, really. I’ve just started working on probabilistic programing using Martin et al ‘Bayesian Modeling and Computation in Python’, which is based on PyMC 3, but their env is not compatible with my Mac. Now I’m starting over with PyMC 5 and then will go back to the book.