pymc-devs / pymc

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

Fitting radon model with bambi gives FileNotFoundError #6103

Closed martiningram closed 2 years ago

martiningram commented 2 years ago

Description of your problem

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

import pandas as pd
import bambi as bmb

df = pd.read_csv('./data.csv')
formula = 'y ~ x + u + (1 | county)'

model = bmb.Model(formula, df, family='gaussian')
model.fit()

Data file: data.csv

Please provide the full traceback.

Complete error traceback ```python --------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/vm.py:1246, in VMLinker.make_all(self, profiler, input_storage, output_storage, storage_map) 1242 # no-recycling is done at each VM.__call__ So there is 1243 # no need to cause duplicate c code by passing 1244 # no_recycling here. 1245 thunks.append( -> 1246 node.op.make_thunk(node, storage_map, compute_map, [], impl=impl) 1247 ) 1248 linker_make_thunk_time[node] = time.time() - thunk_start File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/c/op.py:131, in COp.make_thunk(self, node, storage_map, compute_map, no_recycling, impl) 130 try: --> 131 return self.make_c_thunk(node, storage_map, compute_map, no_recycling) 132 except (NotImplementedError, MethodNotDefined): 133 # We requested the c code, so don't catch the error. File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/c/op.py:96, in COp.make_c_thunk(self, node, storage_map, compute_map, no_recycling) 95 raise NotImplementedError("float16") ---> 96 outputs = cl.make_thunk( 97 input_storage=node_input_storage, output_storage=node_output_storage 98 ) 99 thunk, node_input_filters, node_output_filters = outputs File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/c/basic.py:1202, in CLinker.make_thunk(self, input_storage, output_storage, storage_map, cache, **kwargs) 1201 init_tasks, tasks = self.get_init_tasks() -> 1202 cthunk, module, in_storage, out_storage, error_storage = self.__compile__( 1203 input_storage, output_storage, storage_map, cache 1204 ) 1206 res = _CThunk(cthunk, init_tasks, tasks, error_storage, module) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/c/basic.py:1122, in CLinker.__compile__(self, input_storage, output_storage, storage_map, cache) 1121 output_storage = tuple(output_storage) -> 1122 thunk, module = self.cthunk_factory( 1123 error_storage, 1124 input_storage, 1125 output_storage, 1126 storage_map, 1127 cache, 1128 ) 1129 return ( 1130 thunk, 1131 module, (...) 1140 error_storage, 1141 ) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/c/basic.py:1634, in CLinker.cthunk_factory(self, error_storage, in_storage, out_storage, storage_map, cache) 1633 try: -> 1634 key = self.cmodule_key() 1635 except KeyError: File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/c/basic.py:1283, in CLinker.cmodule_key(self) 1211 """ 1212 Return a complete hashable signature of the module we compiled. 1213 (...) 1281 1282 """ -> 1283 return self.cmodule_key_( 1284 self.fgraph, 1285 self.no_recycling, 1286 compile_args=self.compile_args(), 1287 libraries=self.libraries(), 1288 header_dirs=self.header_dirs(), 1289 c_compiler=self.c_compiler(), 1290 ) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/c/basic.py:1462, in CLinker.cmodule_key_(self, fgraph, no_recycling, compile_args, libraries, header_dirs, insert_config_hash, c_compiler) 1461 if hasattr(node.op, "c_code_cache_version_apply"): -> 1462 version.append(node.op.c_code_cache_version_apply(node)) 1464 props = getattr(node.op, "__props__", None) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/c/interface.py:238, in CLinkerOp.c_code_cache_version_apply(self, node) 219 """Return a tuple of integers indicating the version of this `Op`. 220 221 An empty tuple indicates an "unversioned" `Op` that will not be (...) 236 237 """ --> 238 return self.c_code_cache_version() File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/tensor/blas_c.py:636, in CGemv.c_code_cache_version(self) 635 def c_code_cache_version(self): --> 636 return (14, blas_header_version(), check_force_gemv_init()) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/tensor/blas_c.py:685, in check_force_gemv_init() 665 test_code = """ 666 #include 667 extern "C" void dgemv_(char*, const int*, const int*, const double *, const double *, const int*, const double *, const int*, const double *, double *, const int *); (...) 680 } 681 """ 682 res = GCC_compiler.try_compile_tmp( 683 test_code, 684 tmp_prefix="check_beta_", --> 685 flags=ldflags(libs=True, flags=True, libs_dir=True), 686 try_run=True, 687 ) 688 if res: File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/tensor/blas.py:426, in ldflags(libs, flags, libs_dir, include_dir) 425 ldflags_str = config.blas__ldflags --> 426 return _ldflags( 427 ldflags_str=ldflags_str, 428 libs=libs, 429 flags=flags, 430 libs_dir=libs_dir, 431 include_dir=include_dir, 432 ) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/utils.py:287, in memoize..rval(*args, **kwargs) 286 if key not in cache: --> 287 val = f(*args, **kwargs) 288 cache[key] = val File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/tensor/blas.py:473, in _ldflags(ldflags_str, libs, flags, libs_dir, include_dir) 472 for d in dirs: --> 473 for f in os.listdir(d.strip('"')): 474 if f.endswith(".so") or f.endswith(".dylib") or f.endswith(".dll"): FileNotFoundError: [Errno 2] No such file or directory: '/opt/arm64-builds/lib' During handling of the above exception, another exception occurred: FileNotFoundError Traceback (most recent call last) Cell In [4], line 1 ----> 1 model.fit() File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/bambi/models.py:277, in Model.fit(self, draws, tune, discard_tuned_samples, omit_offsets, include_mean, inference_method, init, n_init, chains, cores, random_seed, **kwargs) 270 if isinstance(self.family, univariate.Bernoulli): 271 _log.info( 272 "Modeling the probability that %s==%s", 273 self.response.name, 274 str(self.response.success), 275 ) --> 277 return self.backend.run( 278 draws=draws, 279 tune=tune, 280 discard_tuned_samples=discard_tuned_samples, 281 omit_offsets=omit_offsets, 282 include_mean=include_mean, 283 inference_method=inference_method, 284 init=init, 285 n_init=n_init, 286 chains=chains, 287 cores=cores, 288 random_seed=random_seed, 289 **kwargs, 290 ) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/bambi/backend/pymc.py:94, in PyMCModel.run(self, draws, tune, discard_tuned_samples, omit_offsets, include_mean, inference_method, init, n_init, chains, cores, random_seed, **kwargs) 92 # NOTE: Methods return different types of objects (idata, approximation, and dictionary) 93 if inference_method in ["mcmc", "nuts_numpyro", "nuts_blackjax"]: ---> 94 result = self._run_mcmc( 95 draws, 96 tune, 97 discard_tuned_samples, 98 omit_offsets, 99 include_mean, 100 init, 101 n_init, 102 chains, 103 cores, 104 random_seed, 105 inference_method, 106 **kwargs, 107 ) 108 elif inference_method == "vi": 109 result = self._run_vi(**kwargs) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/bambi/backend/pymc.py:283, in PyMCModel._run_mcmc(self, draws, tune, discard_tuned_samples, omit_offsets, include_mean, init, n_init, chains, cores, random_seed, sampler_backend, **kwargs) 281 if sampler_backend == "mcmc": 282 try: --> 283 idata = pm.sample( 284 draws=draws, 285 tune=tune, 286 discard_tuned_samples=discard_tuned_samples, 287 init=init, 288 n_init=n_init, 289 chains=chains, 290 cores=cores, 291 random_seed=random_seed, 292 **kwargs, 293 ) 294 except (RuntimeError, ValueError): 295 if ( 296 "ValueError: Mass matrix contains" in traceback.format_exc() 297 and init == "auto" 298 ): File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/pymc/sampling.py:531, in sample(draws, step, init, n_init, initvals, trace, chain_idx, chains, cores, tune, progressbar, model, random_seed, discard_tuned_samples, compute_convergence_checks, callback, jitter_max_retries, return_inferencedata, idata_kwargs, mp_ctx, **kwargs) 528 auto_nuts_init = False 530 initial_points = None --> 531 step = assign_step_methods(model, step, methods=pm.STEP_METHODS, step_kwargs=kwargs) 533 if isinstance(step, list): 534 step = CompoundStep(step) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/pymc/sampling.py:229, in assign_step_methods(model, step, methods, step_kwargs) 221 selected = max( 222 methods, 223 key=lambda method, var=rv_var, has_gradient=has_gradient: method._competence( 224 var, has_gradient 225 ), 226 ) 227 selected_steps[selected].append(var) --> 229 return instantiate_steppers(model, steps, selected_steps, step_kwargs) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/pymc/sampling.py:147, in instantiate_steppers(model, steps, selected_steps, step_kwargs) 145 args = step_kwargs.get(step_class.name, {}) 146 used_keys.add(step_class.name) --> 147 step = step_class(vars=vars, model=model, **args) 148 steps.append(step) 150 unused_args = set(step_kwargs).difference(used_keys) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/pymc/step_methods/hmc/nuts.py:178, in NUTS.__init__(self, vars, max_treedepth, early_max_treedepth, **kwargs) 120 def __init__(self, vars=None, max_treedepth=10, early_max_treedepth=8, **kwargs): 121 r"""Set up the No-U-Turn sampler. 122 123 Parameters (...) 176 `pm.sample` to the desired number of tuning steps. 177 """ --> 178 super().__init__(vars, **kwargs) 180 self.max_treedepth = max_treedepth 181 self.early_max_treedepth = early_max_treedepth File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/pymc/step_methods/hmc/base_hmc.py:95, in BaseHMC.__init__(self, vars, scaling, step_scale, is_cov, model, blocked, potential, dtype, Emax, target_accept, gamma, k, t0, adapt_step_size, step_rand, **aesara_kwargs) 92 else: 93 vars = [self._model.rvs_to_values.get(var, var) for var in vars] ---> 95 super().__init__(vars, blocked=blocked, model=self._model, dtype=dtype, **aesara_kwargs) 97 self.adapt_step_size = adapt_step_size 98 self.Emax = Emax File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/pymc/step_methods/arraystep.py:276, in GradientSharedStep.__init__(self, vars, model, blocked, dtype, logp_dlogp_func, **aesara_kwargs) 273 model = modelcontext(model) 275 if logp_dlogp_func is None: --> 276 func = model.logp_dlogp_function(vars, dtype=dtype, **aesara_kwargs) 277 else: 278 func = logp_dlogp_func File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/pymc/model.py:641, in Model.logp_dlogp_function(self, grad_vars, tempered, **kwargs) 637 ip = self.initial_point(0) 638 extra_vars_and_values = { 639 var: ip[var.name] for var in extra_vars if var in input_vars and var not in grad_vars 640 } --> 641 return ValueGradFunction(costs, grad_vars, extra_vars_and_values, **kwargs) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/pymc/model.py:380, in ValueGradFunction.__init__(self, costs, grad_vars, extra_vars_and_values, dtype, casting, compute_grads, **kwargs) 376 outputs = [cost] 378 inputs = grad_vars --> 380 self._aesara_function = compile_pymc(inputs, outputs, givens=givens, **kwargs) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/pymc/aesaraf.py:1034, in compile_pymc(inputs, outputs, random_seed, mode, **kwargs) 1032 opt_qry = mode.provided_optimizer.including("random_make_inplace", check_parameter_opt) 1033 mode = Mode(linker=mode.linker, optimizer=opt_qry) -> 1034 aesara_function = aesara.function( 1035 inputs, 1036 outputs, 1037 updates={**rng_updates, **kwargs.pop("updates", {})}, 1038 mode=mode, 1039 **kwargs, 1040 ) 1041 return aesara_function File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/compile/function/__init__.py:317, in function(inputs, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input) 311 fn = orig_function( 312 inputs, outputs, mode=mode, accept_inplace=accept_inplace, name=name 313 ) 314 else: 315 # note: pfunc will also call orig_function -- orig_function is 316 # a choke point that all compilation must pass through --> 317 fn = pfunc( 318 params=inputs, 319 outputs=outputs, 320 mode=mode, 321 updates=updates, 322 givens=givens, 323 no_default_updates=no_default_updates, 324 accept_inplace=accept_inplace, 325 name=name, 326 rebuild_strict=rebuild_strict, 327 allow_input_downcast=allow_input_downcast, 328 on_unused_input=on_unused_input, 329 profile=profile, 330 output_keys=output_keys, 331 ) 332 return fn File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/compile/function/pfunc.py:374, in pfunc(params, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input, output_keys, fgraph) 360 profile = ProfileStats(message=profile) 362 inputs, cloned_outputs = construct_pfunc_ins_and_outs( 363 params, 364 outputs, (...) 371 fgraph=fgraph, 372 ) --> 374 return orig_function( 375 inputs, 376 cloned_outputs, 377 mode, 378 accept_inplace=accept_inplace, 379 name=name, 380 profile=profile, 381 on_unused_input=on_unused_input, 382 output_keys=output_keys, 383 fgraph=fgraph, 384 ) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/compile/function/types.py:1759, in orig_function(inputs, outputs, mode, accept_inplace, name, profile, on_unused_input, output_keys, fgraph) 1747 m = Maker( 1748 inputs, 1749 outputs, (...) 1756 fgraph=fgraph, 1757 ) 1758 with config.change_flags(compute_test_value="off"): -> 1759 fn = m.create(defaults) 1760 finally: 1761 t2 = time.time() File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/compile/function/types.py:1652, in FunctionMaker.create(self, input_storage, trustme, storage_map) 1649 start_import_time = aesara.link.c.cmodule.import_time 1651 with config.change_flags(traceback__limit=config.traceback__compile_limit): -> 1652 _fn, _i, _o = self.linker.make_thunk( 1653 input_storage=input_storage_lists, storage_map=storage_map 1654 ) 1656 end_linker = time.time() 1658 linker_time = end_linker - start_linker File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/basic.py:254, in LocalLinker.make_thunk(self, input_storage, output_storage, storage_map, **kwargs) 247 def make_thunk( 248 self, 249 input_storage: Optional["InputStorageType"] = None, (...) 252 **kwargs, 253 ) -> Tuple["BasicThunkType", "InputStorageType", "OutputStorageType"]: --> 254 return self.make_all( 255 input_storage=input_storage, 256 output_storage=output_storage, 257 storage_map=storage_map, 258 )[:3] File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/vm.py:1255, in VMLinker.make_all(self, profiler, input_storage, output_storage, storage_map) 1253 thunks[-1].lazy = False 1254 except Exception: -> 1255 raise_with_op(fgraph, node) 1257 t1 = time.time() 1259 if self.profile: File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/utils.py:534, in raise_with_op(fgraph, node, thunk, exc_info, storage_map) 529 warnings.warn( 530 f"{exc_type} error does not allow us to add an extra error message" 531 ) 532 # Some exception need extra parameter in inputs. So forget the 533 # extra long error message in that case. --> 534 raise exc_value.with_traceback(exc_trace) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/vm.py:1246, in VMLinker.make_all(self, profiler, input_storage, output_storage, storage_map) 1241 thunk_start = time.time() 1242 # no-recycling is done at each VM.__call__ So there is 1243 # no need to cause duplicate c code by passing 1244 # no_recycling here. 1245 thunks.append( -> 1246 node.op.make_thunk(node, storage_map, compute_map, [], impl=impl) 1247 ) 1248 linker_make_thunk_time[node] = time.time() - thunk_start 1249 if not hasattr(thunks[-1], "lazy"): 1250 # We don't want all ops maker to think about lazy Ops. 1251 # So if they didn't specify that its lazy or not, it isn't. 1252 # If this member isn't present, it will crash later. File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/c/op.py:131, in COp.make_thunk(self, node, storage_map, compute_map, no_recycling, impl) 127 self.prepare_node( 128 node, storage_map=storage_map, compute_map=compute_map, impl="c" 129 ) 130 try: --> 131 return self.make_c_thunk(node, storage_map, compute_map, no_recycling) 132 except (NotImplementedError, MethodNotDefined): 133 # We requested the c code, so don't catch the error. 134 if impl == "c": File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/c/op.py:96, in COp.make_c_thunk(self, node, storage_map, compute_map, no_recycling) 94 print(f"Disabling C code for {self} due to unsupported float16") 95 raise NotImplementedError("float16") ---> 96 outputs = cl.make_thunk( 97 input_storage=node_input_storage, output_storage=node_output_storage 98 ) 99 thunk, node_input_filters, node_output_filters = outputs 101 @is_cthunk_wrapper_type 102 def rval(): File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/c/basic.py:1202, in CLinker.make_thunk(self, input_storage, output_storage, storage_map, cache, **kwargs) 1167 """Compile this linker's `self.fgraph` and return a function that performs the computations. 1168 1169 The return values can be used as follows: (...) 1199 1200 """ 1201 init_tasks, tasks = self.get_init_tasks() -> 1202 cthunk, module, in_storage, out_storage, error_storage = self.__compile__( 1203 input_storage, output_storage, storage_map, cache 1204 ) 1206 res = _CThunk(cthunk, init_tasks, tasks, error_storage, module) 1207 res.nodes = self.node_order File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/c/basic.py:1122, in CLinker.__compile__(self, input_storage, output_storage, storage_map, cache) 1120 input_storage = tuple(input_storage) 1121 output_storage = tuple(output_storage) -> 1122 thunk, module = self.cthunk_factory( 1123 error_storage, 1124 input_storage, 1125 output_storage, 1126 storage_map, 1127 cache, 1128 ) 1129 return ( 1130 thunk, 1131 module, (...) 1140 error_storage, 1141 ) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/c/basic.py:1634, in CLinker.cthunk_factory(self, error_storage, in_storage, out_storage, storage_map, cache) 1617 """ 1618 Returns a thunk that points to an instance of a C struct that 1619 can carry on the computation of this linker's fgraph (...) 1631 type, value and traceback of the exception in error_storage. 1632 """ 1633 try: -> 1634 key = self.cmodule_key() 1635 except KeyError: 1636 key = None File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/c/basic.py:1283, in CLinker.cmodule_key(self) 1210 def cmodule_key(self): 1211 """ 1212 Return a complete hashable signature of the module we compiled. 1213 (...) 1281 1282 """ -> 1283 return self.cmodule_key_( 1284 self.fgraph, 1285 self.no_recycling, 1286 compile_args=self.compile_args(), 1287 libraries=self.libraries(), 1288 header_dirs=self.header_dirs(), 1289 c_compiler=self.c_compiler(), 1290 ) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/c/basic.py:1462, in CLinker.cmodule_key_(self, fgraph, no_recycling, compile_args, libraries, header_dirs, insert_config_hash, c_compiler) 1460 for node_pos, node in enumerate(order): 1461 if hasattr(node.op, "c_code_cache_version_apply"): -> 1462 version.append(node.op.c_code_cache_version_apply(node)) 1464 props = getattr(node.op, "__props__", None) 1466 if props: File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/link/c/interface.py:238, in CLinkerOp.c_code_cache_version_apply(self, node) 218 def c_code_cache_version_apply(self, node: Apply) -> Tuple[int, ...]: 219 """Return a tuple of integers indicating the version of this `Op`. 220 221 An empty tuple indicates an "unversioned" `Op` that will not be (...) 236 237 """ --> 238 return self.c_code_cache_version() File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/tensor/blas_c.py:636, in CGemv.c_code_cache_version(self) 635 def c_code_cache_version(self): --> 636 return (14, blas_header_version(), check_force_gemv_init()) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/tensor/blas_c.py:685, in check_force_gemv_init() 647 """ 648 Test issue 1569. 649 Namely when evaluating (...) 663 zeros. 664 """ 665 test_code = """ 666 #include 667 extern "C" void dgemv_(char*, const int*, const int*, const double *, const double *, const int*, const double *, const int*, const double *, double *, const int *); (...) 680 } 681 """ 682 res = GCC_compiler.try_compile_tmp( 683 test_code, 684 tmp_prefix="check_beta_", --> 685 flags=ldflags(libs=True, flags=True, libs_dir=True), 686 try_run=True, 687 ) 688 if res: 689 if res[0]: File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/tensor/blas.py:426, in ldflags(libs, flags, libs_dir, include_dir) 402 """Extract a list of compilation flags from config.blas__ldflags. 403 404 Depending on the options, different type of flags will be kept. (...) 423 424 """ 425 ldflags_str = config.blas__ldflags --> 426 return _ldflags( 427 ldflags_str=ldflags_str, 428 libs=libs, 429 flags=flags, 430 libs_dir=libs_dir, 431 include_dir=include_dir, 432 ) File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/utils.py:287, in memoize..rval(*args, **kwargs) 285 key = (args, kwtup) 286 if key not in cache: --> 287 val = f(*args, **kwargs) 288 cache[key] = val 289 else: File ~/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/aesara/tensor/blas.py:473, in _ldflags(ldflags_str, libs, flags, libs_dir, include_dir) 465 l = _ldflags( 466 ldflags_str=ldflags_str, 467 libs=True, (...) 470 include_dir=False, 471 ) 472 for d in dirs: --> 473 for f in os.listdir(d.strip('"')): 474 if f.endswith(".so") or f.endswith(".dylib") or f.endswith(".dll"): 475 if any(f.find(ll) >= 0 for ll in l): FileNotFoundError: [Errno 2] No such file or directory: '/opt/arm64-builds/lib' Apply node that caused the error: CGemv{no_inplace}(y{[ 0.7885 .. 1.0647]}, TensorConstant{-1.0}, TensorConstant{[[ 0.83351..48700696]]}, Join.0, (d__logp/d1|county_sigma_log___logprob){1.0}) Toposort index: 15 Inputs types: [TensorType(float64, (919,)), TensorType(float64, ()), TensorType(float64, (919, 2)), TensorType(float64, (None,)), TensorType(float64, ())] HINT: Use a linker other than the C linker to print the inputs' shapes and strides. HINT: Re-running with most Aesara optimizations disabled could provide a back-trace showing when this node was created. This can be done by setting the Aesara flag 'optimizer=fast_compile'. If that does not work, Aesara optimizations can be disabled with 'optimizer=None'. HINT: Use the Aesara flag `exception_verbosity=high` for a debug print-out and storage map footprint of this Apply node. ```

