unienv_interface.wrapper.video_record¶
Classes:
| Name | Description |
|---|---|
EpisodeRenderStackWrapper |
|
EpisodeVideoWrapper |
|
EpisodeWandbVideoWrapper |
|
Functions:
| Name | Description |
|---|---|
image_specs_from_space |
The image leaves of |
image_to_hwc_rgb |
Convert an image described by |
Attributes:
| Name | Type | Description |
|---|---|---|
ImageSpecs |
|
EpisodeRenderStackWrapper
¶
EpisodeRenderStackWrapper(
env: Env[
BArrayType,
ContextType,
ObsType,
ActType,
RenderFrame,
BDeviceType,
BDtypeType,
BRNGType,
],
*,
done_index: Optional[int] = None,
rendered_index: Optional[int] = None,
nested_separator: str = ".",
frame_source: Literal["render", "observation"] = "render",
frame_space: Optional[Space] = None,
)
Bases: Wrapper[BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType, BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType]
Initialize the wrapper.
For a batched environment, done_index is used to check episode termination on a specific batch index.
If rendered_index is provided, render outputs that are batched tensors are indexed at this batch index before caching/logging.
Frames are taken from env.render() (frame_source="render") or from the observations returned by
reset / step (frame_source="observation"). frame_space describes the frames; it defaults to
env.observation_space for observation frames. When its leaves declare Space.metadata, only the
leaves with kind == "image" are recorded, converted to (H, W, 3) RGB according to their layout
("CHW" is moved channel-last) and format ("bgr", "rgba", "gray", ...). Without any kind
metadata, every render frame is recorded as an RGB image (and, for observation frames, every
(H, W, 3) leaf).
Methods:
| Name | Description |
|---|---|
step |
|
reset |
|
render |
|
close |
|
sample_space |
Sample from |
sample_action |
Sample one action from |
sample_observation |
Sample one observation from |
sample_context |
Sample one context value if |
update_observation_post_reset |
Merge masked reset observations back into a full batched observation. |
update_context_post_reset |
Merge masked reset contexts back into a full batched context. |
has_wrapper_attr |
Checks if the given attribute is within the wrapper or its environment. |
get_wrapper_attr |
Gets an attribute from the wrapper and lower environments if |
set_wrapper_attr |
Sets an attribute on this wrapper or lower environment if |
Attributes:
| Name | Type | Description |
|---|---|---|
done_index |
|
|
rendered_index |
|
|
nested_separator |
|
|
frame_source |
|
|
frame_space |
|
|
episodic_frames |
Union[List[Any], Dict[str, List[Any]]]
|
|
video_episode_num |
|
|
video_step_num |
|
|
video_episode_start_step |
|
|
metadata |
Dict[str, Any]
|
Returns the :attr: |
render_mode |
Optional[WrapperRenderFrame]
|
|
render_fps |
Optional[int]
|
|
backend |
ComputeBackend[Any, WrapperBDeviceT, Any, WrapperBRngT]
|
|
device |
Optional[WrapperBDeviceT]
|
|
batch_size |
Optional[int]
|
|
action_space |
Space[WrapperActT, WrapperBDeviceT, Any, WrapperBRngT]
|
|
observation_space |
Space[WrapperObsT, WrapperBDeviceT, Any, WrapperBRngT]
|
|
context_space |
Optional[Space[WrapperContextT, WrapperBDeviceT, Any, WrapperBRngT]]
|
|
rng |
WrapperBRngT
|
Returns the :attr: |
unwrapped |
Env
|
Returns the base environment of the wrapper. |
prev_wrapper_layer |
Env[BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType]
|
|
env |
|
action_space
property
writable
¶
action_space: Space[WrapperActT, WrapperBDeviceT, Any, WrapperBRngT]
observation_space
property
writable
¶
observation_space: Space[WrapperObsT, WrapperBDeviceT, Any, WrapperBRngT]
context_space
property
writable
¶
context_space: Optional[Space[WrapperContextT, WrapperBDeviceT, Any, WrapperBRngT]]
unwrapped
property
¶
unwrapped: Env
Returns the base environment of the wrapper.
This will be the bare :class:gymnasium.Env environment, underneath all layers of wrappers.
prev_wrapper_layer
property
¶
prev_wrapper_layer: Env[
BArrayType,
ContextType,
ObsType,
ActType,
RenderFrame,
BDeviceType,
BDtypeType,
BRNGType,
]
step
¶
step(
action: ActType,
) -> Tuple[
ObsType,
Union[SupportsFloat, BArrayType],
Union[bool, BArrayType],
Union[bool, BArrayType],
Dict[str, Any],
]
reset
¶
reset(
*args, mask: Optional[BArrayType] = None, seed: Optional[int] = None, **kwargs
) -> Tuple[ContextType, ObsType, Dict[str, Any]]
sample_context
¶
sample_context() -> Optional[ContextType]
Sample one context value if context_space is defined.
update_observation_post_reset
¶
update_observation_post_reset(
old_obs: ObsType, newobs_masked: ObsType, mask: BArrayType
) -> ObsType
Merge masked reset observations back into a full batched observation.
update_context_post_reset
¶
update_context_post_reset(
old_context: ContextType, new_context: ContextType, mask: BArrayType
) -> ContextType
Merge masked reset contexts back into a full batched context.
has_wrapper_attr
¶
Checks if the given attribute is within the wrapper or its environment.
get_wrapper_attr
¶
Gets an attribute from the wrapper and lower environments if name doesn't exist in this object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The variable name to get |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The variable with name in wrapper or lower environments |
set_wrapper_attr
¶
Sets an attribute on this wrapper or lower environment if name is already defined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The variable name |
required |
value
|
Any
|
The new variable value |
required |
EpisodeVideoWrapper
¶
EpisodeVideoWrapper(
env: Env[
BArrayType,
ContextType,
ObsType,
ActType,
RenderFrame,
BDeviceType,
BDtypeType,
BRNGType,
],
*,
store_dir: PathLike | str,
format: Literal["mp4", "gif", "webm"] = "webm",
done_index: Optional[int] = None,
rendered_index: Optional[int] = None,
nested_separator: str = ".",
frame_source: Literal["render", "observation"] = "render",
frame_space: Optional[Space] = None,
stream: bool = False,
)
Bases: EpisodeRenderStackWrapper[BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType]
stream=True encodes each frame as it is captured instead of holding the episode's frames in memory
until it ends (mp4 / webm only): long episodes of large frames, or many recorded envs, otherwise take
frames x height x width x 3 bytes each. The files and their names are the same either way.
Methods:
| Name | Description |
|---|---|
step |
|
reset |
|
render |
|
close |
|
sample_space |
Sample from |
sample_action |
Sample one action from |
sample_observation |
Sample one observation from |
sample_context |
Sample one context value if |
update_observation_post_reset |
Merge masked reset observations back into a full batched observation. |
update_context_post_reset |
Merge masked reset contexts back into a full batched context. |
has_wrapper_attr |
Checks if the given attribute is within the wrapper or its environment. |
get_wrapper_attr |
Gets an attribute from the wrapper and lower environments if |
set_wrapper_attr |
Sets an attribute on this wrapper or lower environment if |
Attributes:
| Name | Type | Description |
|---|---|---|
store_dir |
|
|
store_format |
|
|
stream |
|
|
metadata |
Dict[str, Any]
|
Returns the :attr: |
render_mode |
Optional[WrapperRenderFrame]
|
|
render_fps |
Optional[int]
|
|
backend |
ComputeBackend[Any, WrapperBDeviceT, Any, WrapperBRngT]
|
|
device |
Optional[WrapperBDeviceT]
|
|
batch_size |
Optional[int]
|
|
action_space |
Space[WrapperActT, WrapperBDeviceT, Any, WrapperBRngT]
|
|
observation_space |
Space[WrapperObsT, WrapperBDeviceT, Any, WrapperBRngT]
|
|
context_space |
Optional[Space[WrapperContextT, WrapperBDeviceT, Any, WrapperBRngT]]
|
|
rng |
WrapperBRngT
|
Returns the :attr: |
unwrapped |
Env
|
Returns the base environment of the wrapper. |
prev_wrapper_layer |
Env[BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType]
|
|
env |
|
|
done_index |
|
|
rendered_index |
|
|
nested_separator |
|
|
frame_source |
|
|
frame_space |
|
|
episodic_frames |
Union[List[Any], Dict[str, List[Any]]]
|
|
video_episode_num |
|
|
video_step_num |
|
|
video_episode_start_step |
|
action_space
property
writable
¶
action_space: Space[WrapperActT, WrapperBDeviceT, Any, WrapperBRngT]
observation_space
property
writable
¶
observation_space: Space[WrapperObsT, WrapperBDeviceT, Any, WrapperBRngT]
context_space
property
writable
¶
context_space: Optional[Space[WrapperContextT, WrapperBDeviceT, Any, WrapperBRngT]]
unwrapped
property
¶
unwrapped: Env
Returns the base environment of the wrapper.
This will be the bare :class:gymnasium.Env environment, underneath all layers of wrappers.
prev_wrapper_layer
property
¶
prev_wrapper_layer: Env[
BArrayType,
ContextType,
ObsType,
ActType,
RenderFrame,
BDeviceType,
BDtypeType,
BRNGType,
]
step
¶
step(
action: ActType,
) -> Tuple[
ObsType,
Union[SupportsFloat, BArrayType],
Union[bool, BArrayType],
Union[bool, BArrayType],
Dict[str, Any],
]
reset
¶
reset(
*args, mask: Optional[BArrayType] = None, seed: Optional[int] = None, **kwargs
) -> Tuple[ContextType, ObsType, Dict[str, Any]]
sample_context
¶
sample_context() -> Optional[ContextType]
Sample one context value if context_space is defined.
update_observation_post_reset
¶
update_observation_post_reset(
old_obs: ObsType, newobs_masked: ObsType, mask: BArrayType
) -> ObsType
Merge masked reset observations back into a full batched observation.
update_context_post_reset
¶
update_context_post_reset(
old_context: ContextType, new_context: ContextType, mask: BArrayType
) -> ContextType
Merge masked reset contexts back into a full batched context.
has_wrapper_attr
¶
Checks if the given attribute is within the wrapper or its environment.
get_wrapper_attr
¶
Gets an attribute from the wrapper and lower environments if name doesn't exist in this object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The variable name to get |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The variable with name in wrapper or lower environments |
set_wrapper_attr
¶
Sets an attribute on this wrapper or lower environment if name is already defined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The variable name |
required |
value
|
Any
|
The new variable value |
required |
EpisodeWandbVideoWrapper
¶
EpisodeWandbVideoWrapper(
env: Env[
BArrayType,
ContextType,
ObsType,
ActType,
RenderFrame,
BDeviceType,
BDtypeType,
BRNGType,
],
*,
wandb_log_key: str,
format: Literal["mp4", "gif", "webm"] = "webm",
control_wandb_step: bool = False,
log_wandb_episode_id: bool = True,
done_index: Optional[int] = None,
rendered_index: Optional[int] = None,
nested_separator: str = ".",
frame_source: Literal["render", "observation"] = "render",
frame_space: Optional[Space] = None,
)
Bases: EpisodeRenderStackWrapper[BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType]
Methods:
| Name | Description |
|---|---|
step |
|
reset |
|
render |
|
close |
|
sample_space |
Sample from |
sample_action |
Sample one action from |
sample_observation |
Sample one observation from |
sample_context |
Sample one context value if |
update_observation_post_reset |
Merge masked reset observations back into a full batched observation. |
update_context_post_reset |
Merge masked reset contexts back into a full batched context. |
has_wrapper_attr |
Checks if the given attribute is within the wrapper or its environment. |
get_wrapper_attr |
Gets an attribute from the wrapper and lower environments if |
set_wrapper_attr |
Sets an attribute on this wrapper or lower environment if |
Attributes:
| Name | Type | Description |
|---|---|---|
wandb |
|
|
wandb_log_key |
|
|
log_wandb_episode_id |
|
|
control_wandb_step |
|
|
store_format |
|
|
metadata |
Dict[str, Any]
|
Returns the :attr: |
render_mode |
Optional[WrapperRenderFrame]
|
|
render_fps |
Optional[int]
|
|
backend |
ComputeBackend[Any, WrapperBDeviceT, Any, WrapperBRngT]
|
|
device |
Optional[WrapperBDeviceT]
|
|
batch_size |
Optional[int]
|
|
action_space |
Space[WrapperActT, WrapperBDeviceT, Any, WrapperBRngT]
|
|
observation_space |
Space[WrapperObsT, WrapperBDeviceT, Any, WrapperBRngT]
|
|
context_space |
Optional[Space[WrapperContextT, WrapperBDeviceT, Any, WrapperBRngT]]
|
|
rng |
WrapperBRngT
|
Returns the :attr: |
unwrapped |
Env
|
Returns the base environment of the wrapper. |
prev_wrapper_layer |
Env[BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType]
|
|
env |
|
|
done_index |
|
|
rendered_index |
|
|
nested_separator |
|
|
frame_source |
|
|
frame_space |
|
|
episodic_frames |
Union[List[Any], Dict[str, List[Any]]]
|
|
video_episode_num |
|
|
video_step_num |
|
|
video_episode_start_step |
|
action_space
property
writable
¶
action_space: Space[WrapperActT, WrapperBDeviceT, Any, WrapperBRngT]
observation_space
property
writable
¶
observation_space: Space[WrapperObsT, WrapperBDeviceT, Any, WrapperBRngT]
context_space
property
writable
¶
context_space: Optional[Space[WrapperContextT, WrapperBDeviceT, Any, WrapperBRngT]]
unwrapped
property
¶
unwrapped: Env
Returns the base environment of the wrapper.
This will be the bare :class:gymnasium.Env environment, underneath all layers of wrappers.
prev_wrapper_layer
property
¶
prev_wrapper_layer: Env[
BArrayType,
ContextType,
ObsType,
ActType,
RenderFrame,
BDeviceType,
BDtypeType,
BRNGType,
]
step
¶
step(
action: ActType,
) -> Tuple[
ObsType,
Union[SupportsFloat, BArrayType],
Union[bool, BArrayType],
Union[bool, BArrayType],
Dict[str, Any],
]
reset
¶
reset(
*args, mask: Optional[BArrayType] = None, seed: Optional[int] = None, **kwargs
) -> Tuple[ContextType, ObsType, Dict[str, Any]]
sample_context
¶
sample_context() -> Optional[ContextType]
Sample one context value if context_space is defined.
update_observation_post_reset
¶
update_observation_post_reset(
old_obs: ObsType, newobs_masked: ObsType, mask: BArrayType
) -> ObsType
Merge masked reset observations back into a full batched observation.
update_context_post_reset
¶
update_context_post_reset(
old_context: ContextType, new_context: ContextType, mask: BArrayType
) -> ContextType
Merge masked reset contexts back into a full batched context.
has_wrapper_attr
¶
Checks if the given attribute is within the wrapper or its environment.
get_wrapper_attr
¶
Gets an attribute from the wrapper and lower environments if name doesn't exist in this object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The variable name to get |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The variable with name in wrapper or lower environments |
set_wrapper_attr
¶
Sets an attribute on this wrapper or lower environment if name is already defined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The variable name |
required |
value
|
Any
|
The new variable value |
required |
image_specs_from_space
¶
image_specs_from_space(
space: Optional[Space], nested_separator: str = "."
) -> Optional[ImageSpecs]
The image leaves of space declared through metadata["kind"] == "image".
Returns {flattened key: (layout, format)} (key None when space itself
is the image), or None when no leaf of space declares a kind at all,
i.e. the space carries no usable description and callers should fall back to
treating every frame as an RGB image.
image_to_hwc_rgb
¶
image_to_hwc_rgb(
image: ndarray, layout: Optional[str] = None, format: Optional[str] = None
) -> ndarray
Convert an image described by layout / format metadata to (H, W, 3) RGB.
layout "CHW" is moved channel-last; format "bgr" / "bgra" are
reordered, "rgba" drops alpha and "gray" is repeated over three channels.
None (or "HWC" / "rgb") leaves the image unchanged.