How to run Stan diagnose binary using StanSample.jl

Hello,

I am trying to run Stan’s diagnose binary on a model. Unfortunately, I am getting an error. Here is some reproducible code using the example bernoulli model.

using StanSample, DataFrames

ProjDir = @__DIR__

bernoulli_model = "
data {
  int<lower=1> N;
  int<lower=0,upper=1> y[N];
}
parameters {
  real<lower=0,upper=1> theta;
}
model {
  theta ~ beta(1,1);
  y ~ bernoulli(theta);
}
";

data = Dict("N" => 10, "y" => [0, 1, 0, 1, 0, 0, 0, 0, 0, 1])

# Keep tmpdir across multiple runs to prevent re-compilation
tmpdir = joinpath(ProjDir, "tmp")
isdir(tmpdir) &&  rm(tmpdir; recursive=true)

sm = SampleModel("bernoulli", bernoulli_model, tmpdir);

rc = stan_sample(sm; data);

if success(rc)
  diagnose(sm)
end

Unfortunately, I get this error message:

Base.IOError("could not spawn `/Users/stephenwild/cmdstan/bin/diagnose /Users/stephenwild/Desktop/Stats_stuff/State_space/tmp/bernoulli_chain_1.csv /Users/stephenwild/Desktop/Stats_stuff/State_space/tmp/bernoulli_chain_2.csv /Users/stephenwild/Desktop/Stats_stuff/State_space/tmp/bernoulli_chain_3.csv /Users/stephenwild/Desktop/Stats_stuff/State_space/tmp/bernoulli_chain_4.csv`: no such file or directory (ENOENT)", -2)

I tried using StanDiagnose.jl, but was also unsuccessful.

What code do I need to run Stan’s diagnose binary on a model?

Have you installed CmdStan already? StanSample assumes that it’s already installed in the location specified by the CMDSTAN environment variable (or equivalent in the Julia config file).

The error implies that there’s no file at /Users/stephenwild/cmdstan/bin/diagnose, so you probably have to either install cmdstan to /Users/stephenwild/cmdstan or update the CMDSTAN environment variable to point to where you did install it.

Thanks for the quick answer.

I have installed it, and I’ve successfully run a bunch of models with StanSample.jl. But I haven’t been able to run diagnose on them. That is why I find it weird.

For whatever reason, this round of cleaning and rebuilding cmdstan worked. I can now use diagnose. Not sure why it didn’t work earlier, even when I followed the instructions here.