Please provide any additional information below.

This uses fresh installations of both pymc and bambi, and I'm a bit stumped. I installed pymc with conda-forge as recommended, then bambi using pip.

I do run an ARM machine, and am currently using python 3.8 because I plan to install an older package later that requires it; maybe that's causing issues? I tried another, non-bambi model also, and that worked fine, so could also be bambi-specific.

Thanks for your help!

Versions and main components

ricardoV94 commented 2 years ago

Sounds like an installation gone wrong

maresb commented 2 years ago

Interesting, thanks for the report!!!

It looks like somehow BLAS is being improperly configured. Perhaps something is polluting the environment, like some stray environment variables. To isolate the problem a bit more, let's think about:

from aesara import config
print(config.blas__ldflags)

On Linux with the same package specifications, I see

-L/home/mares/micromamba/envs/pymc/lib -lcblas -lblas -lcblas -lblas

but from the traceback it seems like on your system the directory is configured to be the nonexistent /opt/arm64-builds/lib.

So I think the real question is where is that nonexistent directory coming from? The logic to compute this is a little complicated, but we should be able to see mostly what's going on with

import sys
import numpy as np
print(np.__config__.get_info("blas_opt"))
print(sys.prefix)
print(sys.version)

For me, this gives

{'define_macros': [('NO_ATLAS_INFO', 1), ('HAVE_CBLAS', None)], 'libraries': ['cblas', 'blas', 'cblas', 'blas'], 'library_dirs': ['/home/mares/micromamba/envs/pymc/lib'], 'include_dirs': ['/home/mares/micromamba/envs/pymc/include'], 'language': 'c'}
/home/mares/micromamba/envs/pymc
3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:18) 
[GCC 10.3.0]
martiningram commented 2 years ago

Hi @maresb , thank you very much for looking into this! I ran your two commands; the first:

from aesara import config
print(config.blas__ldflags)

gives:

-L/opt/arm64-builds/lib -lopenblas -lopenblas -Wl,-rpath,/opt/arm64-builds/lib -Wl,-rpath,/Users/martin.ingram/miniconda3/envs/pymc_problem/lib

The second:

import sys
import numpy as np
print(np.__config__.get_info("blas_opt"))
print(sys.prefix)
print(sys.version)

gives:

{'libraries': ['openblas', 'openblas'], 'library_dirs': ['/opt/arm64-builds/lib'], 'language': 'c', 'define_macros': [('HAVE_CBLAS', None)], 'runtime_library_dirs': ['/opt/arm64-builds/lib']}
/Users/martin.ingram/miniconda3/envs/pymc_problem
3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:05:16) 
[Clang 12.0.1 ]

I checked and, indeed, it seems like /opt/arm64-builds/lib does not exist. In fact, neither does /opt/arm64-builds. I hope this helps -- is it looking for BLAS in the wrong place?

Thanks again and all the best, Martin

maresb commented 2 years ago

Yes, that's very interesting, thanks Martin!

To continue narrowing this down, could you please run

python -c 'import numpy.__config__ as c; print(c.__file__)'

