mattja / sdeint

Numerical integration of Ito or Stratonovich SDEs
GNU General Public License v3.0
154 stars 25 forks source link

Allow passing a numpy Generator for random numbers #21

Closed PFMassiani closed 1 year ago

PFMassiani commented 2 years ago

Hello,

This is a follow up on #14 given numpy's latest recommendation regarding random number generation, which can be found here.

In short, using np.random.XXX is now legacy, and the recommended usage is:

rng = np.random.default_rng(seed=0)
rng.normal()

And instead of setting the global seed, one should pass the Generator instance to the place where it is needed. AFAIK, sdeint does not allow passing a Generator instance.

It would be nice to incorporate this feature for compatibility with newer code, e.g., with sdeint using a global Generator instance that could be set by the user.

Thanks

mattja commented 2 years ago

Excellent suggestion. I'll implement this in the next couple of weeks as time permits. Adding a generator keyword argument in all relevant sdeint functions.

If omitted generator=None, it can just default to instantiate its own np.random.default_rng() . I'll assume no need for bitwise backwards compatibility with the old behavior.