rldurham.VideoRecorder
- class rldurham.VideoRecorder(*args, name_func, **kwargs)[source]
Bases:
RecordVideo
Public Data Attributes:
frames_per_sec
name_prefix
video_length
recording
recorded_frames
render_history
Returns the
Env
metadata
.Returns the
Env
render_mode
.Returns the
Env
spec
attribute with the WrapperSpec if the wrapper inherits from EzPickle.Return the
Env
action_space
unless overwritten then the wrapperaction_space
is used.Return the
Env
observation_space
unless overwritten then the wrapperobservation_space
is used.Inherited from
Wrapper
np_random_seed
Returns the base environment's
np_random_seed
.unwrapped
Returns the base environment of the wrapper.
spec
Returns the
Env
spec
attribute with the WrapperSpec if the wrapper inherits from EzPickle.action_space
Return the
Env
action_space
unless overwritten then the wrapperaction_space
is used.observation_space
Return the
Env
observation_space
unless overwritten then the wrapperobservation_space
is used.metadata
Returns the
Env
metadata
.render_mode
Returns the
Env
render_mode
.np_random
Returns the
Env
np_random
attribute.Inherited from
Env
metadata
render_mode
spec
unwrapped
Returns the base non-wrapped environment.
np_random_seed
Returns the environment's internal
_np_random_seed
that if not set will first initialise with a random int as seed.np_random
Returns the environment's internal
_np_random
that if not set will initialise with a random seed.action_space
observation_space
Public 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 theenv
that can be overwritten to change the returned data.reset
(*[, seed, options])Uses the
reset()
of theenv
that can be overwritten to change the returned data.render
()Uses the
render()
of theenv
that 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
env
representation string.__repr__
()Returns the string representation of the wrapper.
class_name
()Returns the class name of the wrapper.
Inherited from
Env
step
(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_mode
during 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
spec
id'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_spec
This code will never be run due to __getattr__ being called prior this.
_saved_kwargs
Inherited from
Wrapper
_np_random
This code will never be run due to __getattr__ being called prior this.
Inherited from
Env
_np_random
_np_random_seed
Private 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
True
iff a recording should be started at this episode step_trigger: Function that accepts an integer and returnsTrue
iff 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
None
thenthe environment metadata
render_fps
key 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
env
representation 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
Env
action_space
unless overwritten then the wrapperaction_space
is 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
Env
observation_space
unless overwritten then the wrapperobservation_space
is 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
Env
render_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
Env
spec
attribute 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.Env
environment, underneath all layers of wrappers.
- classmethod wrapper_spec(**kwargs)
Generates a WrapperSpec for the wrappers.
- Return type:
WrapperSpec