Unable to install on Mac M1

I have tried install pymc through conda and via pip/setuptools/github and I get the same error when I run this example code:

import numpy as np
import pymc as pm

X = np.random.normal(size=100)
y = np.random.normal(X) * 1.2

with pm.Model() as linear_model:
    weights = pm.Normal("weights", mu=0, sigma=1)
    noise = pm.Gamma("noise", alpha=2, beta=1)
    y_observed = pm.Normal(
        "y_observed",
        mu=X @ weights,
        sigma=noise,
        observed=y,
    )

    prior = pm.sample_prior_predictive()
    posterior = pm.sample()
    posterior_pred = pm.sample_posterior_predictive(posterior)

The error message is (truncated here):

ERROR (aesara.graph.opt): Optimization failure due to: constant_folding
ERROR (aesara.graph.opt): node: InplaceDimShuffle{}(TensorConstant{(1,) of 100})
ERROR (aesara.graph.opt): TRACEBACK:
ERROR (aesara.graph.opt): Traceback (most recent call last):
  File "/Users/robertarbon/opt/miniconda3/envs/pymc/lib/python3.9/site-packages/aesara/graph/opt.py", line 1850, in process_node
    replacements = lopt.transform(fgraph, node)
  File "/Users/robertarbon/opt/miniconda3/envs/pymc/lib/python3.9/site-packages/aesara/graph/opt.py", line 1055, in transform
    return self.fn(fgraph, node)
  File "/Users/robertarbon/opt/miniconda3/envs/pymc/lib/python3.9/site-packages/aesara/tensor/basic_opt.py", line 2954, in constant_folding
    thunk = node.op.make_thunk(node, storage_map, compute_map, no_recycling=[])
  File "/Users/robertarbon/opt/miniconda3/envs/pymc/lib/python3.9/site-packages/aesara/link/c/op.py", line 131, in make_thunk
    return self.make_c_thunk(node, storage_map, compute_map, no_recycling)
  File "/Users/robertarbon/opt/miniconda3/envs/pymc/lib/python3.9/site-packages/aesara/link/c/op.py", line 96, in make_c_thunk
    outputs = cl.make_thunk(
  File "/Users/robertarbon/opt/miniconda3/envs/pymc/lib/python3.9/site-packages/aesara/link/c/basic.py", line 1198, in make_thunk
    cthunk, module, in_storage, out_storage, error_storage = self.__compile__(
  File "/Users/robertarbon/opt/miniconda3/envs/pymc/lib/python3.9/site-packages/aesara/link/c/basic.py", line 1133, in __compile__
    thunk, module = self.cthunk_factory(
  File "/Users/robertarbon/opt/miniconda3/envs/pymc/lib/python3.9/site-packages/aesara/link/c/basic.py", line 1629, in cthunk_factory
    module = get_module_cache().module_from_key(key=key, lnk=self)
  File "/Users/robertarbon/opt/miniconda3/envs/pymc/lib/python3.9/site-packages/aesara/link/c/cmodule.py", line 1216, in module_from_key
    module = lnk.compile_cmodule(location)
  File "/Users/robertarbon/opt/miniconda3/envs/pymc/lib/python3.9/site-packages/aesara/link/c/basic.py", line 1538, in compile_cmodule
    module = c_compiler.compile_str(
  File "/Users/robertarbon/opt/miniconda3/envs/pymc/lib/python3.9/site-packages/aesara/link/c/cmodule.py", line 2575, in compile_str
    raise CompileError(
aesara.link.c.exceptions.CompileError: Compilation failed (return status=1):
/usr/bin/clang++ -dynamiclib -g -O3 -fno-math-errno -Wno-unused-label -Wno-unused-variable -Wno-write-strings -Wno-c++11-narrowing -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -m64 -fPIC -undefined dynamic_lookup -I/Users/robertarbon/opt/miniconda3/envs/pymc/lib/python3.9/site-packages/numpy/core/include -I/Users/robertarbon/opt/miniconda3/envs/pymc/include/python3.9 -I/Users/robertarbon/opt/miniconda3/envs/pymc/lib/python3.9/site-packages/aesara/link/c/c_code -L/Users/robertarbon/opt/miniconda3/envs/pymc/lib -fvisibility=hidden -o /Users/robertarbon/.aesara/compiledir_macOS-10.16-x86_64-i386-64bit-i386-3.9.0-64/tmpvw4knnhk/mba10987274f369529454d4a60996746c3927712a0b1b3928446a3c275151e2ee.so /Users/robertarbon/.aesara/compiledir_macOS-10.16-x86_64-i386-64bit-i386-3.9.0-64/tmpvw4knnhk/mod.cpp
In file included from /Users/robertarbon/.aesara/compiledir_macOS-10.16-x86_64-i386-64bit-i386-3.9.0-64/tmpvw4knnhk/mod.cpp:1:
In file included from /Users/robertarbon/opt/miniconda3/envs/pymc/include/python3.9/Python.h:25:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:64:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:93:16: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
        unsigned char   *_base;
...
...

My hardware:

Model Name: MacBook Pro
Model Identifier: MacBookPro18,3
Chip: Apple M1 Pro
Total Number of Cores: 8 (6 performance and 2 efficiency)
Memory: 16 GB
System Firmware Version: 7429.61.2
OS Loader Version: 7429.61.2

OS: Mac 12.1

I’ve install pymc from github (output below from conda list):
pymc 4.0.0b6 dev_0 <develop>

My CPATH is set to:

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/

However if i run:

(pymc) ➜  include xcrun --show-sdk-path
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk

It’s also a bit weird that the .aesara directory created for compilation is:

/.aesara/compiledir_macOS-10.16-x86_64-i386-64bit-i386-3.9.0-64

Note: I also I installed my whole workspace/account from a previous M1 which in turn was installed from a previous intel machine (probably running 10.6 but I can’t remember exact version).

I’ve also tried running pymc3 but that also fails but with a different error.

Any help greatly appreciated!

Thanks.

UPDATE

I created a soft-link to the current MacOS SDK (12.3) from MacOSX10.15.sdk and it works, i.e.:

(pymc) ➜  SDKs ll
total 0
lrwxr-xr-x  1 root  wheel    14B 18 May 10:23 MacOSX.sdk -> MacOSX12.3.sdk
drwxr-xr-x@ 7 root  wheel   224B 13 Jan 20:18 MacOSX10.14.sdk
lrwxr-xr-x  1 root  wheel    14B 18 May 13:19 MacOSX10.15.sdk -> MacOSX12.3.sdk
drwxr-xr-x@ 7 root  wheel   224B 13 Jan 20:18 MacOSX11.0.sdk
drwxr-xr-x  7 root  wheel   224B 18 May 10:23 MacOSX11.3.sdk
lrwxr-xr-x  1 root  wheel    14B 18 May 10:22 MacOSX11.sdk -> MacOSX11.3.sdk
drwxr-xr-x  7 root  wheel   224B 22 Jul  2021 MacOSX12.0.sdk
drwxr-xr-x  7 root  wheel   224B 19 Nov 22:25 MacOSX12.1.sdk
drwxr-xr-x  7 root  wheel   224B 18 May 10:24 MacOSX12.3.sdk
lrwxr-xr-x  1 root  wheel    14B 18 May 10:22 MacOSX12.sdk -> MacOSX12.3.sdk

This doesn’t seem like the optimum solution - so any help is still appreciated.

I know @fonnesbeck has v4 working on a Mac. Any idea what’s happening here, Chris?

Unfortunately I’ve not seen this before myself, so I have no insight. Perhaps the Aesara folks would be helpful? I know in the past deleting my .theano (now .aesara) directory solved compilation issues from time to time, but just guessing here. Glad you found a solution.

1 Like

Thanks - I’m thinking that this has to do with my conda and command line tools install. When I have the emotional energy I will retinstall both from scratch and report back.

Knowing that it’s working on the new macs is a help in itself so thanks.

2 Likes

Hi @RobertArbon, chipping in a bit late: I ran into a lot of these issues lately and it was making me really confused. Quite frankly, I’m not familiar with the suggestion that you came up with, but happy to hear that it works!

I found out that my Terminal can be started using Rosetta which seems to allow things to run as if the chip were Intel (to my understanding?). I followed this tutorial which worked for me: How to install Python under Rosetta 2 | by Vojtech Rinik | Thinknum | Medium

Pytest seems a bit slower compared to things when I would run on an Ubuntu VM, but this was my solution to making things work on my M1 Mac, which I love very much :sweat_smile:

We have some open issues in Aesara where I complain about my installation troubles: issue 909 and issue 934

2 Likes

I’m running from a mambaforge arm64 install on my M1 MacBook Air and Mac Studio with no problems