Add TypedDictSpace (spaces.Dict subclass) #2261
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TypedDictSpace
(This is a draft PR, just looking for feedback on the idea at the moment)
TODOS
batch_space
andconcatenate
single-dispatch functions), since thedtype
argument would be lost when using the current version of these functions with aTypedDictSpace
.Adds
TypedDictSpace
, a subclass ofgym.spaces.Dict
, which adds the following:dict
;typing.TypedDict
)space.x
:=space["x"]
)Examples:
constructor:
Can use any type here, as long as it can receive the samples from each space as
keyword arguments.
One good example of this is to use a
dataclass
as the custom dtype.You are strongly encouraged to use a dtype that inherits from the
Mapping
classfrom
collections.abc
, so that samples form your space can be handled similarly toregular dictionaries.
If an annotation on the class doesn't have a default value, then it is treated as a
required argument:
NOTE: spaces can also inherit from each other!
Let me know what you think! :)
Signed-off-by: Fabrice Normandin fabrice.normandin@gmail.com