rldurham.Recorder
- class rldurham.Recorder(env, info=True, video=False, logs=False, ignore_existing=False, key='recorder', video_folder='videos', video_prefix='xxxx00-agent-video', full_stats=False, smoothing=None)[source]
Bases:
Wrapper,RecordConstructorArgsPublic Data Attributes:
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__(env[, info, video, logs, ...])Wrapper to record statistics, videos, and logs.
add_stats(info[, ignore_existing])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.close()Closes the wrapper and
env.write_log([folder, file])__getattr__(item)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:
Inherited from
Wrapper_np_randomThis code will never be run due to __getattr__ being called prior this.
_action_space_observation_space_metadata_cached_specInherited from
Env_np_random_np_random_seedInherited from
RecordConstructorArgs_saved_kwargsPrivate Methods:
_video_episode_trigger(episode_id)
- __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]: ….
- __dict__ = mappingproxy({'__module__': 'rldurham', '__init__': <function Recorder.__init__>, '_video_episode_trigger': <function Recorder._video_episode_trigger>, '_video_name_func': <function Recorder._video_name_func>, 'add_stats': <function Recorder.add_stats>, 'step': <function Recorder.step>, '_finish_episode': <function Recorder._finish_episode>, 'reset': <function Recorder.reset>, 'close': <function Recorder.close>, 'write_log': <function Recorder.write_log>, '__doc__': None, '__parameters__': (), '__getattr__': <function transparent_wrapper.<locals>.__getattr__>, '__annotations__': {}, '__slotnames__': []})
- __enter__()
Support with-statement for the environment.
- __exit__(*args)
Support with-statement for the environment and closes the environment.
- __getattr__(item)
- __init__(env, info=True, video=False, logs=False, ignore_existing=False, key='recorder', video_folder='videos', video_prefix='xxxx00-agent-video', full_stats=False, smoothing=None)[source]
Wrapper to record statistics, videos, and logs.
- The statistics added to info are
“idx”: index of this episode “length”: length of this episode “r_sum”: sum of rewards of this episode “r_mean”: mean reward of this episode “r_std”: standard deviation of rewards of this episode
- If smoothings is not None:
“length_”: smoothed length of episodes (i.e. smoothed version of “length”) “r_sum_”: sum (over smoothing window) of sum (over single episodes) of rewards “r_mean_”: average (over smoothing window) of sum (over single episodes) of rewards (i.e. smoothed
version of “r_sum”)
“r_std_”: standard deviation of sums over rewards (i.e. the std associated with “r_mean_”)
- if full_stats:
“full”: list of [(obs, reward, terminated, truncated, info), …] for episode
- Parameters:
env – environment
info – populate info dict with statistics at each step
video – wrap env with VideoRecorder and activate recording (can be deactivated by setting
video = Falseon the Recorder object)logs – keep logs of episode statistics (these are different stats from the ones in info and useful for evaluating training performance over episodes)
ignore_existing – silently skip adding stats in info if an entry with corresponding key already exists (otherwise raises a RuntimeError)
key – key used to store stats in info dict
video_folder – folder for storing videos
video_prefix – prefix for video files
full_stats – add full stats of (obs, reward, terminated, truncated, info) for each step of the episode
smoothing – add stats smoothed over this many time steps
- classmethod __init_subclass__()
Function to initialize subclasses.
- __module__ = 'rldurham'
- __orig_bases__ = (gymnasium.core.Env[~WrapperObsType, ~WrapperActType], typing.Generic[~WrapperObsType, ~WrapperActType, ~ObsType, ~ActType])
- __parameters__ = ()
- __repr__()
Returns the string representation of the wrapper.
- __slotnames__ = []
- __str__()
Returns the wrapper name and the
envrepresentation string.
- __weakref__
list of weak references to the object
- _action_space: Space[WrapperActType] | None
- _cached_spec: EnvSpec | None
- _metadata: dict[str, Any] | None
- 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
- _observation_space: Space[WrapperObsType] | 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
- 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()
Uses the
render()of theenvthat can be overwritten to change the returned data.- Return type:
Union[TypeVar(RenderFrame),list[TypeVar(RenderFrame)],None]
- property render_mode: str | None
Returns the
Envrender_mode.
- reset(*, seed=None, options=None)[source]
Uses the
reset()of theenvthat can be overwritten to change the returned data.
- 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.
- step(action)[source]
Uses the
step()of theenvthat can be overwritten to change the returned data.
- 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