Files
Gymnasium/gymnasium/experimental/wrappers/lambda_action.py

31 lines
801 B
Python
Raw Normal View History

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
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)