-
Notifications
You must be signed in to change notification settings - Fork 5
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
Chains are not independent #23
Comments
Hi Chris, why do you think that? I see 4 chains in the plots. In the line1 example I don't set the seed. |
nchains is the total number of chains created, ncommands set the number of processes used to run the nchains. Not sure how I handled the case where commands > 1 and not equal to chains. |
Maybe I introduced a bug in one of my updates |
Hmm,
|
Just ncommands=1, nchains=2: I might have to check if tmp is cleared properly. My statement above is wrong, 4 chains in parallel is ncommands=4, nchains=1. |
Strange. Do you also obtain the correct results with the code in my initial post? |
P.S. I think you need to test
|
I tried to compare version 2.0.1 to the most current version but I couldn't get it to work any more. Really strange. In case I set up my example incorrectly, could you try it and/or send me the example that was successful for you? I'll give it a try once I get back from the gym. |
Ok. After finding your example and comparing it to mine, I discovered part of the problem. The code I copied and pasted to create my model had a random seed in the inits dictionary:
After removing the RNG variable, I was able to get different chains in some cases, but not others.
With the setup below, the result is 4 different chains sampled sequentially:
Finally, the setup below yields 4 different sets of chains and chains with each set are identical.
Confirming this is the case:
So is there a way to run 4 different chains in parallel? |
Not right now, looking at the code, the way to achieve this is to pass a
needs to be expanded to:
for cmd1. Etc.This might be a consequence of the fact this needs to be compiled in. Definitely a bit of work. I don't think that has ever worked properly in earlier releases. Shows that Jags.jl hasn't been used that much. How important is it for your work? |
To documents this a bit further, each cmd and each chain need an init file generated from:
in your example. |
And the jagsmodel.command array:
in the case of 4 parallel executions, each with 2 chains needs to look like:
|
Thanks, Rob. Its somewhat important. I started to use Jags because Turing does not currently have an efficient sampler for discrete parameters (see this issue). They may have a solution in 3-6 months, but it's often the case that projects take longer than anticipated. Do you think adding this capability would be difficult? |
Not that difficult, but just a very detail-sensitive project. Basically something like:
I think those are the steps needed. |
Hi Rob, I just wanted to follow up with you about this issue. As a summary, Jags.jl runs identical chains in parallel, which defeats the purpose of having multiple parallel chains. Do you still have plans to fix this? |
Hi Chris, In the Jags docs, on page 16:
with a footnote:
My conclusion is that:
But I do have a problem with the Jags binary in that ncommands in above script used to be 1, but now it hangs Julia if I don't set it to 4. This could also be the new thread model in Julia. I do see 4 chains. |
If I recall correctly, my intention was that using chains Jags controls running the individual chains, with ncommands Julia is supposed to be the master. |
Hi Rob, Thank you for clarifying. Would it be possible to add your example above to the README as an example of running multiple independent chains? I think that will be useful for other people who use Jags.jl. Aside from that, I think the issue is resolved. Thanks again! |
Hi Chris, Yes, as far as possible, it is, but I'm worried about why Julia hangs with 4 Julia commands each with 1 chain. Will try to find some time to dig into this. Edit: Still working on the revamp of StanJulia. There is now a StanSample.jl v5.0.0 branch which is all keyword argument based but before releasing it I need to do the others (StanOptimize and StanVariational). |
Sorry. I overlooked that. Thank for looking into this issue. Great news about StanSample.jl by the way. I will update as soon as it is released! |
It's still a branch only (v5). I actually wonder if one of the random number generators in Jags is failing (on MacOS) and this causes Julia to hang. |
Doesn't seem to be related to setting different random number generators but it is the Jags binary hanging on my system. Did put a note on multiple inits in the readme and a warning about the problem. For now I will leave this issue open, not sure if I can fix it. By the way, have you tried Mamba for Gibbs? |
Thanks for looking into the issue. I played around with Mamba several years ago but did not think about using it for Gibbs. Thanks for hte idea. |
Hi Rob-
I noticed that the chains are not independent. Another potential issue is that the functionality of
ncommands
andnchains
is unclear. Both appear to run n instances of the same chain, butncommands
appears to run them in parallel. Is this a bug or a problem with my setup?Here is a simple example:
The text was updated successfully, but these errors were encountered: