helios.core.rng¶
Classes¶
Default RNG from Numpy. |
Functions¶
|
Return the default seed. |
|
Initialize the default RNG with the given seed. |
|
Return the default RNG. |
|
Seed the default RNGs with the given seed. |
|
Get the state dict for the default RNGs. |
|
Restore the default RNGs from the given state dict. |
Module Contents¶
- class helios.core.rng.DefaultNumpyRNG(seed: int | list[int] | tuple[int] | None = None)[source]¶
Default RNG from Numpy.
This is intended to serve as a replacement for the legacy random API from Numpy. The class wraps the new Generator instance, which is set to use PCG64. Functionality similar to the modules for PyTorch is provided for easy serialization and restoring.
- Parameters:
seed – (optional) the initial seed to use.
- property generator: numpy.random.Generator¶
Return the Numpy Generator instance.
- helios.core.rng.create_default_numpy_rng(seed: int | list[int] | tuple[int] | None = None)[source]¶
Initialize the default RNG with the given seed.
- Parameters:
seed – (optional) the seed to use.
- helios.core.rng.get_default_numpy_rng() DefaultNumpyRNG [source]¶
Return the default RNG.
- Returns:
The random generator.
- Raises:
RuntimeError – if the default Numpy RNG hasn’t been created.
- helios.core.rng.seed_rngs(seed: int | None = None, skip_torch: bool = False) None [source]¶
Seed the default RNGs with the given seed.
If no seed is given, then the default seed from Helios will be used. The RNGs that will be seeded are: PyTorch (+ CUDA if available), stdlib random, and the default Numpy generator. The
skip_torch
flag is intended to be used when seeding worker processes for dataloaders. In those cases, the RNGs for PyTorch have already been seeded, so we shouldn’t be re-seeding them.- Parameters:
seed – optional value to seed the random generators with.
skip_torch – if True, torch RNGs won’t be seeded.
- helios.core.rng.get_rng_state_dict() dict[str, Any] [source]¶
Get the state dict for the default RNGs.
Default RNGs are: PyTorch (+ CUDA if available) and Random.
- Returns:
The state of all RNGs.
- helios.core.rng.load_rng_state_dict(state_dict: dict[str, Any]) None [source]¶
Restore the default RNGs from the given state dict.
See
get_rng_state_dict()
for the list of default RNGs.- Parameters:
state_dict – the state of the RNGs