torchsig.utils.random.Seedable

class torchsig.utils.random.Seedable(seed: int | None = None, parent=None, **kwargs)[source]

Bases: object

A class/interface representing objects capable of accessing random numbers and being seeded. Stores an inernal random number generator object. Can be seeded with the Seedable.seed(seed_value : long) function. Two Seedable objects with the same seed will always generate/access the same random values in the same order. Containing or composing Seedable objects are generally responsible for seeding contained or composed Seedable objects.

Methods

add_parent

Add parent Seedable object and set up RNGs accordingly

get_distribution

get_second_seed

Gets second seed, usually used to seed both torch and numpy generators with slightly different seeds

seed

Seed number generators with given seed.

setup_rngs

Initialize torch and numpy number generators, and update its children.

update_from_parent

Update numpy and torch number generators with parent seed

__init__(seed: int | None = None, parent=None, **kwargs)[source]

Initializes seedable object with self.seed = seed; if a parent Seedable object is passed in, they will share random number generators, and the seed argument will not be used

Parameters:
  • seed (int, optional) – Seed for use for number genrators. Defaults to None.

  • parent (Seedable, optional) – Parent Seedable responsible for seeding this object. Defaults to None.

add_parent(parent) None[source]

Add parent Seedable object and set up RNGs accordingly

update_from_parent() None[source]

Update numpy and torch number generators with parent seed

seed(seed: int) None[source]

Seed number generators with given seed.

Parameters:

seed (int) – Seed to use.

get_second_seed(seed: int) int[source]

Gets second seed, usually used to seed both torch and numpy generators with slightly different seeds

Parameters:

seed (int) – Seed to use.

Returns:

New seed.

Return type:

int

setup_rngs() None[source]

Initialize torch and numpy number generators, and update its children.

__repr__() str[source]

Return repr(self).