Spaces

RLMesh spaces are Python wrappers around native SpaceSpec values. They provide the familiar sample, contains, and seed methods while keeping the spec available for transport and conversion.

Base Types

class rlmesh.spaces.Space[source]

Bases: Generic[OutputT]

Base wrapper for an RLMesh-native space.

__init__(spec)[source]
Parameters:

spec (SpaceSpec)

Return type:

None

property spec: SpaceSpec[source]

Native space specification backing this wrapper.

property kind: str[source]

Native RLMesh space kind.

property shape: list[int][source]

Native shape for tensor-like spaces.

property dtype: str[source]

Element dtype reported by the native spec.

seed(seed=None)[source]

Seed the native sampler for this space.

Parameters:

seed (int | None)

Return type:

int | None

sample()[source]

Sample a value from this space.

Return type:

OutputT

contains(value)[source]

Return whether a value is contained in this space.

Parameters:

value (object)

Return type:

bool

to_gymnasium_space()[source]

Convert this wrapper into a Gymnasium space.

Return type:

object

class rlmesh.spaces.SpaceBridge[source]

Bases: Generic[OutputT]

Convert space samples and inputs for a Python backend.

__init__(sample, input=None)[source]
Parameters:
  • sample (Callable[[object, SpaceSpec], OutputT])

  • input (Callable[[object, SpaceSpec], object] | None)

Return type:

None

sample(value, spec)[source]

Convert a native space sample into the backend value type.

Parameters:
  • value (object)

  • spec (SpaceSpec)

Return type:

OutputT

input(value, spec)[source]

Convert a backend value into the native input accepted by contains().

Parameters:
  • value (object)

  • spec (SpaceSpec)

Return type:

object

Conversion Helpers

rlmesh.spaces.from_gymnasium_space(space)[source]

Convert a Gymnasium space into an RLMesh space wrapper.

Parameters:

space (object) – Gymnasium or legacy Gym space.

Returns:

Matching RLMesh space wrapper.

Return type:

Space[Value]

rlmesh.spaces.to_gymnasium_space(space)[source]

Convert an RLMesh space or native spec into a Gymnasium space.

Parameters:

space (Space[Any] | SpaceSpec) – RLMesh space wrapper or native space specification.

Returns:

Gymnasium space object.

Return type:

object

rlmesh.spaces.space_from_spec(spec: SpaceSpec, *, bridge: None = None) Space[Value][source]
rlmesh.spaces.space_from_spec(spec: SpaceSpec, *, bridge: SpaceBridge[OutputT]) Space[OutputT]

Create the named RLMesh space wrapper for a native spec.

Parameters:
  • spec (SpaceSpec) – Native space specification.

  • bridge (SpaceBridge[OutputT] | None) – Optional backend bridge for sample/contains values.

Returns:

Matching RLMesh space wrapper.

Return type:

Space[OutputT] | Space[Value]

Fundamental Spaces

Box and Discrete are stable. MultiBinary, MultiDiscrete, and Text are experimental and may change; see Compatibility and the per-space labels in Gymnasium Compatibility.

final class rlmesh.spaces.Box[source]

Bases: Space[None | bool | int | float | str | bytes | _Tensor | list[Value] | tuple[Value, …] | dict[str, Value]]

Continuous box space.

Parameters:
  • low – Lower bound, or an existing native SpaceSpec.

  • high – Upper bound when constructing a new spec.

  • shape – Box shape when constructing a new spec.

  • dtype – Element dtype name.

__init__(low, high=None, shape=None, dtype='float32')[source]
Parameters:
  • low (float | SpaceSpec)

  • high (float | None)

  • shape (Sequence[int] | None)

  • dtype (str)

Return type:

None

contains(value)[source]

Return whether a value is contained in this space.

Parameters:

value (object)

Return type:

bool

property dtype: str[source]

Element dtype reported by the native spec.

property kind: str[source]

Native RLMesh space kind.

sample()[source]