What is the path of this file?

maresb commented 2 years ago

Could you also please provide the output of the following?

conda list
martiningram commented 2 years ago

Certainly! Here's the output of the first:

/Users/martin.ingram/miniconda3/envs/pymc_problem/lib/python3.8/site-packages/numpy/__config__.py

And here's the output of the second:

# packages in environment at /Users/martin.ingram/miniconda3/envs/pymc_problem:
#
# Name                    Version                   Build  Channel
aeppl                     0.0.35             pyhd8ed1ab_0    conda-forge
aeppl-base                0.0.35             pyhd8ed1ab_0    conda-forge
aesara                    2.8.2            py38h50f692f_0    conda-forge
aesara-base               2.8.2            py38h10201cd_0    conda-forge
appnope                   0.1.3              pyhd8ed1ab_0    conda-forge
argon2-cffi               21.3.0             pyhd8ed1ab_0    conda-forge
argon2-cffi-bindings      21.2.0           py38h33210d7_2    conda-forge
arviz                     0.12.1             pyhd8ed1ab_1    conda-forge
asttokens                 2.0.8              pyhd8ed1ab_0    conda-forge
attrs                     22.1.0             pyh71513ae_1    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                        py_2    conda-forge
backports.functools_lru_cache 1.6.4              pyhd8ed1ab_0    conda-forge
bambi                     0.9.1                    pypi_0    pypi
beautifulsoup4            4.11.1             pyha770c72_0    conda-forge
blas                      2.116                  openblas    conda-forge
blas-devel                3.9.0           16_osxarm64_openblas    conda-forge
bleach                    5.0.1              pyhd8ed1ab_0    conda-forge
brotli                    1.0.9                h1c322ee_7    conda-forge
brotli-bin                1.0.9                h1c322ee_7    conda-forge
bzip2                     1.0.8                h3422bc3_4    conda-forge
c-ares                    1.18.1               h3422bc3_0    conda-forge
c-compiler                1.5.0                h5008568_0    conda-forge
ca-certificates           2022.6.15            h4653dfc_0    conda-forge
cachetools                5.2.0              pyhd8ed1ab_0    conda-forge
cctools                   973.0.1             hcbb26d4_10    conda-forge
cctools_osx-arm64         973.0.1             he930820_10    conda-forge
certifi                   2022.6.15          pyhd8ed1ab_1    conda-forge
cffi                      1.15.1           py38h0e10f82_0    conda-forge
cftime                    1.6.1            py38hd91e067_0    conda-forge
clang                     14.0.4               hce30654_0    conda-forge
clang-14                  14.0.4          default_h81a5282_0    conda-forge
clang_osx-arm64           14.0.4               hc634a12_2    conda-forge
clangxx                   14.0.4          default_hb7ecf47_0    conda-forge
clangxx_osx-arm64         14.0.4               hb7a33d8_2    conda-forge
cloudpickle               2.1.0              pyhd8ed1ab_0    conda-forge
compiler-rt               14.0.4               h4418234_0    conda-forge
compiler-rt_osx-arm64     14.0.4               hb07f8d1_0    conda-forge
cons                      0.4.5              pyhd8ed1ab_0    conda-forge
curl                      7.83.1               h7965298_0    conda-forge
cxx-compiler              1.5.0                hffc8910_0    conda-forge
cycler                    0.11.0             pyhd8ed1ab_0    conda-forge
debugpy                   1.6.3            py38hdba0465_0    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
defusedxml                0.7.1              pyhd8ed1ab_0    conda-forge
entrypoints               0.4                pyhd8ed1ab_0    conda-forge
etuples                   0.3.8              pyhd8ed1ab_0    conda-forge
executing                 1.0.0              pyhd8ed1ab_0    conda-forge
fastprogress              1.0.3              pyhd8ed1ab_0    conda-forge
filelock                  3.8.0              pyhd8ed1ab_0    conda-forge
flit-core                 3.7.1              pyhd8ed1ab_0    conda-forge
fonttools                 4.37.1           py38hb991d35_0    conda-forge
formulae                  0.3.4                    pypi_0    pypi
freetype                  2.12.1               hd633e50_0    conda-forge
hdf4                      4.2.15               hc683e77_4    conda-forge
hdf5                      1.12.2          nompi_h33dac16_100    conda-forge
icu                       70.1                 h6b3803e_0    conda-forge
importlib-metadata        4.11.4           py38h10201cd_0    conda-forge
importlib_resources       5.9.0              pyhd8ed1ab_0    conda-forge
ipykernel                 6.15.2             pyh736e0ef_0    conda-forge
ipython                   8.5.0              pyhd1c38e8_1    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
ipywidgets                8.0.2              pyhd8ed1ab_1    conda-forge
jedi                      0.18.1             pyhd8ed1ab_2    conda-forge
jinja2                    3.1.2              pyhd8ed1ab_1    conda-forge
jpeg                      9e                   he4db4b2_2    conda-forge
jsonschema                4.15.0             pyhd8ed1ab_0    conda-forge
jupyter                   1.0.0            py38h10201cd_7    conda-forge
jupyter_client            7.3.5              pyhd8ed1ab_0    conda-forge
jupyter_console           6.4.4              pyhd8ed1ab_0    conda-forge
jupyter_core              4.11.1           py38h10201cd_0    conda-forge
jupyterlab_pygments       0.2.2              pyhd8ed1ab_0    conda-forge
jupyterlab_widgets        3.0.3              pyhd8ed1ab_0    conda-forge
kiwisolver                1.4.4            py38haa2428a_0    conda-forge
krb5                      1.19.3               he492e65_0    conda-forge
lcms2                     2.12                 had6a04f_0    conda-forge
ld64                      609                 h619f069_10    conda-forge
ld64_osx-arm64            609                 h132958c_10    conda-forge
lerc                      4.0.0                h9a09cb3_0    conda-forge
libblas                   3.9.0           16_osxarm64_openblas    conda-forge
libbrotlicommon           1.0.9                h1c322ee_7    conda-forge
libbrotlidec              1.0.9                h1c322ee_7    conda-forge
libbrotlienc              1.0.9                h1c322ee_7    conda-forge
libcblas                  3.9.0           16_osxarm64_openblas    conda-forge
libclang-cpp14            14.0.4          default_h81a5282_0    conda-forge
libcurl                   7.83.1               h7965298_0    conda-forge
libcxx                    14.0.6               h2692d47_0    conda-forge
libdeflate                1.13                 h57fd34a_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_25    conda-forge
libgfortran5              11.3.0              hdaf2cc0_25    conda-forge
libiconv                  1.16                 h642e427_0    conda-forge
liblapack                 3.9.0           16_osxarm64_openblas    conda-forge
liblapacke                3.9.0           16_osxarm64_openblas    conda-forge
libllvm14                 14.0.4               h37c5ba8_0    conda-forge
libnetcdf                 4.8.1           nompi_h996a5af_104    conda-forge
libnghttp2                1.47.0               h519802c_1    conda-forge
libopenblas               0.3.21          openmp_hc731615_3    conda-forge
libpng                    1.6.37               h9b2ccdc_4    conda-forge
libsodium                 1.0.18               h27ca646_1    conda-forge
libsqlite                 3.39.3               h76d750c_0    conda-forge
libssh2                   1.10.0               h7a5bd25_3    conda-forge
libtiff                   4.4.0                hd6ca8d7_3    conda-forge
libwebp-base              1.2.4                h57fd34a_0    conda-forge
libxcb                    1.13              h9b22ae9_1004    conda-forge
libxml2                   2.9.14               h9d8dfc2_4    conda-forge
libxslt                   1.1.35               ha8fb468_0    conda-forge
libzip                    1.9.2                h76ab92c_1    conda-forge
libzlib                   1.2.12               ha287fd2_2    conda-forge
llvm-openmp               14.0.4               hd125106_0    conda-forge
llvm-tools                14.0.4               h37c5ba8_0    conda-forge
logical-unification       0.4.5              pyhd8ed1ab_0    conda-forge
lxml                      4.9.1            py38he5c2ac2_0    conda-forge
markupsafe                2.1.1            py38h33210d7_1    conda-forge
matplotlib-base           3.5.3            py38h4399b95_2    conda-forge
matplotlib-inline         0.1.6              pyhd8ed1ab_0    conda-forge
minikanren                1.0.3              pyhd8ed1ab_0    conda-forge
mistune                   2.0.4              pyhd8ed1ab_0    conda-forge
multipledispatch          0.6.0                      py_0    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
nbclient                  0.6.7              pyhd8ed1ab_0    conda-forge
nbconvert                 7.0.0              pyhd8ed1ab_0    conda-forge
nbconvert-core            7.0.0              pyhd8ed1ab_0    conda-forge
nbconvert-pandoc          7.0.0              pyhd8ed1ab_0    conda-forge
nbformat                  5.4.0              pyhd8ed1ab_0    conda-forge
ncurses                   6.3                  h07bb92c_1    conda-forge
nest-asyncio              1.5.5              pyhd8ed1ab_0    conda-forge
netcdf4                   1.6.0           nompi_py38hce67723_102    conda-forge
notebook                  6.4.12             pyha770c72_0    conda-forge
numpy                     1.21.6                   pypi_0    pypi
openblas                  0.3.21          openmp_hf78f355_3    conda-forge
openjpeg                  2.5.0                h5d4e404_1    conda-forge
openssl                   3.0.5                h7aea29f_1    conda-forge
packaging                 21.3               pyhd8ed1ab_0    conda-forge
pandas                    1.4.4            py38h2a4bfaf_0    conda-forge
pandoc                    2.12                 hca03da5_0  
pandocfilters             1.5.0              pyhd8ed1ab_0    conda-forge
parso                     0.8.3              pyhd8ed1ab_0    conda-forge
pexpect                   4.8.0              pyh9f0ad1d_2    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    9.2.0            py38h96fe7ce_2    conda-forge
pip                       22.2.2             pyhd8ed1ab_0    conda-forge
pkgutil-resolve-name      1.3.10             pyhd8ed1ab_0    conda-forge
prometheus_client         0.14.1             pyhd8ed1ab_0    conda-forge
prompt-toolkit            3.0.31             pyha770c72_0    conda-forge
prompt_toolkit            3.0.31               hd8ed1ab_0    conda-forge
psutil                    5.9.2            py38hb991d35_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
pygments                  2.13.0             pyhd8ed1ab_0    conda-forge
pymc                      4.1.7                hd8ed1ab_0    conda-forge
pymc-base                 4.1.7              pyhd8ed1ab_0    conda-forge
pyparsing                 3.0.9              pyhd8ed1ab_0    conda-forge
pyrsistent                0.18.1           py38h33210d7_1    conda-forge
python                    3.8.13          hd3575e6_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python-fastjsonschema     2.16.1             pyhd8ed1ab_0    conda-forge
python_abi                3.8                      2_cp38    conda-forge
pytz                      2022.2.1           pyhd8ed1ab_0    conda-forge
pyzmq                     23.2.1           py38h6a7385f_0    conda-forge
readline                  8.1.2                h46ed386_0    conda-forge
scipy                     1.9.1            py38h3aeb131_0    conda-forge
send2trash                1.8.0              pyhd8ed1ab_0    conda-forge
setuptools                65.3.0             pyhd8ed1ab_1    conda-forge
sigtool                   0.1.3                h44b9a77_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
soupsieve                 2.3.2.post1        pyhd8ed1ab_0    conda-forge
sqlite                    3.39.3               h2229b38_0    conda-forge
stack_data                0.5.0              pyhd8ed1ab_0    conda-forge
tapi                      1100.0.11            he4954df_0    conda-forge
terminado                 0.15.0           py38h10201cd_0    conda-forge
tinycss2                  1.1.1              pyhd8ed1ab_0    conda-forge
tk                        8.6.12               he1e0b03_0    conda-forge
toolz                     0.12.0             pyhd8ed1ab_0    conda-forge
tornado                   6.2              py38he5c2ac2_0    conda-forge
traitlets                 5.3.0              pyhd8ed1ab_0    conda-forge
typing-extensions         4.3.0                hd8ed1ab_0    conda-forge
typing_extensions         4.3.0              pyha770c72_0    conda-forge
unicodedata2              14.0.0           py38h33210d7_1    conda-forge
wcwidth                   0.2.5              pyh9f0ad1d_2    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.37.1             pyhd8ed1ab_0    conda-forge
widgetsnbextension        4.0.3              pyhd8ed1ab_0    conda-forge
xarray                    2022.6.0           pyhd8ed1ab_1    conda-forge
xarray-einstats           0.3.0              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
zeromq                    4.3.4                hbdafb3b_1    conda-forge
zipp                      3.8.1              pyhd8ed1ab_0    conda-forge
zstd                      1.5.2                h8128057_4    conda-forge
maresb commented 2 years ago

Aha! It appears that your numpy has been clobbered by pip.

bambi                     0.9.1                    pypi_0    pypi
formulae                  0.3.4                    pypi_0    pypi
numpy                     1.21.6                   pypi_0    pypi
maresb commented 2 years ago

You may be able to fix it with conda install bambi.

maresb commented 2 years ago

Also, your environment is pretty big. I'd highly recommend using mamba as a drop-in replacement for conda. It's way faster.

martiningram commented 2 years ago

Hi @maresb , looks like you were right on the money -- it works if I use conda instead! And I'll have to check out mamba thanks, conda is certainly slow sometimes... Thank you very much for your quick help and for solving this problem!

I'll close this now, but if you don't mind, just so I understand: was the problem that pip installed a second version of numpy, which expected BLAS to be in a certain place, while conda had actually installed it somewhere else?

maresb commented 2 years ago

Hi @martiningram, glad I could help!

The problem was that pip uninstalled the conda-forge version of numpy and installed its own. While a Conda package can provide a Python package, a Python package cannot provide a Conda package (since Conda packages have additional structure). Thus conda and pip are not really aware of what each other are doing. I don't know precisely what led to the error, but my guess is that the Conda package for NumPy has some post-install and activation magic (and possibly even a monkey-patch) which ensures the paths are set correctly, and when pip downgrades numpy this magic is somehow lost.

To avoid these sorts of problems, the recommendation is to avoid using pip (except for editable installs of a package under development) and favor installing with conda/mamba instead. In case you do need to use pip because, for example, a PyPI package doesn't exist or is broken on conda-forge, it's best to make sure all the dependencies have already been installed with conda/mamba. To accomplish that, you can make use of pip's flags like --dry-run and --no-deps, and verify consistency with pip check.

(And in case a package doesn't exist or is broken, you can create a recipe and submit it, and if a package is broken you can file an issue in the corresponding feedstock, and get support on the website and Gitter.)

As for why pip was uninstalling NumPy, it's because bambi's current requirements don't allow for the latest version of NumPy so a downgrade is necessary. But thanks to @aloctavodia, the latest NumPy will be allowed in the next Bambi release.

martiningram commented 2 years ago

I see -- thanks a lot for the detailed explanation @maresb , and for fixing the issue! 😊