rldurham.VideoRecorder
- class rldurham.VideoRecorder(*args, name_func, **kwargs)[source]
Bases:
RecordVideoPublic Data Attributes:
frames_per_secname_prefixvideo_lengthrecordingrecorded_framesrender_historyReturns the
Envmetadata.Returns the
Envrender_mode.Returns the
Envspecattribute with the WrapperSpec if the wrapper inherits from EzPickle.Return the
Envaction_spaceunless overwritten then the wrapperaction_spaceis used.Return the
Envobservation_spaceunless overwritten then the wrapperobservation_spaceis used.Inherited from
Wrappernp_random_seedReturns the base environment's
np_random_seed.unwrappedReturns the base environment of the wrapper.
specReturns the
Envspecattribute with the WrapperSpec if the wrapper inherits from EzPickle.action_spaceReturn the
Envaction_spaceunless overwritten then the wrapperaction_spaceis used.observation_spaceReturn the
Envobservation_spaceunless overwritten then the wrapperobservation_spaceis used.metadataReturns the
Envmetadata.render_modeReturns the
Envrender_mode.np_randomReturns the
Envnp_randomattribute.Inherited from
Envmetadatarender_modespecunwrappedReturns the base non-wrapped environment.
np_random_seedReturns the environment's internal
_np_random_seedthat if not set will first initialise with a random int as seed.np_randomReturns the environment's internal
_np_randomthat if not set will initialise with a random seed.action_spaceobservation_spacePublic Methods:
__init__(*args, name_func, **kwargs)Wrapper records videos of rollouts.
Stop current recording and saves the video.
__getattr__(item)Inherited from
RecordVideo__init__(env, video_folder[, ...])Wrapper records videos of rollouts.
reset(*[, seed, options])Reset the environment and eventually starts a new recording.
step(action)Steps through the environment using action, recording observations if
self.recording.render()Compute the render frames as specified by render_mode attribute during initialization of the environment.
close()Closes the wrapper then the video recorder.
start_recording(video_name)Start a new recording.
stop_recording()Stop current recording and saves the video.
__del__()Warn the user in case last video wasn't saved.
Inherited from
Wrapper__init__(env)Wraps an environment to allow a modular transformation of the
step()andreset()methods.step(action)Uses the
step()of theenvthat can be overwritten to change the returned data.reset(*[, seed, options])Uses the
reset()of theenvthat can be overwritten to change the returned data.render()Uses the
render()of theenvthat can be overwritten to change the returned data.close()Closes the wrapper and
env.wrapper_spec(**kwargs)Generates a WrapperSpec for the wrappers.
has_wrapper_attr(name)Checks if the given attribute is within the wrapper or its environment.
get_wrapper_attr(name)Gets an attribute from the wrapper and lower environments if name doesn't exist in this object.
set_wrapper_attr(name, value, *[, force])Sets an attribute on this wrapper or lower environment if name is already defined.
__str__()Returns the wrapper name and the
envrepresentation string.__repr__()Returns the string representation of the wrapper.
class_name()Returns the class name of the wrapper.
Inherited from
Envstep(action)Run one timestep of the environment's dynamics using the agent actions.
reset(*[, seed, options])Resets the environment to an initial internal state, returning an initial observation and info.
render()Compute the render frames as specified by
render_modeduring the initialization of the environment.close()After the user has finished using the environment, close contains the code necessary to "clean up" the environment.
__str__()Returns a string of the environment with
specid's if :attr:`spec.__enter__()Support with-statement for the environment.
__exit__(*args)Support with-statement for the environment and closes the environment.
has_wrapper_attr(name)Checks if the attribute name exists in the environment.
get_wrapper_attr(name)Gets the attribute name from the environment.
set_wrapper_attr(name, value, *[, force])Sets the attribute name on the environment with value, see Wrapper.set_wrapper_attr for more info.
Inherited from
Generic__class_getitem__Parameterizes a generic class.
__init_subclass__Function to initialize subclasses.
Inherited from
RecordConstructorArgs__init__(*[, _disable_deepcopy])Records all arguments passed to constructor to _saved_kwargs.
Private Data Attributes:
_video_name_action_space_observation_space_metadata_cached_specThis code will never be run due to __getattr__ being called prior this.
_saved_kwargsInherited from
Wrapper_np_randomThis code will never be run due to __getattr__ being called prior this.
Inherited from
Env_np_random_np_random_seedPrivate Methods:
Inherited from
RecordVideo_capture_frame()
- __annotations__ = {}
- classmethod __class_getitem__()
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….
- __del__()
Warn the user in case last video wasn’t saved.
- __dict__ = mappingproxy({'__module__': 'rldurham', '__init__': <function VideoRecorder.__init__>, 'stop_recording': <function VideoRecorder.stop_recording>, '__doc__': None, '__parameters__': (), '__annotations__': {'frames_per_sec': 'int', 'name_prefix': 'str', '_video_name': 'str | None', 'video_length': 'int', 'recording': 'bool', 'recorded_frames': 'list[RenderFrame]', 'render_history': 'list[RenderFrame]', '_action_space': 'spaces.Space[WrapperActType] | None', '_observation_space': 'spaces.Space[WrapperObsType] | None', '_metadata': 'dict[str, Any] | None', '_cached_spec': 'EnvSpec | None', 'metadata': 'dict[str, Any]', 'render_mode': 'str | None', 'spec': 'EnvSpec | None', 'action_space': 'spaces.Space[ActType]', 'observation_space': 'spaces.Space[ObsType]', '_np_random': 'np.random.Generator | None', '_np_random_seed': 'int | None', '_saved_kwargs': 'dict[str, Any]'}, '__getattr__': <function transparent_wrapper.<locals>.__getattr__>})
- __enter__()
Support with-statement for the environment.
- __exit__(*args)
Support with-statement for the environment and closes the environment.
- __getattr__(item)
- __init__(*args, name_func, **kwargs)[source]
Wrapper records videos of rollouts.
- Args:
env: The environment that will be wrapped video_folder (str): The folder where the recordings will be stored episode_trigger: Function that accepts an integer and returns
Trueiff a recording should be started at this episode step_trigger: Function that accepts an integer and returnsTrueiff a recording should be started at this step video_length (int): The length of recorded episodes. If 0, entire episodes are recorded.Otherwise, snippets of the specified length are captured
name_prefix (str): Will be prepended to the filename of the recordings fps (int): The frame per second in the video. Provides a custom video fps for environment, if
Nonethenthe environment metadata
render_fpskey is used if it exists, otherwise a default value of 30 is used.disable_logger (bool): Whether to disable moviepy logger or not, default it is disabled
- classmethod __init_subclass__()
Function to initialize subclasses.
- __module__ = 'rldurham'
- __orig_bases__ = (gymnasium.core.Wrapper[~ObsType, ~ActType, ~ObsType, ~ActType], <class 'gymnasium.utils.record_constructor.RecordConstructorArgs'>)
- __parameters__ = ()
- __repr__()
Returns the string representation of the wrapper.
- __str__()
Returns the wrapper name and the
envrepresentation string.
- __weakref__
list of weak references to the object
- _capture_frame()
- property _np_random
This code will never be run due to __getattr__ being called prior this.
It seems that @property overwrites the variable (_np_random) meaning that __getattr__ gets called with the missing variable.
- _np_random_seed: int | None = None
- property action_space: Space[ActType] | Space[WrapperActType]
Return the
Envaction_spaceunless overwritten then the wrapperaction_spaceis used.
- classmethod class_name()
Returns the class name of the wrapper.
- Return type:
str
- close()
Closes the wrapper then the video recorder.
- get_wrapper_attr(name)
Gets an attribute from the wrapper and lower environments if name doesn’t exist in this object.
- Return type:
Any
- Args:
name: The variable name to get
- Returns:
The variable with name in wrapper or lower environments
- has_wrapper_attr(name)
Checks if the given attribute is within the wrapper or its environment.
- Return type:
bool
- property np_random_seed: int | None
Returns the base environment’s
np_random_seed.
- property observation_space: Space[ObsType] | Space[WrapperObsType]
Return the
Envobservation_spaceunless overwritten then the wrapperobservation_spaceis used.
- render()
Compute the render frames as specified by render_mode attribute during initialization of the environment.
- Return type:
Union[TypeVar(RenderFrame),list[TypeVar(RenderFrame)]]
- property render_mode: str | None
Returns the
Envrender_mode.
- reset(*, seed=None, options=None)
Reset the environment and eventually starts a new recording.
- Return type:
tuple[TypeVar(ObsType),dict[str,Any]]
- set_wrapper_attr(name, value, *, force=True)
Sets an attribute on this wrapper or lower environment if name is already defined.
- Return type:
bool
- Args:
name: The variable name value: The new variable value force: Whether to create the attribute on this wrapper if it does not exists on the
lower environment instead of raising an exception
- Returns:
If the variable has been set in this or a lower wrapper.
- property spec: EnvSpec | None
Returns the
Envspecattribute with the WrapperSpec if the wrapper inherits from EzPickle.
- start_recording(video_name)
Start a new recording. If it is already recording, stops the current recording before starting the new one.
- step(action)
Steps through the environment using action, recording observations if
self.recording.- Return type:
tuple[TypeVar(ObsType),SupportsFloat,bool,bool,dict[str,Any]]
- property unwrapped: Env[ObsType, ActType]
Returns the base environment of the wrapper.
This will be the bare
gymnasium.Envenvironment, underneath all layers of wrappers.
- classmethod wrapper_spec(**kwargs)
Generates a WrapperSpec for the wrappers.
- Return type:
WrapperSpec