rlberry.spaces.Dict

class rlberry.spaces.Dict(spaces=None, **spaces_kwargs)[source]

Bases: Dict

Inherited from gymnasium.spaces.Dict for compatibility with gym.

rlberry wraps gym.spaces to make sure the seeding mechanism is unified in the library (rlberry.seeding)

Attributes:
rngnumpy.random._generator.Generator

random number generator provided by rlberry.seeding

Methods

reseed()

get new random number generator

contains(x: Any) bool[source]

Return boolean specifying if x is a valid member of this space.

from_jsonable(sample_n: dict[str, list[Any]]) list[collections.OrderedDict[str, Any]][source]

Convert a JSONable data type to a batch of samples from this space.

get(k[, d]) D[k] if k in D, else d.  d defaults to None.
property is_np_flattenable

Checks whether this space can be flattened to a spaces.Box.

items() a set-like object providing a view on D's items
keys() KeysView[source]

Returns the keys of the Dict.

property np_random: Generator

Lazily seed the PRNG since this is expensive and only needed if sampling from this space.

As seed() is not guaranteed to set the _np_random for particular seeds. We add a check after seed() to set a new random number generator.

sample(mask: dict[str, Any] | None = None) dict[str, Any][source]

Generates a single random sample from this space.

The sample is an ordered dictionary of independent samples from the constituent spaces.

Args:

mask: An optional mask for each of the subspaces, expects the same keys as the space

Returns:

A dictionary with the same key and sampled values from self.spaces

seed(seed: dict[str, Any] | int | None = None) list[int][source]

Seed the PRNG of this space and all subspaces.

Depending on the type of seed, the subspaces will be seeded differently

  • None - All the subspaces will use a random initial seed

  • Int - The integer is used to seed the Dict space that is used to generate seed values for each of the subspaces. Warning, this does not guarantee unique seeds for all of the subspaces.

  • Dict - Using all the keys in the seed dictionary, the values are used to seed the subspaces. This allows the seeding of multiple composite subspaces (Dict["space": Dict[...], ...] with {"space": {...}, ...}).

Args:

seed: An optional list of ints or int to seed the (sub-)spaces.

property shape: tuple[int, ...] | None

Return the shape of the space as an immutable property.

to_jsonable(sample_n: Sequence[dict[str, Any]]) dict[str, list[Any]][source]

Convert a batch of samples from this space to a JSONable data type.

values() an object providing a view on D's values