2023-11-07 13:27:25 +00:00
|
|
|
"""Test suite for ClipAction wrapper."""
|
|
|
|
|
2019-06-08 00:56:56 +02:00
|
|
|
import numpy as np
|
|
|
|
|
2023-11-07 13:27:25 +00:00
|
|
|
from gymnasium.spaces import Box
|
2022-09-08 10:10:07 +01:00
|
|
|
from gymnasium.wrappers import ClipAction
|
2023-11-07 13:27:25 +00:00
|
|
|
from tests.testing_env import GenericTestEnv
|
|
|
|
from tests.wrappers.utils import record_action_step
|
2019-06-08 00:56:56 +02:00
|
|
|
|
|
|
|
|
2023-11-07 13:27:25 +00:00
|
|
|
def test_clip_action_wrapper():
|
|
|
|
"""Test that the action is correctly clipped to the base environment action space."""
|
|
|
|
env = GenericTestEnv(
|
|
|
|
action_space=Box(np.array([0, 0, 3]), np.array([1, 2, 4])),
|
|
|
|
step_func=record_action_step,
|
2022-06-16 14:29:13 +01:00
|
|
|
)
|
2023-11-07 13:27:25 +00:00
|
|
|
wrapped_env = ClipAction(env)
|
2019-06-08 00:56:56 +02:00
|
|
|
|
2023-11-07 13:27:25 +00:00
|
|
|
sampled_action = np.array([-1, 5, 3.5], dtype=np.float32)
|
|
|
|
assert sampled_action not in env.action_space
|
|
|
|
assert sampled_action in wrapped_env.action_space
|
2019-06-08 00:56:56 +02:00
|
|
|
|
2023-11-07 13:27:25 +00:00
|
|
|
_, _, _, _, info = wrapped_env.step(sampled_action)
|
|
|
|
assert np.all(info["action"] in env.action_space)
|
|
|
|
assert np.all(info["action"] == np.array([0, 2, 3.5]))
|