Provinding Pathfinder with Initial Values

Hello!

I am using pathfinder in CmdStanPy 1.2.2 and CmdStan 2.34.1. I tried to provide initial values as a list of strings, each string being the path to json file containing the initial values per (pathfinder) path (as stated in the API Reference: list of strings - per-path pathname to data file.)

#----- Write initial values ----#

stan_inits = {
              'i_MP' : 20,
              'b0' : 6,
              'sigma0' : sigma,
              'T_i' : 100
              }

init_files = []
for path_num in range(1, 5):
    init_file = join(homedir, "initfile_{}.json".format(path_num))
    with open(init_file, "w") as f:
        json.dump(stan_inits, f)
    init_files.append(init_file)

#----- Compile the model and fit ------#

compiled_model = CmdStanModel(stan_file = join(homedir, 'main/{}.stan'.format(HMM_model_name)), cpp_options = {'STAN_THREADS':'true', 'STAN_OPENCL':'true', 'INTEGRATED_OPENCL':'true'}, force_compile = True)

print("init files: " , init_files)
print("type : ", type(init_files))

FIT = compiled_model.pathfinder(data = data, show_console = True, num_paths = 4, inits = init_files)

The output of the print statements is the following:

init files:  ['/home/ilambert/SunTag_HMM/initfile_1.json', '/home/ilambert/SunTag_HMM/initfile_2.json', '/home/ilambert/SunTag_HMM/initfile_3.json', '/home/ilambert/SunTag_HMM/initfile_4.json']
type :  <class 'list'>

as expected. However I get the following error:

Traceback (most recent call last):
  File "main/stan_regression_HMM_on_simu_jed_gpu.py", line 232, in <module>
    FIT = compiled_model.pathfinder(data = data, show_console = True, num_paths = 4, inits = init_files)
  File "/home/ilambert/.local/lib/python3.8/site-packages/cmdstanpy/model.py", line 1793, in pathfinder
    args = CmdStanArgs(
  File "/home/ilambert/.local/lib/python3.8/site-packages/cmdstanpy/cmdstan_args.py", line 798, in __init__
    self.validate()
  File "/home/ilambert/.local/lib/python3.8/site-packages/cmdstanpy/cmdstan_args.py", line 935, in validate
    raise ValueError('no such file {}'.format(self.inits))
ValueError: no such file /tmp/tmppcjguuoa/tfq6nxx9.json

What could the issue be?

Thank you in advance for your invaluable help.

I tried a local version of your code and it did not lead to any errors. This behavior changed in 1.2.2, are you positive you have the latest version of cmdstanpy?

1 Like

cmdstanpy: 1.2.1ā€¦ Iā€™m sorry, I thought I installed 1.2.2. I will upgrade it!

thank you!!!