mpcrl.wrappers.agents.Log#
- class mpcrl.wrappers.agents.Log(agent, log_name=None, level=20, to_file=False, mode='a', precision=3, log_frequencies=None, exclude_mandatory=None)[source]#
Bases:
Wrapper[SymType]A wrapper class for logging information about an agent.
- Parameters:
- agentLearningAgent or inheriting
Agent to wrap.
- log_namestr, optional
Name of the logger. If not provided, the name of the agent is used.
- levelint, optional
The logging level, by default
logging.INFO.- to_filebool, optional
Whether to write the log also to a file in the current directory. By default,
False.- modestr, optional
The mode for opening the logging faile, in case
to_file=True. By default, it appends to the file, if already present.- precisionint, optional
Precision for printing floats, by default
3.- log_frequenciesdict of (str, int), optional
A dict containing, for each logging call hook, its corresponding frequency. The calls for which a frequency can be set are:
"on_episode_start""on_episode_end""on_env_step""on_timestep_end""on_update".
If this dictionary does not contain an entry for a specific call, the call is assumed to be never logged.
- exclude_mandatoryiterable of str, optional
An iterable of strings that contains the default mandatory callbacks to be excluded. These mandatory callbacks that can be excluded are:
"on_mpc_failure""on_validation_start""on_validation_end""on_update_failure""on_training_start""on_training_end".
Methods
detach_wrapper([recursive])Detaches the wrapper from the agent, returning the unwrapped agent.
is_wrapped(wrapper_type)Gets whether the agent instance is wrapped or not by the wrapper type.
Attributes
Returns the original agent wrapped by this wrapper.
- detach_wrapper(recursive=False)#
Detaches the wrapper from the agent, returning the unwrapped agent. De facto, this method detaches all the hooks attached by this wrapper.
- Parameters:
- recursivebool, optional
If
True, detaches all the wrappers around the agent recursively.
- Returns:
- Agent or LearningAgent or Wrapper
Returns the wrapped agent (or other wrapper) instance. This instance has no more active hooks attached by this wrapper. If
recursive=True, all the wrappers around the agent and their hooks are detached.
- Return type:
Union[Agent[TypeVar(SymType,SX,MX)],LearningAgent[TypeVar(SymType,SX,MX),TypeVar(ExpType)],Wrapper[TypeVar(SymType,SX,MX)]]
Notes
Detaching a wrapper is useful when you want to make sure that the wrapper’s hooked callback cannot modify the behaviour or data of the agent, for example, after learning is done and you want to save and evaluate your learnt policy.
- is_wrapped(wrapper_type)#
Gets whether the agent instance is wrapped or not by the wrapper type.
- Parameters:
- wrapper_typetype of Wrapper
Type of wrapper to check if the agent is wrapped with.
- Returns:
- bool
Trueif wrapped by an instance ofwrapper_type;False, otherwise.
- Return type:
- property unwrapped: Agent[SymType] | LearningAgent[SymType, ExpType]#
Returns the original agent wrapped by this wrapper.