2019-06-08 00:56:56 +02:00
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
import gym
|
|
|
|
from gym.wrappers import ClipAction
|
|
|
|
|
|
|
|
|
|
|
|
def test_clip_action():
|
|
|
|
# mountaincar: action-based rewards
|
Update the flake8 pre-commit ignores (#2778)
* Remove additional ignores from flake8
* Remove all unused imports
* Remove all unused imports
* Update flake8 and pyupgrade
* F841, removed unused variables
* E731, removed lambda assignment to variables
* Remove E731, F403, F405, F524
* Remove E722, bare exceptions
* Remove E712, compare variable == True or == False to is True or is False
* Remove E402, module level import not at top of file
* Added --pre-file-ignores
* Add --per-file-ignores removing E741, E302 and E704
* Add E741, do not use variables named ‘l’, ‘O’, or ‘I’ to ignore issues in classic control
* Fixed issues for pytest==6.2
* Remove unnecessary # noqa
* Edit comment with the removal of E302
* Added warnings and declared module, attr for pyright type hinting
* Remove unused import
* Removed flake8 E302
* Updated flake8 from 3.9.2 to 4.0.1
* Remove unused variable
2022-04-26 16:18:37 +01:00
|
|
|
env = gym.make("MountainCarContinuous-v0")
|
|
|
|
wrapped_env = ClipAction(gym.make("MountainCarContinuous-v0"))
|
2019-06-08 00:56:56 +02:00
|
|
|
|
|
|
|
seed = 0
|
|
|
|
|
2021-12-08 22:14:15 +01:00
|
|
|
env.reset(seed=seed)
|
|
|
|
wrapped_env.reset(seed=seed)
|
2019-06-08 00:56:56 +02:00
|
|
|
|
2021-07-29 02:26:34 +02:00
|
|
|
actions = [[0.4], [1.2], [-0.3], [0.0], [-2.5]]
|
2019-06-08 00:56:56 +02:00
|
|
|
for action in actions:
|
2021-07-29 15:39:42 -04:00
|
|
|
obs1, r1, d1, _ = env.step(
|
|
|
|
np.clip(action, env.action_space.low, env.action_space.high)
|
|
|
|
)
|
2019-06-08 00:56:56 +02:00
|
|
|
obs2, r2, d2, _ = wrapped_env.step(action)
|
|
|
|
assert np.allclose(r1, r2)
|
|
|
|
assert np.allclose(obs1, obs2)
|
|
|
|
assert d1 == d2
|