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

def deserialize_rng(klass, entropy, rng=None):
    if rng is not None and klass ==
rng.bit_generator.state['bit_generator']:
        rng.bit_generator.seed_seq.entropy = entropy
        return rng
    BG = getattr(np.random, klass)
    bg = BG(np.random.SeedSequence(entropy))
    return np.random.default_rng(bg)
```
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to