-
-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bad interaction between num_chains and fixed_param sampler #495
Comments
arguably, we didn't introduce a bug, fixing the logic uncovered a bug. |
I'm unable to recreate this as described. Using the example model: import os
from cmdstanpy import cmdstan_path, CmdStanModel
bernoulli_dir = os.path.join(cmdstan_path(), 'examples', 'bernoulli')
stan_file = os.path.join(bernoulli_dir, 'bernoulli.stan')
import os
os.remove(os.path.join(bernoulli_dir, 'bernoulli'))
model = CmdStanModel(stan_file=stan_file, cpp_options={'STAN_THREADS':'true'})
print(model)
data = { "N" : 10, "y" : [0,1,0,0,0,0,0,0,0,1] }
print(model.exe_info()) # confirms stan_threads is true
fit = model.sample(data=data, chains=7, parallel_chains=2, iter_sampling=100000)
print(fit.runset.csv_files) # 7 files This runs for me without a problem using |
testing on develop on my machine - model compiled 2.28.1:
maybe there are 7 files, but somehow, it can't parse one of them:
|
Can you cat that file or inspect it manually? |
Ah, this is because of that incredibly annoying |
The But, we can't tell a-priori if it will run fixed_param, so we might be cooked. stan-dev/cmdstan#1054 should be merged as a top priority IMO |
You can verify this using the command line interface: |
Do you want to open a CmdStan issue or shall I? Even after stan-dev/cmdstan#1054 this will probably still happen if the user specifically requests As for what we do in the interfaces... I really don't know if more unit tests helps us when CmdStan itself has bad behavior, and I don't think we can do much other than try to create a nicer error message instructing users to set |
force_one_process_per_chain
arg
it would be great if you do this. I will go back to banging my head against the compile logic. as for CmdStan, the sooner we build a different CLI, the better. |
we can do a better job of handling models with no parameters by extending the checks in |
Fair, but if the behavior is about to be removed from CmdStan I think bending over backwards for it is probably not worth it |
this would make life a whole lot easier sooner - or is this not exposed the way that |
I don't think there's any way to get that information out of the executable itself. I suppose you could try to grep the .hpp file to get the value of This might be a philosophical debate but ultimately I think there's a limit to how much an interface can fix the problems of the thing it is wrapping, and this is probably that barrier. Upstream changes in CmdStan and trying to produce better error messages are better than a lot of extra (and very hard to test) logic. I think we're nearing the point where it's a win when the code in this repo gets smaller, not larger |
The solution we should do for now, IMO, is add a check to these lines Lines 1467 to 1473 in 3cbfae4
If Edit: Actually, we probably need to do this in |
agreed to points above. I can add these in the next PR. |
how does the |
It's done the same way the I see you are talking about obtaining the number of parameters. You can do that via stanc3 and the --info flag. It returns a JSON file. That doesn't help you when the CmdStanModel object was made from the exe_file, but I would say that is the less common case. |
This is also what cmdstanr does: https://github.com/stan-dev/cmdstanr/blob/master/R/model.R#L861 |
thanks, I looked there, but not closely enough. the code you wrote is fine. |
OK, will do something similar. |
Summary:
somewhere late in PR #492 we introduced a bug.
possibly around changing the logic w/r/t behavoir when user tries to explicitly run chains in parallel?
Description:
the following call to
sample
, given a model which was compiled withstan_threads
==True
sampler tries to run multi-threaded - resulting CmdStan call is this:
which craps out because now there are only 2 output CSV files, not the expected 7. investigate logic and fix.
Additional Information:
Provide any additional information here.
Current Version:
The text was updated successfully, but these errors were encountered: