Abstract Policies
lerax.policy.AbstractPolicy
Bases:
Base class for policies.
Policies map observations and internal states to actions and new internal states.
Attributes:
| Name | Type | Description |
|---|---|---|
|
|
The name of the policy. |
|
|
The action space of the policy. |
|
|
The observation space of the policy. |
observation_space
instance-attribute
serialize
Serialize the model to the specified path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
|
The path to serialize to. |
required |
no_suffix
|
|
If True, do not append the ".eqx" suffix |
False
|
deserialize
classmethod
deserialize[**Params, ClassType](
path: str | Path,
*args: Params.args,
**kwargs: Params.kwargs,
) -> ClassType
Deserialize the model from the specified path. Must provide any additional arguments required by the class constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
|
The path to deserialize from. |
required |
*args
|
|
Additional arguments to pass to the class constructor |
()
|
**kwargs
|
|
Additional keyword arguments to pass to the class constructor |
{}
|
Returns:
| Type | Description |
|---|---|
|
The deserialized model. |
__call__
abstractmethod
__call__(
state: StateType,
observation: ObsType,
*,
key: Key | None = None,
action_mask: MaskType | None = None,
) -> tuple[StateType, ActType]
Return the next action and new internal state given the current observation and internal state.
A key can be provided for stochastic policies. If no key is provided, the policy should behave deterministically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
|
The current internal state of the policy. |
required |
observation
|
|
The current observation. |
required |
key
|
|
An optional JAX random key for stochastic policies. |
None
|
action_mask
|
|
An optional action mask. |
None
|
Returns:
| Type | Description |
|---|---|
|
The new internal state and the action to take. |
lerax.policy.AbstractPolicyState
Bases:
Base class for policy internal states.