pymc icon indicating copy to clipboard operation
pymc copied to clipboard

Refactor step methods to use their own random stream

Open lucianopaz opened this issue 3 years ago • 2 comments

Description of your problem

This issue is a spin off from a discussion in #5787. At the moment of that PR, our step methods rely on the global numpy random state to generate random numbers. It would be great to modify the step methods to allow them to have their own random generator that could then be used to generate all of their random number proposals.

Surprisingly, metropolis has some proposal distributions that could in principle take a random stream, the problem is that the actual steppers don't expose an easy to access random stream generator argument for users (or pm.sample) to set. HMC on the other hand is plagued with calls to numpy.random.some_method

lucianopaz avatar May 24 '22 09:05 lucianopaz

Yeah the metropolis RNG interface was added so that SMC sampling did not rely on global seeding in https://github.com/pymc-devs/pymc/pull/5131.

ricardoV94 avatar May 24 '22 09:05 ricardoV94

I had a look at this issue and I have several questions about it:

  • Work has started on this functionality in #5131, creating two API points to specify a local prng for the Proposal distributions: at __init__ where a random_seed can be specified, and at __call__ where a rng can be passed. Are these two options necessary in principle, or could we just do with one of them?
  • This implementation has been partially reverted in #5135 because it made some tests flaky. Would it be acceptable to make the incriminated tests fix the local rng instead of the global one in order to un-revert the original PR and build from there?

Armavica avatar Sep 15 '22 05:09 Armavica