2022-12-10 22:04:14 +00:00
|
|
|
"""Test suite for lambda observation wrappers."""
|
2022-11-20 00:57:10 +01:00
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2022-12-10 22:04:14 +00:00
|
|
|
from gymnasium.experimental.wrappers import LambdaObservationV0
|
|
|
|
from gymnasium.spaces import Box
|
|
|
|
from tests.experimental.wrappers.utils import (
|
|
|
|
check_obs,
|
|
|
|
record_action_as_obs_step,
|
|
|
|
record_obs_reset,
|
2022-12-05 19:14:56 +00:00
|
|
|
)
|
|
|
|
from tests.testing_env import GenericTestEnv
|
2022-11-20 00:57:10 +01:00
|
|
|
|
2022-12-04 22:24:02 +08:00
|
|
|
|
2022-12-05 19:14:56 +00:00
|
|
|
def test_lambda_observation_wrapper():
|
|
|
|
"""Tests lambda observation that the function is applied to both the reset and step observation."""
|
|
|
|
env = GenericTestEnv(
|
2022-12-10 22:04:14 +00:00
|
|
|
reset_func=record_obs_reset, step_func=record_action_as_obs_step
|
2022-12-05 19:14:56 +00:00
|
|
|
)
|
2022-12-10 22:04:14 +00:00
|
|
|
wrapped_env = LambdaObservationV0(env, lambda _obs: _obs + 2, Box(2, 3))
|
2022-12-05 19:14:56 +00:00
|
|
|
|
|
|
|
obs, info = wrapped_env.reset(options={"obs": np.array([0], dtype=np.float32)})
|
2022-12-10 22:04:14 +00:00
|
|
|
check_obs(env, wrapped_env, obs, info["obs"])
|
2022-12-05 19:14:56 +00:00
|
|
|
|
|
|
|
obs, _, _, _, info = wrapped_env.step(np.array([1], dtype=np.float32))
|
2022-12-10 22:04:14 +00:00
|
|
|
check_obs(env, wrapped_env, obs, info["obs"])
|