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.
Note
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.
Example
>>> 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_key(): Set a new random keyget_key(): Get the current random keyseed_context(): Temporary seed changes with automatic restoration
- Return type: