Hi, I am working on advi from cmdstanpy to run a toy stan model in python using Linux. But I failed in compiling the model with lengthy error output which really confused me. I will list my workflow and part of error output. Would you mind double-checking if any part goes wrong? I really appreciate your help!
Here is the linux command part, I load gcc 11.2.0 and python first.
ml gcc/11.2.0
ml python3/3.8.10
import os
import cmdstanpy
from cmdstanpy import CmdStanModel
def main():
stan_file = 'bernoulli.stan'
print(stan_file)
model = CmdStanModel(stan_file=stan_file)
save_path = "adviResults/"
isExist = os.path.exists(save_path)
if not isExist:
os.makedirs(save_path)
print("The new directory is created!")
data = {
"N" : 10,
"y" : [0,1,0,0,0,0,0,0,0,1]
}
fit = model.variational(data = data, output_dir = save_path)
if __name__ == '__main__':
main()
and here is the stan code
data {
int<lower=0> N;
int<lower=0,upper=1> y[N];
}
parameters {
real<lower=0,upper=1> theta;
}
model {
theta ~ beta(1,1); // uniform prior on interval 0,1
y ~ bernoulli(theta);
}
Traceback (most recent call last):
File “advi_test.py”, line 26, in
main()
File “advi_test.py”, line 11, in main
model = CmdStanModel(stan_file=stan_file)
File “/projectnb/mutsigs/venvs/mynewenv2/lib/python3.8/site-packages/cmdstanpy/model.py”, line 236, in init
self.compile(force=str(compile).lower() == ‘force’)
File “/projectnb/mutsigs/venvs/mynewenv2/lib/python3.8/site-packages/cmdstanpy/model.py”, line 563, in compile
raise ValueError(
ValueError: Failed to compile Stan model ‘/projectnb/mutsigs/mutsigsfb/haoyuefeng/FlankingBases/scripts/python/bernoulli.stan’. Console:
/share/pkg.7/gcc/11.2.0/install/bin/gcc -Wl,-L,“/usr4/ma751/fengx456/.cmdstan/cmdstan-2.31.0/stan/lib/stan_math/lib/tbb” -Wl,-rpath,“/usr4/ma751/fengx45
6/.cmdstan/cmdstan-2.31.0/stan/lib/stan_math/lib/tbb” /projectnb/mutsigs/mutsigsfb/haoyuefeng/FlankingBases/scripts/python/bernoulli.o -Wl,-L,“/us
r4/ma751/fengx456/.cmdstan/cmdstan-2.31.0/stan/lib/stan_math/lib/tbb” -Wl,-rpath,“/usr4/ma751/fengx456/.cmdstan/cmdstan-2.31.0/stan/lib/stan_math/lib/tbb” -o
/projectnb/mutsigs/mutsigsfb/haoyuefeng/FlankingBases/scripts/python/bernoulli
/lib/…/lib64/crt1.o: In function _start': (.text+0x20): undefined reference to
main’