Sample a value from this space.

Return type:

OutputT

seed(seed=None)[source]

Seed the native sampler for this space.

Parameters:

seed (int | None)

Return type:

int | None

property shape: list[int][source]

Native shape for tensor-like spaces.

property spec: SpaceSpec[source]

Native space specification backing this wrapper.

to_gymnasium_space()[source]

Convert this wrapper into a Gymnasium space.

Return type:

object

final class rlmesh.spaces.Discrete[source]

Bases: Space[None | bool | int | float | str | bytes | _Tensor | list[Value] | tuple[Value, …] | dict[str, Value]]

Discrete integer space.

Parameters:
  • n – Number of values, or an existing native SpaceSpec.

  • start – First integer value in the space.

  • dtype – Integer dtype name.

__init__(n, start=0, dtype='int64')[source]
Parameters:
  • n (int | SpaceSpec)

  • start (int)

  • dtype (str)

Return type:

None

contains(value)[source]

Return whether a value is contained in this space.

Parameters:

value (object)

Return type:

bool

property dtype: str[source]

Element dtype reported by the native spec.

property kind: str[source]

Native RLMesh space kind.

sample()[source]

Sample a value from this space.

Return type:

OutputT

seed(seed=None)[source]

Seed the native sampler for this space.

Parameters:

seed (int | None)

Return type:

int | None

property shape: list[int][source]

Native shape for tensor-like spaces.

property spec: SpaceSpec[source]

Native space specification backing this wrapper.

to_gymnasium_space()[source]

Convert this wrapper into a Gymnasium space.

Return type:

object

final class rlmesh.spaces.MultiBinary[source]

Bases: Space[None | bool | int | float | str | bytes | _Tensor | list[Value] | tuple[Value, …] | dict[str, Value]]

Binary vector or tensor space.

Parameters:

shape – Number of binary values, tensor shape, or native SpaceSpec.

__init__(shape)[source]
Parameters:

shape (int | Sequence[int] | SpaceSpec)

Return type:

None

contains(value)[source]

Return whether a value is contained in this space.

Parameters:

value (object)

Return type:

bool

property dtype: str[source]

Element dtype reported by the native spec.

property kind: str[source]

Native RLMesh space kind.

sample()[source]

Sample a value from this space.

Return type:

OutputT

seed(seed=None)[source]

Seed the native sampler for this space.

Parameters:

seed (int | None)

Return type:

int | None

property shape: list[int][source]

Native shape for tensor-like spaces.

property spec: SpaceSpec[source]

Native space specification backing this wrapper.

to_gymnasium_space()[source]

Convert this wrapper into a Gymnasium space.

Return type:

object

final class rlmesh.spaces.MultiDiscrete[source]

Bases: Space[None | bool | int | float | str | bytes | _Tensor | list[Value] | tuple[Value, …] | dict[str, Value]]

Vector of discrete dimensions.

Parameters:
  • nvec – Per-dimension counts, or an existing native SpaceSpec.

  • dtype – Integer dtype name.

__init__(nvec, dtype='int64')[source]
Parameters:
  • nvec (Sequence[int] | SpaceSpec)

  • dtype (str)

Return type:

None

contains(value)[source]

Return whether a value is contained in this space.

Parameters:

value (object)

Return type:

bool

property dtype: str[source]

Element dtype reported by the native spec.

property kind: str[source]

Native RLMesh space kind.

sample()[source]

Sample a value from this space.

Return type:

OutputT

seed(seed=None)[source]

Seed the native sampler for this space.

Parameters:

seed (int | None)

Return type:

int | None

property shape: list[int][source]

Native shape for tensor-like spaces.

property spec: SpaceSpec[source]

Native space specification backing this wrapper.

to_gymnasium_space()[source]

Convert this wrapper into a Gymnasium space.

Return type:

object

final class rlmesh.spaces.Text[source]

Bases: Space[None | bool | int | float | str | bytes | _Tensor | list[Value] | tuple[Value, …] | dict[str, Value]]

