[Numpy-discussion] Re: Canonical way of serialising Generators

2024-10-27 Thread Robert Kern via NumPy-Discussion
On Mon, Oct 28, 2024 at 12:11 AM Andrew Nelson via NumPy-Discussion < numpy-discussion@python.org> wrote: > Hi all, > is there a canonical way of serialising Generators (not via pickle). > Pickle is the canonical way. In particular, the pickle _machinery_ is going to be the single source of truth

[Numpy-discussion] Re: Canonical way of serialising Generators

2024-10-27 Thread Andrew Nelson via NumPy-Discussion
On Mon, 28 Oct 2024 at 15:06, Andrew Nelson wrote: > Hi all, > is there a canonical way of serialising Generators > Specifically I'm interested in a safe way (i.e. no pickle) of saving/restoring Generator state via HDF5 file storage. ___ NumPy-Discussi

[Numpy-discussion] Canonical way of serialising Generators

2024-10-27 Thread Andrew Nelson via NumPy-Discussion
Hi all, is there a canonical way of serialising Generators (not via pickle). Would the following be reasonable for saving and restoring state: ``` def serialize_rng(rng): klass = rng.bit_generator.state['bit_generator'] entropy = rng.bit_generator.seed_seq.entropy return klass, entropy