qmcpack icon indicating copy to clipboard operation
qmcpack copied to clipboard

Revise random number generation and initialization

Open prckent opened this issue 7 years ago • 6 comments

After v.3.6.0, discuss with wider group + update random initialization to a scheme that guarantees different random numbers on each thread.

prckent avatar Nov 27 '18 02:11 prckent

One option is Counter-Based RNGs https://en.wikipedia.org/wiki/Counter-based_random_number_generator_(CBRNG)

Random123 is available here: http://www.thesalmons.org/john/random123/releases/latest/docs/index.html

markdewing avatar Sep 01 '20 03:09 markdewing

Thanks. Do you have a preferred scheme?

My current thoughts on this topic are:

  • We pick a new scheme. Use fast skip ahead for threads + mpi tasks. This is the default. Take care to avoid the obvious mistakes in the current initialization. (Note that the observed problem with the current scheme is how parallelization is handled in initialization. My reading indicates that the current generator is not terrible.)
  • Keep the current scheme as an option to avoid having to redo all the deterministic tests (only, the short & long must be fine by definition). e.g. New generator="legacy" option in the XML.
  • Consider a debug/testing option to enable parallel deterministic tests e.g. all the random numbers follow the same sequence across threads and tasks.
  • All the above is input switchable, no #defines

Comments welcome.

prckent avatar Sep 01 '20 14:09 prckent

I'll weigh into this in one of the issues. RandomGenerator_t is not thread safe so particular thread needs to have sole access to a particular RandomGenerator just making copies isn't good enough. In the new drivers the Crowd has a "properly initialized" rng that it gives to the hamiltonians that need RNG. Ideally that would come as a function parameter (i.e. some sort of resource) but right now we update the hamiltonian object state in the initialLogEvaluation and at each step so this is correct for the step context it is in.

PDoakORNL avatar Aug 26 '21 13:08 PDoakORNL

I think we have gone through whether this can be made to match the old method and the answer is no.

PDoakORNL avatar Aug 26 '21 13:08 PDoakORNL

Food for thought on selecting RNG's:

https://www.pcg-random.org/statistical-tests.html#testu01-s-crush-and-bigcrush-batteries

jtkrogel avatar Jan 04 '22 14:01 jtkrogel

I've been looking at that as well. They provide an API for c++ that follows the rng API. MIT licensed so no barrier to using it there. It's header only and could easily be put in external_codes as we do with catch2

PDoakORNL avatar Jan 04 '22 19:01 PDoakORNL