Namespace Gym.Spaces
Classes
- Box
A possibly unbounded box in R^n: every element is an array of Shape and DType whose entries lie within Low and High (each interval closed, or open to infinity). It describes continuous observations and actions, such as CartPole's observation; an integer dtype makes it a discrete grid.
- Dict
A dictionary of spaces: every element is a string-keyed dict (Gym.NET's insertion-ordered Python dict, Info, DR-13's generic form) holding one element of each subspace under its key, such as a robot's
{"position": …, "velocity": …}.
- Discrete
The integers
{Start, ..., Start + N - 1}: a categorical action or observation, such as CartPole's two pushes or FrozenLake's 16 cells. An element is a 0-d array of DType (int64 by default), Gym.NET's stand-in for NumPy'snp.int64scalar (DR-08).
- Graph
Graphs whose nodes and edges carry features from two spaces: every element is a GraphInstance of node features, edge features, and the
(m, 2)links saying which two nodes each edge joins. The number of nodes and edges varies per sample.
- GraphInstance
One element of a Graph space: the node features, the edge features and the edge links, as the
(nodes, edges, edge_links)tuple Gymnasium's NamedTuple is. It deconstructs like one:var (nodes, edges, links) = graph.Sample();.
- MultiBinary
The binary arrays of a fixed shape: every element is an int8 array of 0s and 1s, such as a set of on/off switches.
- MultiDiscrete
The cartesian product of discrete spaces: every element is an integer array whose entry
ilies in[Start[i], Start[i] + Nvec[i]), such as a game controller's several buttons each with its own options.
- ObjectSpace
Any space seen as a
Space<object?>, for an env typedEnv<object?, object?>whose spaces vary (Gymnasium's generic test envs take any space). Everything forwards to Inner: sampling, membership, seeding, the generator,reprand equality, so the view behaves as the space itself.
- OneOf
The direct sum of spaces: every element is an element of exactly one subspace, tagged with its index, as the pair
(index, value)(an object?[] whose index is a 0-d int64 array, NumPy'snp.int64). Use it for an action that is one of several kinds, each with its own parameters.
- Sequence
Sequences of any length whose items belong to one feature space: every element is a tuple (an object?[]) of feature-space elements, or, with Stack, those elements stacked into one batch (an array, or a tuple or dict of arrays).
- Space
The untyped view of every space: the set an env's actions or observations belong to. It records their Shape and DType (when its elements are arrays), tests membership (Contains(object?)) and draws random members (Sample(object?, object?)) from a generator of its own, so seeding a space never disturbs the env's stream. Code that knows the element type uses Space<T>, which every space derives from.
- SpaceUtils
Gymnasium's
gymnasium.spaces.utils: flattening a space's elements into one array for learning code (Flatten(Space, object?)), back (Unflatten(Space, object?)), the space they flatten into (FlattenSpace(Space)) and its size (Flatdim(Space)), plus the dtype-and-shape equivalence vector envs check (IsSpaceDtypeShapeEquiv(Space, Space)).
- Space<T>
A space whose elements are
T: Box and Discrete areSpace<NDArray>(a discrete element is a 0-d int64 array, NumPy'snp.int64, DR-08). An env'sActionSpaceandObservationSpaceare typed this way (DR-07), and custom spaces derive from it.
- Spaces
Gymnasium's
gymnasium.spacesmodule as one static class (DR-79, DR-86): withusing Gym.Spaces;,Spaces.Discrete(4, seed: 0)reads asspaces.Discrete(4, seed=0)afterfrom gymnasium import spaces. Each factory builds the class of its name exactly as its constructor does, and the module's functions are here too: Flatdim(Space), Flatten(Space, object?), FlattenSpace(Space), Unflatten(Space, object?).
- Text
The strings of a character set whose length lies in
[MinLength, MaxLength], such as a command or a name.
- Tuple
The cartesian product of spaces: every element is a tuple (an object?[], DR-13's generic form) holding one element of each subspace, in order, such as Blackjack's
(player sum, dealer card, usable ace).
Structs
- SpaceSeed
What a space constructor's
seedaccepts, Gymnasium'sint | np.random.Generator | None: an integer seed for a fresh generator of the space's own, or an existing generator the space then shares. Callers never name this type:seed: 42,seed: someBigIntegerandseed: generatorconvert implicitly, and a Nullable<T> null isNone.
Enums
- BoundedMannerEnum
Which side of a Box IsBounded(BoundedMannerEnum) checks; Gymnasium spells it as a string.