rldurham.Recorder
- class rldurham.Recorder(env, info=True, video=False, logs=False, key='recorder', video_folder='videos', video_prefix='xxxx00-agent-video', full_stats=False, smoothing=None)[source]
Bases:
Wrapper,RecordConstructorArgsPublic Data Attributes:
Returns 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__(env[, info, video, logs, key, ...])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.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:
_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:
_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>, '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__': {'_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]'}, '__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, key='recorder', video_folder='videos', video_prefix='xxxx00-agent-video', full_stats=False, smoothing=None)[source]
Wraps an environment to allow a modular transformation of the
step()andreset()methods.- Args:
env: The environment to wrap
- 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
- 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
- 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