Skip to content
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

Ensure mixmax rng is not initialized with all zeros #3287

Merged
merged 1 commit into from
May 22, 2024
Merged

Conversation

WardBrian
Copy link
Member

Submission Checklist

  • Run unit tests: ./runTests.py src/test/unit
  • Run cpplint: make cpplint
  • Declare copyright holder and open-source license: see below

Summary

Prevents the poor behavior seen in #3285.

The boost::mixmax rng is actually initialized with 128 bits of state. The overload we were previously calling was synonymous with rng(0,0, 0, seed+chain). This PR changes to rng(0,1,seed,chain). In addition to ensuring that the full 128 bits are never all zero, it also makes adjacent seeds more independent; previously seed=1 chain=1, seed=2 chain=0, and seed=0 chain=2 would all yield the same seeding.

I am still awaiting on confirmation from the boost devs that this configuration of the RNG preserves the desirable property that chain and chain+1 yield independent streams, hence the draft status.

Intended Effect

Closes #3285

How to Verify

See the updated godbolt which shows that the single 1 prevents the deterministic behavior

Side Effects

Seeds will be different from 2.35RC1. This also required updating the tests which are seed-dependent.

Documentation

None

Copyright and Licensing

Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company):

Simons Foundation

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses:

@WardBrian WardBrian requested a review from andrjohns May 17, 2024 19:58
@WardBrian WardBrian marked this pull request as draft May 17, 2024 20:01
@WardBrian
Copy link
Member Author

The original reference implementation from which boost's is derived makes it clear that this is a valid configuration:

void seed_uniquestream(rng_state_t* X, myID_t clusterID, myID_t machineID, myID_t runID, myID_t  streamID );
/*
 best choice: will make a state vector from which you can get at least 10^100 numbers 
 guaranteed mathematically to be non-colliding with any other stream prepared from another set of 32bit IDs,
 so long as it is different by at least one bit in at least one of the four IDs
			-- useful if you are running a parallel simulation with many clusters, many CPUs each
 */

@WardBrian
Copy link
Member Author

@andrjohns @nhuurre mind reviewing?

Downstream failures addressed by stan-dev/cmdstan#1274 (tolerance too tight) and by re-running the gold tests after merge (expected for the model that fails)

@WardBrian WardBrian merged commit 356d206 into develop May 22, 2024
2 of 3 checks passed
@WardBrian WardBrian deleted the fix/rng-init branch May 22, 2024 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible issue with new RNG?
2 participants