stan-dev / stan

Stan development repository. The master branch contains the current release. The develop branch contains the latest stable development. See the Developer Process Wiki for details.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
2.61k stars 369 forks source link

Move away from the `boost::ecuyer1988` pRNG #3256

Closed WardBrian closed 9 months ago

WardBrian commented 10 months ago

Summary:

The currently pRNG used by Stan has a few issues which have come up over the past year:

While tracking down the first, I opened https://github.com/boostorg/random/issues/92 which led to the following comments:

Similar defects with obsolete ancient RNGs have been reported time and time again

ecuyer1988 is not a very high quality PRNG.

The recommendation was to use boost::mixmax instead. This does not offer fast discard, but we may not need it:

I suspect that the authors of Stan implemented seeding several parallel streams/threads (or “chains” in MCMC lingo) using discard. Some while ago another user of Monte-Carlo had been asking me for arbitrary skip in MIXMAX. But this is a misunderstanding. When a user needs parallel streams from MIXMAX they should just seed using the default method from consecutive seeds. If you need eight streams you can seed them with 1,2,3…8 or with 1001,1002,1003,…1008. No other generator currently gives you that kind of satety.

Description:

There are a few places where the swap would need to happen:

I did most of these changes in a now out-of-date branch after #3167: https://github.com/stan-dev/stan/compare/develop...experiment/mixmax-rng. There is also a corresponding stanc3 branch (very simple): https://github.com/stan-dev/stanc3/compare/master...experiment/mixmax-rng

Besides these relatively small changes, the primary barrier is the tests. A lot of our unit tests in this repo fix a seed and compare against hard-coded results. All of these would need updating and validating.

Current Version:

v2.34.0

bob-carpenter commented 10 months ago

Their speculation was correct and the alternative is even easier.

I don't think its being a "low quality" RNG was ever an issue.

WardBrian commented 10 months ago

I don't think its being a "low quality" RNG was ever an issue.

Are you saying it is not worth changing at this point?

bob-carpenter commented 10 months ago

Sorry for being unclear---please change to solve the issues.

I just meant that the quality of the random numbers has never been an issue for us. The seed and other things are definitely an issue.