schola.core.spaces.dict.DictSpace

class schola.core.spaces.dict.DictSpace(space_dict=None)[source]

Bases: Dict

A Space representing a dictionary of spaces.

Parameters:

space_dict (Dict[str, gymnasium.spaces.Space]) – The dictionary of spaces to be represented.

spaces

The dictionary of spaces represented by this object.

Type:

Dict[str, gymnasium.spaces.Space]

See also

gymnasium.spaces.Dict

The gym space object that this class is analogous to.

proto_spaces.DictSpace

The protobuf representation of this space.

Methods

__init__([space_dict])

Constructor of Dict space.

contains(x)

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

fill_proto(msg, action)

from_jsonable(sample_n)

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

from_proto(message)

get(k[,d])

items()

keys()

Returns the keys of the Dict.

process_data(msg)

sample([mask])

Generates a single random sample from this space.

seed([seed])

Seed the PRNG of this space and all subspaces.

simplify()

Simplify the dictionary space by merging subspaces of the same fundamental type, if possible.

to_jsonable(sample_n)

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

to_normalized()

Normalize this dictionary space by normalizing all of the subspaces in this dictionary space.

values()

Attributes

has_only_one_fundamental_type

Check if all the subspaces in the dictionary space are of the same fundamental type.

is_np_flattenable

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

np_random

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

shape

Return the shape of the space as an immutable property.

shapes

Get the shapes of the subspaces in the dictionary space.

__init__(space_dict=None)[source]

Constructor of Dict space.

This space can be instantiated in one of two ways: Either you pass a dictionary of spaces to __init__() via the spaces argument, or you pass the spaces as separate keyword arguments (where you will need to avoid the keys spaces and seed)

Parameters:
  • spaces – A dictionary of spaces. This specifies the structure of the Dict space

  • seed – Optionally, you can use this argument to seed the RNGs of the spaces that make up the Dict space.

  • **spaces_kwargs – If spaces is None, you need to pass the constituent spaces as keyword arguments, as described above.

fill_proto(msg, action)[source]
Parameters:

msg (DictPoint)

classmethod from_proto(message)[source]
property has_only_one_fundamental_type

Check if all the subspaces in the dictionary space are of the same fundamental type.

Returns:

True if all the subspaces are of the same fundamental type, False otherwise

Return type:

bool

Examples

Copied!

>>> space = DictSpace({"a": BoxSpace([0,0],[2,2]), "b": DiscreteSpace(3)})
>>> space.has_only_one_fundamental_type
False

Copied!

>>> space = DictSpace({"a": BoxSpace([0,0],[2,2]), "b": BoxSpace([0,0],[2,2])})
>>> space.has_only_one_fundamental_type
True

Copied!

>>> space = DictSpace({"a": DiscreteSpace(3), "b": MultiDiscreteSpace([3,3])})
>>> space.has_only_one_fundamental_type
True

process_data(msg)[source]
Parameters:

msg (DictPoint)

property shapes

Get the shapes of the subspaces in the dictionary space.

Returns:

A dictionary of the shapes of the subspaces in the dictionary space

Return type:

Dict[str, Tuple[int]]

Examples

Copied!

>>> space = DictSpace({"a": BoxSpace(0, 1, shape=(2,)), "b": DiscreteSpace(3)})
>>> space.shapes
{'a': 2, 'b': 1}

simplify()[source]

Simplify the dictionary space by merging subspaces of the same fundamental type, if possible.

Returns:

The simplified space

Return type:

gymnasium.spaces.Space

Examples

Copied!

>>> space = DictSpace({"a": BoxSpace([0,0],[2,2]), "b": BoxSpace([0,0],[2,2])})
>>> space.simplify()
Box(0.0, 2.0, (4,), float32)

Copied!

>>> space = DictSpace({"a": DiscreteSpace(4), "b": BoxSpace([0,0],[2,2])})
>>> space.simplify()
Dict('a': Discrete(4), 'b': Box(0.0, 2.0, (2,), float32))

Copied!

>>> space = DictSpace({"a": DiscreteSpace(4)})
>>> space.simplify()
Discrete(4)

to_normalized()[source]

Normalize this dictionary space by normalizing all of the subspaces in this dictionary space.

Returns:

The normalized dictionary space. A modified version of the space this method is called on

Return type:

DictSpace

Examples

Copied!

>>> space = DictSpace({"a": BoxSpace([0,0],[2,2]), "b": DiscreteSpace(3)})
>>> space.to_normalized()
Dict('a': Box(0.0, 2.0, (2,), float32), 'b': Discrete(3))

Related pages

  • Visit the Schola product page for download links and more information.

Looking for more documentation on GPUOpen?

AMD GPUOpen software blogs

Our handy software release blogs will help you make good use of our tools, SDKs, and effects, as well as sharing the latest features with new releases.

GPUOpen Manuals

Don’t miss our manual documentation! And if slide decks are what you’re after, you’ll find 100+ of our finest presentations here.

AMD GPUOpen Performance Guides

The home of great performance and optimization advice for AMD RDNA™ 2 GPUs, AMD Ryzen™ CPUs, and so much more.

Getting started: AMD GPUOpen software

New or fairly new to AMD’s tools, libraries, and effects? This is the best place to get started on GPUOpen!

AMD GPUOpen Getting Started Development and Performance

Looking for tips on getting started with developing and/or optimizing your game, whether on AMD hardware or generally? We’ve got you covered!

AMD GPUOpen Technical blogs

Browse our technical blogs, and find valuable advice on developing with AMD hardware, ray tracing, Vulkan®, DirectX®, Unreal Engine, and lots more.

Find out more about our software!

AMD GPUOpen Effects - AMD FidelityFX technologies

Create wonder. No black boxes. Meet the AMD FidelityFX SDK!

AMD GPUOpen Samples

Browse all our useful samples. Perfect for when you’re needing to get started, want to integrate one of our libraries, and much more.

AMD GPUOpen developer SDKs

Discover what our SDK technologies can offer you. Query hardware or software, manage memory, create rendering applications or machine learning, and much more!

AMD GPUOpen Developer Tools

Analyze, Optimize, Profile, Benchmark. We provide you with the developer tools you need to make sure your game is the best it can be!