stan-dev/cmdstanpy

Multiple inits files incorrectly processed when running multiple chains in one executable

WardBrian opened this issue · 1 comments

Summary:

Make two inits files, inits1.json and inits2.json. They can both just contain {}.
Run

import os
from cmdstanpy import CmdStanModel, cmdstan_path
bernoulli_dir = os.path.join(cmdstan_path(), 'examples', 'bernoulli')
stan_file = os.path.join(bernoulli_dir, 'bernoulli.stan')
model = CmdStanModel(stan_file=stan_file)
data = {"N": 10, "y": [0, 1, 0, 0, 0, 0, 0, 0, 0, 1]}
model.sample(data=data, chains=2, inits=['inits1.json', 'inits2.json'], output_dir='.', force_one_process_per_chain=False)

Open the resulting output files, both will have used inits1.json

To make this even more obvious, you can make inits2.json contain something that would fail to initialize, like {'theta':4.0}

Additional Information:

This is related to #362 and #685

Oh, the correct behavior is worth noting:

You need a base filename, like init.json, which can be used to "infer" the filenames per chain, which look like init_1.json, init_2.json

This isn't too hard to make work, but getting it to collaborate with the historical multiprocessing approach is belabored.