Bounded text space.

Parameters:
  • max_length – Maximum string length, or an existing native SpaceSpec.

  • min_length – Minimum string length.

  • charset – Optional allowed character set.

__init__(max_length, min_length=1, charset=None)[source]
Parameters:
  • max_length (int | SpaceSpec)

  • min_length (int)

  • charset (str | None)

Return type:

None

contains(value)[source]

Return whether a value is contained in this space.

Parameters:

value (object)

Return type:

bool

property dtype: str[source]

Element dtype reported by the native spec.

property kind: str[source]

Native RLMesh space kind.

sample()[source]

Sample a value from this space.

Return type:

OutputT

seed(seed=None)[source]

Seed the native sampler for this space.

Parameters:

seed (int | None)

Return type:

int | None

property shape: list[int][source]

Native shape for tensor-like spaces.

property spec: SpaceSpec[source]

Native space specification backing this wrapper.

to_gymnasium_space()[source]

Convert this wrapper into a Gymnasium space.

Return type:

object

Composite Spaces

Dict is stable. Tuple is experimental and may change; see Compatibility and the per-space labels in Gymnasium Compatibility.

final class rlmesh.spaces.Tuple[source]

Bases: Space[None | bool | int | float | str | bytes | _Tensor | list[Value] | tuple[Value, …] | dict[str, Value]]

Ordered tuple of child spaces.

Parameters:

spaces – Iterable of child spaces, or an existing native SpaceSpec.

__init__(spaces)[source]
Parameters:

spaces (Iterable[Space[Any] | SpaceSpec] | SpaceSpec)

Return type:

None

contains(value)[source]

Return whether a value is contained in this space.

Parameters:

value (object)

Return type:

bool

property dtype: str[source]

Element dtype reported by the native spec.

property kind: str[source]

Native RLMesh space kind.

sample()[source]

Sample a value from this space.

Return type:

OutputT

seed(seed=None)[source]

Seed the native sampler for this space.

Parameters:

seed (int | None)

Return type:

int | None

property shape: list[int][source]

Native shape for tensor-like spaces.

property spec: SpaceSpec[source]

Native space specification backing this wrapper.

to_gymnasium_space()[source]

Convert this wrapper into a Gymnasium space.

Return type:

object

final class rlmesh.spaces.Dict[source]

Bases: Space[None | bool | int | float | str | bytes | _Tensor | list[Value] | tuple[Value, …] | dict[str, Value]]

Mapping of named child spaces.

Exposes read-only mapping access over its children, mirroring gymnasium.spaces.Dict: index a child by name (space["obs"]), iterate names (for name in space), test membership ("obs" in space), take len(space), and read keys() / values() / items(). The children are immutable (a MappingProxyType); build a new Dict to change them.

Parameters:

spaces – Mapping of child spaces, or an existing native SpaceSpec.

__init__(spaces)[source]
Parameters:

spaces (Mapping[str, Space[Any] | SpaceSpec] | SpaceSpec)

Return type:

None

keys()[source]

The subspace names.

Return type:

KeysView[str]

values()[source]

The subspaces, in key order.

Return type:

ValuesView[Space[Value]]

items()[source]

The (name, subspace) pairs.

Return type:

ItemsView[str, Space[Value]]

contains(value)[source]

Return whether a value is contained in this space.

Parameters:

value (object)

Return type:

bool

property dtype: str[source]

Element dtype reported by the native spec.

property kind: str[source]

Native RLMesh space kind.

sample()[source]

Sample a value from this space.

Return type:

OutputT

seed(seed=None)[source]

Seed the native sampler for this space.

Parameters:

seed (int | None)

Return type:

int | None

property shape: list[int][source]

Native shape for tensor-like spaces.

property spec: SpaceSpec[source]

Native space specification backing this wrapper.

to_gymnasium_space()[source]

Convert this wrapper into a Gymnasium space.

Return type:

object