You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to checkpoint ak.numpy.random.Generator ? #4709
This issue seeks a solution for the currently-incomplete checkpointing of ak.numpy.random.Generator objects.
Details
The current checkpointing effort and #4710 are concerned with saving and restoring the SymTab entires ON THE SERVER. This is not sufficient / correct for preserving the complete state of an ak.numpy.random.Generator instance. That is, in the following scenario:
The user expects that the use of g in #2 will generate the same sequence of numbers as its use in #1.
Currently this will not be the case, here is why. While the server's state related to g will be restored properly upon ak.load_checkpoint(someName), g._state will not be restored while affecting the numbers generated by g.
In other words, these Generators rely on both server-side and client-side state, while the current checkpointing approach preserves only server-side state.
My initial recommendation is to eliminate g._state. It is used to fast-forward Chapel's RNGs, however it may not be necessary.
BTW if we keep g._state, we need to add its increment by 1 in cases like this:
ifsizeisNone:
# delegate to numpy when return size is 1returnself._np_generator.uniform(low=low, high=high)
Here is another proposal that will result in simpler implementation, thanks to @mppf:
Store (seed, state) on the client side. Notes: "State", which is the current position in the random number sequence for the given seed, is already stored as Generator._state. "Seed" is also stored, we just need to "instantiate" it to an integer in the case that the generator is created with seed=None.
Whenever a Generator needs to participate in a server-side operation, send its seed and state over to the server. The server will create a randomStream on the fly, with the desired element type.
This way we can remove Generator._name_dict in the client and GeneratorSymEntry on the server, as well as back out the additions in #4710 that are related to checkpointing of GeneratorSymEntrys.
I am realizing that my recommendation to eliminate Generator._state is not appropriate unless accompanied with other changes. This is because, for example, if the same Generator is created with a given seed then used to fill an array of ints and then an array of floats, both arrays will be sourcing from the same portion of the random number sequence. This latter is because a Generator contains separate randomStream instances on the server, one for ints and another for floats. Today each randomStream is advanced to the generator's _state before it is asked to generate numbers.
Activity
vasslitvinov commentedon Jul 11, 2025
Here is another proposal that will result in simpler implementation, thanks to @mppf:
Store (seed, state) on the client side. Notes: "State", which is the current position in the random number sequence for the given seed, is already stored as Generator._state. "Seed" is also stored, we just need to "instantiate" it to an integer in the case that the generator is created with
seed=None.Whenever a Generator needs to participate in a server-side operation, send its seed and state over to the server. The server will create a
randomStreamon the fly, with the desired element type.This way we can remove
Generator._name_dictin the client andGeneratorSymEntryon the server, as well as back out the additions in #4710 that are related to checkpointing of GeneratorSymEntrys.I am realizing that my recommendation to eliminate
Generator._stateis not appropriate unless accompanied with other changes. This is because, for example, if the same Generator is created with a given seed then used to fill an array of ints and then an array of floats, both arrays will be sourcing from the same portion of the random number sequence. This latter is because a Generator contains separaterandomStreaminstances on the server, one for ints and another for floats. Today eachrandomStreamis advanced to the generator's_statebefore it is asked to generate numbers.Back out generator checkpointing, pending Bears-R-Us#4709
Back out generator checkpointing, pending Bears-R-Us#4709
Back out generator checkpointing, pending Bears-R-Us#4709
Back out generator checkpointing, pending Bears-R-Us#4709
ak.get_registration_config() and tweaks (#4752)
ak.get_registration_config() and tweaks (Bears-R-Us#4752)