Pymc-marketing Install successful; bgm.fit() creates 7 errors

I have previously installed and successfully fit several pymc-marketing models on an Intel-silicon MacBookPro by activating an Anaconda environment and using jupyterlab:

% conda create -c conda-forge -n pymc_env "pymc>=5"
% conda activate pymc_env

I just set up an Apple-silicon MacBookPro (M2 vintage) using the same setup as above, with a fresh Anaconda installation.

After importing the following:

import numpy as np
import pandas as pd
import pymc as pm
from arviz.labels import MapLabeller
from pymc_marketing import clv

I received a warning:
: WARNING (pytensor.tensor.blas): Using NumPy C-API based implementation for BLAS functions.

Then when i executed:

bgm.fit()
bgm.fit_summary()

This is one cell of errors:

ERROR (pytensor.graph.rewriting.basic): Rewrite failure due to: constant_folding
ERROR (pytensor.graph.rewriting.basic): node: Cast{float32}(10)
ERROR (pytensor.graph.rewriting.basic): TRACEBACK:
ERROR (pytensor.graph.rewriting.basic): Traceback (most recent call last):
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/graph/rewriting/basic.py", line 1919, in process_node
    replacements = node_rewriter.transform(fgraph, node)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/graph/rewriting/basic.py", line 1081, in transform
    return self.fn(fgraph, node)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/tensor/rewriting/basic.py", line 1127, in constant_folding
    thunk = node.op.make_thunk(node, storage_map, compute_map, no_recycling=[])
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/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/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/link/c/op.py", line 84, in make_c_thunk
    outputs = cl.make_thunk(
              ^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/link/c/basic.py", line 1190, in make_thunk
    cthunk, module, in_storage, out_storage, error_storage = self.__compile__(
                                                             ^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/link/c/basic.py", line 1110, in __compile__
    thunk, module = self.cthunk_factory(
                    ^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/link/c/basic.py", line 1632, in cthunk_factory
    module = cache.module_from_key(key=key, lnk=self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/link/c/cmodule.py", line 1233, in module_from_key
    module = lnk.compile_cmodule(location)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/link/c/basic.py", line 1533, in compile_cmodule
    module = c_compiler.compile_str(
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/link/c/cmodule.py", line 2634, in compile_str
    raise CompileError(
pytensor.link.c.exceptions.CompileError: Compilation failed (return status=1):
/opt/anaconda3/envs/pymc_env/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 -fPIC -undefined dynamic_lookup -I/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/numpy/core/include -I/opt/anaconda3/envs/pymc_env/include/python3.12 -I/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/link/c/c_code -L/opt/anaconda3/envs/pymc_env/lib -fvisibility=hidden -o /Users/stuartkerr/.pytensor/compiledir_macOS-14.5-arm64-arm-64bit-arm-3.12.3-64/tmpf0_ilt5x/me74092bd2820b30210582801be6ace00b8255d62e9b7646e2038659d8b6ecf02.so /Users/stuartkerr/.pytensor/compiledir_macOS-14.5-arm64-arm-64bit-arm-3.12.3-64/tmpf0_ilt5x/mod.cpp
In file included from /Users/stuartkerr/.pytensor/compiledir_macOS-14.5-arm64-arm-64bit-arm-3.12.3-64/tmpf0_ilt5x/mod.cpp:1:
In file included from /opt/anaconda3/envs/pymc_env/include/python3.12/Python.h:23:
/opt/anaconda3/envs/pymc_env/bin/../include/c++/v1/stdlib.h:148:34: error: unknown type name 'ldiv_t'
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
                                 ^
/opt/anaconda3/envs/pymc_env/bin/../include/c++/v1/stdlib.h:149:12: error: no member named 'ldiv' in the global namespace
  return ::ldiv(__x, __y);
         ~~^
/opt/anaconda3/envs/pymc_env/bin/../include/c++/v1/stdlib.h:152:34: error: unknown type name 'lldiv_t'
inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
                                 ^
/opt/anaconda3/envs/pymc_env/bin/../include/c++/v1/stdlib.h:154:12: error: no member named 'lldiv' in the global namespace
  return ::lldiv(__x, __y);
         ~~^
In file included from /Users/stuartkerr/.pytensor/compiledir_macOS-14.5-arm64-arm-64bit-arm-3.12.3-64/tmpf0_ilt5x/mod.cpp:1:
In file included from /opt/anaconda3/envs/pymc_env/include/python3.12/Python.h:26:
/opt/anaconda3/envs/pymc_env/bin/../include/c++/v1/string.h:94:102: error: unknown type name 'size_t'
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const void* memchr(const void* __s, int __c, size_t __n) {
                                                                                                     ^
/opt/anaconda3/envs/pymc_env/bin/../include/c++/v1/string.h:97:90: error: unknown type name 'size_t'
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD void* memchr(void* __s, int __c, size_t __n) {
                                                                                         ^
In file included from /Users/stuartkerr/.pytensor/compiledir_macOS-14.5-arm64-arm-64bit-arm-3.12.3-64/tmpf0_ilt5x/mod.cpp:1:
/opt/anaconda3/envs/pymc_env/include/python3.12/Python.h:29:12: fatal error: 'unistd.h' file not found
#  include <unistd.h>
           ^~~~~~~~~~
7 errors generated.

Any hints regarding what is going wrong? Thank you…

CC @maresb @lucianopaz

So you have additional information from which to propose solutions, here is what follows the error panel previously provided (then the error panels basically repeat):

You can find the C code in this temporary file: /var/folders/9p/33r9p4353337m5957h9hdqmr0000gn/T/pytensor_compilation_error_94patoqs

thanks @ricardoV94 . Are @maresb @lucianopaz pymc-marketing experts?

Here is another error panel with more clues:

ERROR (pytensor.graph.rewriting.basic): Rewrite failure due to: constant_folding
ERROR (pytensor.graph.rewriting.basic): node: Cast{float64}(10)
ERROR (pytensor.graph.rewriting.basic): TRACEBACK:
ERROR (pytensor.graph.rewriting.basic): Traceback (most recent call last):
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/graph/rewriting/basic.py", line 1919, in process_node
    replacements = node_rewriter.transform(fgraph, node)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/graph/rewriting/basic.py", line 1081, in transform
    return self.fn(fgraph, node)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/tensor/rewriting/basic.py", line 1127, in constant_folding
    thunk = node.op.make_thunk(node, storage_map, compute_map, no_recycling=[])
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/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/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/link/c/op.py", line 84, in make_c_thunk
    outputs = cl.make_thunk(
              ^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/link/c/basic.py", line 1190, in make_thunk
    cthunk, module, in_storage, out_storage, error_storage = self.__compile__(
                                                             ^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/link/c/basic.py", line 1110, in __compile__
    thunk, module = self.cthunk_factory(
                    ^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/link/c/basic.py", line 1632, in cthunk_factory
    module = cache.module_from_key(key=key, lnk=self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/link/c/cmodule.py", line 1233, in module_from_key
    module = lnk.compile_cmodule(location)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/link/c/basic.py", line 1533, in compile_cmodule
    module = c_compiler.compile_str(
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/link/c/cmodule.py", line 2634, in compile_str
    raise CompileError(
pytensor.link.c.exceptions.CompileError: Compilation failed (return status=1):
/opt/anaconda3/envs/pymc_env/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 -fPIC -undefined dynamic_lookup -I/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/numpy/core/include -I/opt/anaconda3/envs/pymc_env/include/python3.12 -I/opt/anaconda3/envs/pymc_env/lib/python3.12/site-packages/pytensor/link/c/c_code -L/opt/anaconda3/envs/pymc_env/lib -fvisibility=hidden -o /Users/stuartkerr/.pytensor/compiledir_macOS-14.5-arm64-arm-64bit-arm-3.12.3-64/tmput_lye11/maf7dfc2b98019ae231490759913de9c7eae2cf26062201cb60a34079dffa7f98.so /Users/stuartkerr/.pytensor/compiledir_macOS-14.5-arm64-arm-64bit-arm-3.12.3-64/tmput_lye11/mod.cpp
In file included from /Users/stuartkerr/.pytensor/compiledir_macOS-14.5-arm64-arm-64bit-arm-3.12.3-64/tmput_lye11/mod.cpp:1:
In file included from /opt/anaconda3/envs/pymc_env/include/python3.12/Python.h:23:
/opt/anaconda3/envs/pymc_env/bin/../include/c++/v1/stdlib.h:148:34: error: unknown type name 'ldiv_t'
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
                                 ^
/opt/anaconda3/envs/pymc_env/bin/../include/c++/v1/stdlib.h:149:12: error: no member named 'ldiv' in the global namespace
  return ::ldiv(__x, __y);
         ~~^
/opt/anaconda3/envs/pymc_env/bin/../include/c++/v1/stdlib.h:152:34: error: unknown type name 'lldiv_t'
inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
                                 ^
/opt/anaconda3/envs/pymc_env/bin/../include/c++/v1/stdlib.h:154:12: error: no member named 'lldiv' in the global namespace
  return ::lldiv(__x, __y);
         ~~^
In file included from /Users/stuartkerr/.pytensor/compiledir_macOS-14.5-arm64-arm-64bit-arm-3.12.3-64/tmput_lye11/mod.cpp:1:
In file included from /opt/anaconda3/envs/pymc_env/include/python3.12/Python.h:26:
/opt/anaconda3/envs/pymc_env/bin/../include/c++/v1/string.h:94:102: error: unknown type name 'size_t'
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const void* memchr(const void* __s, int __c, size_t __n) {
                                                                                                     ^
/opt/anaconda3/envs/pymc_env/bin/../include/c++/v1/string.h:97:90: error: unknown type name 'size_t'
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD void* memchr(void* __s, int __c, size_t __n) {
                                                                                         ^
In file included from /Users/stuartkerr/.pytensor/compiledir_macOS-14.5-arm64-arm-64bit-arm-3.12.3-64/tmput_lye11/mod.cpp:1:
/opt/anaconda3/envs/pymc_env/include/python3.12/Python.h:29:12: fatal error: 'unistd.h' file not found
#  include <unistd.h>
           ^~~~~~~~~~
7 errors generated.

The problem has been solved. Let’s categorize this as “operator error.”

I kept the same instance of JupyterLab running while as i issued:

conda activate pymc_env

I was unaware that i had to close JupyterLab and relaunch via Anaconda.

Thanks to anyone who spent anytime looking at this issue; and really appreciate the great work put into pymc-marketing

4 Likes

One of the standard “checks” when something isn’t working in a notebook is to try running the same code via a script and/or in a terminal. Notebooks can often hide warnings and error messages. Selecting the intended kernel is also somewhat less obvious in a notebook setting. Glad you resolved it!