2022-11-20 00:57:10 +01:00
|
|
|
"""Lambda action wrapper which apply a function to the provided action."""
|
|
|
|
|
|
|
|
from typing import Any, Callable
|
|
|
|
|
|
|
|
import gymnasium as gym
|
|
|
|
from gymnasium.core import ActType
|
2022-11-29 23:37:53 +00:00
|
|
|
from gymnasium.experimental.wrappers import ArgType
|
2022-11-20 00:57:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
class LambdaActionV0(gym.ActionWrapper):
|
|
|
|
"""A wrapper that provides a function to modify the action passed to :meth:`step`."""
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
env: gym.Env,
|
|
|
|
func: Callable[[ArgType], Any],
|
|
|
|
):
|
|
|
|
"""Initialize LambdaAction.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
env (Env): The gymnasium environment
|
|
|
|
func (Callable): function to apply to action
|
|
|
|
"""
|
|
|
|
super().__init__(env)
|
|
|
|
|
|
|
|
self.func = func
|
|
|
|
|
|
|
|
def action(self, action: ActType) -> Any:
|
|
|
|
"""Apply function to action."""
|
|
|
|
return self.func(action)
|