-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add PybulletEnvironment class * refactor the way pybullet imports work * PybulletEnvironment accept kwargs * loosen constraint on pybullet env test
- Loading branch information
Showing
8 changed files
with
74 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from .gym import GymEnvironment | ||
|
||
|
||
class PybulletEnvironment(GymEnvironment): | ||
short_names = { | ||
"ant": "AntBulletEnv-v0", | ||
"cheetah": "HalfCheetahBulletEnv-v0", | ||
"humanoid": "HumanoidBulletEnv-v0", | ||
"hopper": "HopperBulletEnv-v0", | ||
"walker": "Walker2DBulletEnv-v0" | ||
} | ||
|
||
def __init__(self, name, **kwargs): | ||
import pybullet_envs | ||
if name in self.short_names: | ||
name = self.short_names[name] | ||
super().__init__(name, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import unittest | ||
from all.environments import PybulletEnvironment, GymEnvironment | ||
|
||
|
||
class PybulletEnvironmentTest(unittest.TestCase): | ||
def test_env_short_name(self): | ||
for short_name, long_name in PybulletEnvironment.short_names.items(): | ||
env = PybulletEnvironment(short_name) | ||
self.assertEqual(env.name, long_name) | ||
|
||
def test_env_full_name(self): | ||
env = PybulletEnvironment('HalfCheetahBulletEnv-v0') | ||
self.assertEqual(env.name, 'HalfCheetahBulletEnv-v0') | ||
|
||
def test_reset(self): | ||
env = PybulletEnvironment('cheetah') | ||
state = env.reset() | ||
self.assertEqual(state.observation.shape, (26,)) | ||
self.assertEqual(state.reward, 0.) | ||
self.assertFalse(state.done) | ||
self.assertEqual(state.mask, 1) | ||
|
||
def test_step(self): | ||
env = PybulletEnvironment('cheetah') | ||
env.seed(0) | ||
state = env.reset() | ||
state = env.step(env.action_space.sample()) | ||
self.assertEqual(state.observation.shape, (26,)) | ||
self.assertGreater(state.reward, -1.) | ||
self.assertLess(state.reward, 1) | ||
self.assertNotEqual(state.reward, 0.) | ||
self.assertFalse(state.done) | ||
self.assertEqual(state.mask, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters