I am learning pystan and I tried to run the following code, which I copy-pasted from here:
#/my_file.py
import pystan as ps
import numpy as np
model = """
data {
int<lower=0> N;
vector[N] x;
vector[N] y;
}
parameters {
real alpha;
real beta;
real<lower=0> sigma;
}
model {
y ~ normal(alpha + beta * x, sigma);
}
"""
# Parameters to be inferred
alpha = 4.0
beta = 0.5
sigma = 1.0
np.random.seed(101)
# Generate and plot data
x = 10 * np.random.rand(100)
y = alpha + beta * x
y = np.random.normal(y, scale=sigma)
# Put our data in a dictionary
data = {'N': len(x), 'x': x, 'y': y}
# Compile the model
sm = ps.StanModel(model_code=model)
When I run it with python3 my_file.py
I get
INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_(long hash) NOW.
Segmentation fault (core dumped)
It has been impossible to run it in a NoteBook, it is just worst.
I have tried other tutorials with the same outcome.
I have tried to track the problem with a debugger, and the code stops in the file /pystan/model.py, at the line 384:
self.module = load_module(self.module_name, lib_dir)
When I jump into load_module, it stops in return __import__(module_name)
, after which I fall in a rabbit hole (I get lost), and the debugger log message is long and incomprehensible to me. For example, in one line it states: AttributeError: partially initialized module 'matplotlib' has no attribute 'rcParams' (most likely due to a circular import)
OS: Ubuntu
I installed pystan using a YML file like:
name: bayesian
channels:
- defaults
dependencies:
- python=3.9
- numpy
- pystan
- matplotlib
...