Bug with init argument, json file and num_chains>1, cmdstan 2.28.1

I think there is a bug (or a strange error message) when specifying num_chains=x with x>1 and additionally init=inits.json

What works
Bernoulli example:

./bernoulli sample num_chains=1 data file=bernoulli.data.json init=theta_inits.json

with theta_inits.json:

{
  "theta": [0.5]
}

This also works:

./bernoulli sample num_chains=4 data file=bernoulli.data.json init=10

What DOESN’T work

./bernoulli sample num_chains=4 data file=bernoulli.data.json init=theta_inits.json

I get the error message:

file ending of .json is not supported by cmdstan

Which is a bit strange since in the docs it says .json is basically the only extension that is supported (besides Rdump, but I don’t really know how that works).

I tried for theta_inits.json

{
  "theta": [0.5]
}

and

{
  {
    "theta": [0.5]
  },
  {
    "theta": [0.5]
  },
  {
    "theta": [0.5]
  },
  {
    "theta": [0.5]
  }
}

Is this a bug or do I just not know how to make multi-chain inits work with a json file?

Here is the full error output:

method = sample (Default)
  sample
    num_samples = 1000 (Default)
    num_warmup = 1000 (Default)
    save_warmup = 0 (Default)
    thin = 1 (Default)
    adapt
      engaged = 1 (Default)
      gamma = 0.050000000000000003 (Default)
      delta = 0.80000000000000004 (Default)
      kappa = 0.75 (Default)
      t0 = 10 (Default)
      init_buffer = 75 (Default)
      term_buffer = 50 (Default)
      window = 25 (Default)
    algorithm = hmc (Default)
      hmc
        engine = nuts (Default)
          nuts
            max_depth = 10 (Default)
        metric = diag_e (Default)
        metric_file =  (Default)
        stepsize = 1 (Default)
        stepsize_jitter = 0 (Default)
    num_chains = 4
id = 1 (Default)
data
  file = bernoulli.data.json
init = theta_inits_1.json
random
  seed = 727596610 (Default)
output
  file = output.csv (Default)
  diagnostic_file =  (Default)
  refresh = 100 (Default)
  sig_figs = -1 (Default)
  profile_file = profile.csv (Default)
num_threads = 1 (Default)

file ending of .json is not supported by cmdstan

I am guessing you need to create 4 files: theta_inits_1.json, theta_inits_2.json, … but specify the file as you have with theta_inits.json

1 Like

Thank you for the quick answer! That doesn’t seem work either unfortunately. I have 4 files now,
theta_inits_[1-4].json, that are all the same:

{
  "theta": [0.5]
}

I get the same error message still

file ending of .json is not supported by cmdstan

By the way, I also tried replacing the { by [ in the above multi-chain example, but to no avail:

[
  {
    "theta": [0.5]
  },
  {
    "theta": [0.5]
  },
  {
    "theta": [0.5]
  },
  {
    "theta": [0.5]
  }
]

Dug a bit deeper, this is actually a bug :/

This line cmdstan/command.hpp at develop · stan-dev/cmdstan · GitHub
should have a && not ||.

1 Like

Great, so it’s fixable! Thank you for taking the time to check, I’ll wait for the next release then!

No, thank YOU for the report!! I was shocked we don’t have a test for this case.

Made an issue: Unable to set init files with num_chains > 1 · Issue #1058 · stan-dev/cmdstan · GitHub

This is a pretty big one and because we also found another one for the 2.28.1 release there will be another patch release this week or the next.