Hi,
I have
cmdstan 2.34.1
cmdstanpy 1.2.2
installed through conda-forge. I wanted to try the new pathfinder method for variational inference but I get this message:
ValueError: Method ‘pathfinder’ not available for CmdStan versions before 2.33
Since pathfinder is in CmdStanPy 1.2.2 documentation I thought it would be available…
Hi @irelamb -
Could you provide the output of cmdstanpy.show_versions()?
yes sure. Here it is
INSTALLED VERSIONS
python: 3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:50:58) [GCC 12.3.0]
python-bits: 64
OS: Linux
OS-release: 5.14.0-70.30.1.el9_0.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: (‘en_US’, ‘UTF-8’)
cmdstan_folder: /home/ilambert/miniconda3/envs/cmdstan_2.34/bin/cmdstan
cmdstan: (2, 34)
cmdstanpy: 1.2.2
pandas: 2.2.1
xarray: None
tqdm: 4.66.2
numpy: 1.26.4
I just re-created an environment with identical versions and was able to successfully run Pathfinder. Can you share a bit more of the code you are trying to run?
Sure, thanks!
#----- Define inference data ------#
data = {}
data = {
'ndata' : len(traces_conc),
'ntraces' : ntraces,
'I' : traces_conc.tolist(),
't' : times_conc.tolist(),
'starts' : (starts + 1).tolist(),
'time_step' : dt,
'n_per_MP' : n_per_MP,
'n_max' : n_max,
'max_n_ramp' : max_n_ramp,
'max_n_term' : max_n_term,
'sigma' : sigma
}
#----- Compile the model and fit ------#
start = time()
compiled_model = CmdStanModel(stan_file = join(homedir, 'main/{}.stan'.format(HMM_model_name)), cpp_options = {'STAN_THREADS':'true'})#, force_compile = True)
print(compiled_model)
print(compiled_model.exe_info())
#FIT = compiled_model.sample(data = data, chains = n_chains, parallel_chains = n_chains, iter_sampling = n_samples, show_console = True)#, inits = inits)
FIT = compiled_model.pathfinder(data = data, show_console = True)
#FIT = compiled_model.variational(data = data, show_console = True)
end = time()
print("model took ", end-start)
I am able to run sample and variational without errors of this kind.
In the same script:
from cmdstanpy import set_cmdstan_path, cmdstan_path, show_versions
print(cmdstan_path())
print(show_versions())
from cmdstanpy import CmdStanModel
with the output
/home/ilambert/miniconda3/envs/cmdstan_2.34/bin/cmdstan
INSTALLED VERSIONS
---------------------
python: 3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:50:58) [GCC 12.3.0]
python-bits: 64
OS: Linux
OS-release: 5.14.0-70.30.1.el9_0.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
cmdstan_folder: /home/ilambert/miniconda3/envs/cmdstan_2.34/bin/cmdstan
cmdstan: (2, 34)
cmdstanpy: 1.2.2
pandas: 2.2.1
xarray: None
tqdm: 4.66.2
numpy: 1.26.4
The complete error that I get:
Traceback (most recent call last):
File "/home/ilambert/SunTag_HMM/main/stan_regression_HMM_on_simu_jed_cmdstan.py", line 183, in <module>
FIT = compiled_model.pathfinder(data = data, show_console = True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ilambert/miniconda3/envs/cmdstan_2.34/lib/python3.12/site-packages/cmdstanpy/model.py", line 1710, in pathfinder
raise ValueError(
ValueError: Method 'pathfinder' not available for CmdStan versions before 2.33
@WardBrian ,
sorry but maybe it was a stupid mistake on my side… Right now I recompiled the model and I don’t get the error anymore. I guess that before I was just re-loading a model that was compiled with CmdStan 2.31…
I am really sorry, I should have thought about this before.
1 Like
No worries! Glad it is working now
1 Like
Thank you so much for your help!!!