restore_key#
- class brainstate.random.restore_key#
Restore the default random key to its previous state.
This function restores the global random state to a previously backed up state. It’s useful for undoing changes to the random state or implementing checkpoint functionality in computational workflows.
- Return type:
Notes
This operation requires that a backup was previously created. If no backup exists, this function may not have any effect or may restore to an initial state.
Examples
>>> import brainstate >>> brainstate.random.seed(42) >>> original_key = brainstate.random.get_key() >>> brainstate.random.seed(123) # Change the seed >>> brainstate.random.restore_key() # Restore to previous state >>> assert np.array_equal(brainstate.random.get_key(), original_key)
See also
set_keySet a new random key
get_keyGet the current random key
seed_contextTemporary seed changes with automatic restoration