mpcrl.wrappers.agents.Wrapper#
- class mpcrl.wrappers.agents.Wrapper(agent)[source]#
Bases:
CallbackMixin,Generic[SymType]Wraps an instance of
mpcrl.Agentto allow a modular transformation of its behaviour. This class is the base class for all wrappers. The subclass could override some methods to change the behavior of the original agent without touching the original code.- Parameters:
- agentAgent or subclass
The agent to wrap.
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)[source]#
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)[source]#
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.