-
Notifications
You must be signed in to change notification settings - Fork 12
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
Breaking change: Implement param_constrain in a thread-safe way #98
Conversation
Note: this does not implement the idea discussed in #92 where the interfaces could have a non-thread-safe default mode where they store and use an RNG on your behalf. We could implement this afterwards quite easily, and it would not be a further breaking change to do so (if anything it makes it slightly less breaking) |
I think this looks nice :-) Is there a reason why the I also noticed that it this is using ecuyer1988 to get random numbers. I'm very far from an expert on those, but I think this is a pretty old one that might not be all that reliable? I couldn't find detailed analysis on it, but it is mentioned here as having issues: https://www.pcg-random.org/pdf/hmc-cs-2014-0905.pdf |
The model’s constructor can have some randomization in it (RNG functions in the The ecuyer1988 generator does seem to be suboptimal in the modern landscape, and we’ve encountered strange issues with it before (the fact that I always discard 1 draw from it is actually working around a bug someone reported to us recently: stan-dev/stan#3167) Unfortunately the Stan model base class only exposes write_array with that argument, so upstream changes would be needed for us to use a different one in bridgestan |
Ah, makes sense. If there is a global model seed anyway, would it then make sense to turn the seed argument of If With independent seeds as in the current design it is much harder for consumers of the API to figure out a good system for those seeds. |
I agree that is a better interface @aseyboldt. Reworking now |
018e69b
to
7304b04
Compare
A small inconsistency: |
Nope! Just forgot to update after we changed bs_construct in #91. I’ll fix tomorrow |
I believe this is ready for feedback/review from you both @roualdes @bob-carpenter |
Discussed with @bob-carpenter and he is in favor of ditching any logic where we deal with chain IDs or implicitly constructing an RNG for the user if they give us one. The interface would then be:
This essentially removes bullet point 4 in the original PR post and greatly simplifies 5. I think I am also in favor of this, since it's not clear to me that the "advance by some huge number times the chain ID" scheme makes sense when the only thing the RNG is being used for is Thoughts @roualdes? |
Overall the conclusions of your discussions sound good. Ditching any logic surrounding RNGs where they are not necessary is a win. I feel like I'm missing some details, but I'll pick those up after looking over the next draft. |
Updated the code and the PR description per the above. |
|
new_model uses that seed if the Stan code has RNG functions in |
I certainly did not consider that idea. Thanks. I should have time Thursday, at latest, to review this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a big one. Thanks much for your effort, @WardBrian.
Overall, the structure looks great. Lots of little tidbits in this review. Mostly I'm interested in a new Julia test to confirm that these changes are thread-safe.
@WardBrian, I just pushed a re-worked version of the julia test "threaded model: full". As I understand things, the previous test passed but did not test what we wanted for two reasons.
This all speaks to a larger, julia specific, issue of our modifying functions, e.g. Let me know what you think, then I'll do one last pass and approve. |
Sounds good, I heartily appreciate the look-over on that test. That does sound like some possibly messy Julia inside baseball. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thanks!
This closes #92.
bs_model_rng
struct no longer holds an RNG (and has thus been renamed tobs_model
).bs_param_constrain
function now expects a pointer to abs_rng
struct, which holds theboost::ecuyer1988
RNGbs_rng
struct have been added. These are exposed in the interfaces to create new RNG holders from a seed.rng
argument toparam_constrain
. This must be set ifinclude_gq == true
.