acerbilab / pyvbmc

PyVBMC: Variational Bayesian Monte Carlo algorithm for posterior and model inference in Python
https://acerbilab.github.io/pyvbmc/
BSD 3-Clause "New" or "Revised" License
112 stars 6 forks source link

Allowing finer grained control over random variate generation #138

Open matt-graham opened 1 year ago

matt-graham commented 1 year ago

In quite a few places in the main (non-test) code, random variates are sampled using functions in the top-level numpy.random namespace which map to the methods of a (globally shared) RandomState instance. From a reproducibility / ease of debugging perspective it would be better to instead allow explicitly passing an instance of the numpy.random.Generator class (introduced in Numpy v1.17) or the legacy numpy.random.RandomState class to functions which use (pseudo) random variates - see for example this blog post for a nice write up of why this is recommended. The current interface could be maintained by making this an optional keyword argument that defaults to a global Generator / RandomState instance if not specified, while allowing the user to explicitly control the random number generator if desired. This would also facilitate ensuring the tests are deterministic as discussed in #135.

Just to be clear as this would be quite a substantial change, I'm suggesting this more as a feature request / nice to have in future rather than as a blocker to acceptance for the JOSS review!

Bobby-Huggins commented 1 year ago

Thanks again for the suggestion, @matt-graham, I agree it would be good to modernize how we handle random states and seeds!