Skip to content

Modernize random number generation (i.e., stop using np.random.seed/get_state/set_state) #11687

Open
@eteq

Description

@eteq

numpy has gone away from the np.random.seed/np.random.set_state/np.random.get_state models for random number generation. astropy should follow suit where possible. This in practice means the following tasks:

  • Stop using our home-grown RNGContext in the tests and replace with the newer numpy mechanism.
  • Replace anywhere that np.random.* is used currently with something that uses the new mechanism (e.g. the random functions in Add new module for generating random or gridded spherical points #11628 ), which may require some API additions to let the new numpy generators be passed into functions.
  • ? Deprecate our home-grown RNGContext and replacing it with the "new" numpy mechanism. Note it is not currently clear to me if we can do this. I don't think the numpy scheme supports a context manager a la our ScienceState approach. In that case we have to decide if we think it's worth supporting this long-term, trying to get this into numpy or just deciding it's better to use the numpy approach anyway.

For some backstory/justification on the numpy shift see:

cc @adrn @lpsinger @mhvk (as discussers from #11628)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions