-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pixel observations for dmc #150
Draft
Benjamin-eecs
wants to merge
76
commits into
sail-sg:main
Choose a base branch
from
Benjamin-eecs:feature/pixel_obs_dmc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 66 commits
Commits
Show all changes
76 commits
Select commit
Hold shift + click to select a range
b7758f6
feat(pix-obs dmc): add init for visualization
Benjamin-eecs 1525024
feat(pix-obs dmc): init Render method
Benjamin-eecs fecae8e
feat(pix-obs dmc): physicsrender method finished without segmentation
Benjamin-eecs 781ca97
feat(pix-obs dmc): physicsrender method finished without segmentation
Benjamin-eecs 3599c84
Merge remote-tracking branch 'upstream/main' into feature/pixel_obs_dmc
Benjamin-eecs adb2392
feat(pix-obs dmc): init bazel BUILD
Benjamin-eecs c200d6f
Merge remote-tracking branch 'upstream/main' into feature/pixel_obs_dmc
Benjamin-eecs b0b3e51
fix(pix-obs dmc): merge upstream
Benjamin-eecs 29f217f
Merge branch 'main' into feature/pixel_obs_dmc
Benjamin-eecs 4a1c3d7
fix(pix-obs dmc): fix glfw
Benjamin-eecs d275b6e
Merge branch 'feature/pixel_obs_dmc' of https://github.com/Benjamin-e…
Benjamin-eecs f8e6036
fix(pix-obs dmc): fix glfw
Benjamin-eecs a2d754b
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs c4eaca1
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs 242b2f0
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs 5b6a77c
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs e346072
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs 950af99
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs dd643f4
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs fca61e0
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs 93afd2f
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs 3621eec
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs 15d5651
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs f67e988
fix(pix-obs dmc): fix lint
Benjamin-eecs feeac6b
Merge remote-tracking branch 'upstream/main' into dev
Benjamin-eecs f1e1750
Merge remote-tracking branch 'upstream/main' into dev
Benjamin-eecs 774d6ba
resolve conflicts
Benjamin-eecs f89b425
fix: pass lint
Benjamin-eecs a1ed423
fix: update mujoco BUILD file
Benjamin-eecs 6ae1612
Merge remote-tracking branch 'upstream/main' into feature/pixel_obs_dmc
Benjamin-eecs a5f1060
fix: update mujoco BUILD file
Benjamin-eecs f8e0e4b
fix: use EGL header
Benjamin-eecs ec8aeb3
fix: update types
Benjamin-eecs c40b533
fix: update types
Benjamin-eecs 2a706bd
fix: update types
Benjamin-eecs 881734b
fix: update stack wrapper
Benjamin-eecs a7e8138
fix: update stack wrapper
Benjamin-eecs 5ab45df
fix: update mujoco env argument
Benjamin-eecs ce36612
fix: update mujoco env arguments
Benjamin-eecs 66b0c8c
fix: update mujoco env arguments
Benjamin-eecs 3e4169c
fix: update mujoco env arguments
Benjamin-eecs 138c382
fix: update egl bazel build file
Benjamin-eecs 0dee3d1
fix: update egl bazel build file
Benjamin-eecs d4e3a41
fix: update egl bazel build file
Benjamin-eecs 10f36ff
fix: update egl bazel build file
Benjamin-eecs fd0a3ad
fix: update egl bazel build file
Benjamin-eecs e0a2e85
fix: update egl bazel build file
Benjamin-eecs 4b168ee
fix: update egl bazel build file
Benjamin-eecs bf4a08b
fix: egl initialization error
Benjamin-eecs ba0a868
fix: switch to osmesa gl backend
Benjamin-eecs 71c53e9
fix: switch to osmesa gl backend
Benjamin-eecs 8a0bc15
fix: switch to osmesa gl backend
Benjamin-eecs 129057a
fix: switch to osmesa gl backend
Benjamin-eecs e760f24
fix: switch to osmesa gl backend
Benjamin-eecs ff02df9
fix: switch to osmesa gl backend
Benjamin-eecs 0832add
fix: switch to osmesa gl backend
Benjamin-eecs e4a4f28
fix: switch to osmesa gl backend
Benjamin-eecs 314db6e
fix: switch to osmesa gl backend
Benjamin-eecs 55bebfb
fix: switch to osmesa gl backend
Benjamin-eecs 699397c
fix: switch to osmesa gl backend
Benjamin-eecs 6368c9d
fix: switch to osmesa gl backend
Benjamin-eecs b61fc58
fix: switch to osmesa gl backend
Benjamin-eecs 15f0a3a
fix: switch to osmesa gl backend
Benjamin-eecs 42dd819
fix: switch to osmesa gl backend
Benjamin-eecs 9f0bbd5
fix: switch to osmesa gl backend
Benjamin-eecs 778db9b
chore: comment on the unfixed code
Benjamin-eecs b94f4f1
fix: pass lint
Benjamin-eecs 329ec06
Merge branch 'main' into feature/pixel_obs_dmc
Benjamin-eecs 5ce57c0
Merge branch 'main' into feature/pixel_obs_dmc
Benjamin-eecs 62238fa
Merge branch 'main' into feature/pixel_obs_dmc
Benjamin-eecs 9055bc8
merge: sync with upstream main
Benjamin-eecs b5bfee5
merge: sync with upstream main
Benjamin-eecs 6998490
merge: sync with upstream main
Benjamin-eecs 2212d00
merge: sync with upstream main
Benjamin-eecs cb03ed2
Merge branch 'sail-sg:main' into feature/pixel_obs_dmc
Benjamin-eecs a29237c
Merge branch 'sail-sg:main' into feature/pixel_obs_dmc
Benjamin-eecs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,7 +126,7 @@ def test_make_mujoco_gym(self) -> None: | |
"Walker2d-v4", | ||
] | ||
) | ||
|
||
# make test with GL loading error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like the python side also needs to load GL. Now it pops out |
||
def test_make_mujoco_dmc(self) -> None: | ||
self.check_step( | ||
[ | ||
|
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
103 changes: 103 additions & 0 deletions
103
envpool/mujoco/dmc/mujoco_dmc_suite_ext_render_align_test.py
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,103 @@ | ||
# Copyright 2022 Garena Online Private Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Unit tests for Mujoco dm_control suite align check.""" | ||
|
||
from typing import Any, List, no_type_check | ||
|
||
import dm_env | ||
import numpy as np | ||
from absl import logging | ||
from absl.testing import absltest | ||
from dm_control import suite | ||
|
||
from envpool.mujoco.dmc import DmcHumanoidCMUDMEnvPool, DmcHumanoidCMUEnvSpec | ||
|
||
|
||
class _MujocoDmcSuiteExtAlignTest(absltest.TestCase): | ||
|
||
@no_type_check | ||
def run_space_check(self, env0: dm_env.Environment, env1: Any) -> None: | ||
"""Check observation_spec() and action_spec().""" | ||
obs0, obs1 = env0.observation_spec(), env1.observation_spec() | ||
for k in obs0: | ||
self.assertTrue(hasattr(obs1, k)) | ||
np.testing.assert_allclose(obs0[k].shape, getattr(obs1, k).shape) | ||
act0, act1 = env0.action_spec(), env1.action_spec() | ||
np.testing.assert_allclose(act0.shape, act1.shape) | ||
np.testing.assert_allclose(act0.minimum, act1.minimum) | ||
np.testing.assert_allclose(act0.maximum, act1.maximum) | ||
|
||
@no_type_check | ||
def reset_state( | ||
self, env: dm_env.Environment, ts: dm_env.TimeStep, domain: str, task: str | ||
) -> None: | ||
# manually reset, mimic initialize_episode | ||
with env.physics.reset_context(): | ||
env.physics.data.qpos = ts.observation.qpos0[0] | ||
if domain in ["humanoid_CMU"]: | ||
env.physics.after_reset() | ||
|
||
def sample_action(self, action_spec: dm_env.specs.Array) -> np.ndarray: | ||
return np.random.uniform( | ||
low=action_spec.minimum, | ||
high=action_spec.maximum, | ||
size=action_spec.shape, | ||
) | ||
|
||
def run_align_check( | ||
self, env0: dm_env.Environment, env1: Any, domain: str, task: str | ||
) -> None: | ||
logging.info(f"align check for {domain} {task}") | ||
obs_spec, action_spec = env0.observation_spec(), env0.action_spec() | ||
for i in range(3): | ||
np.random.seed(i) | ||
env0.reset() | ||
a = self.sample_action(action_spec) | ||
ts = env1.reset(np.array([0])) | ||
self.reset_state(env0, ts, domain, task) | ||
logging.info(f"reset qpos {ts.observation.qpos0[0]}") | ||
cnt = 0 | ||
done = False | ||
while not done: | ||
cnt += 1 | ||
a = self.sample_action(action_spec) | ||
# logging.info(f"{cnt} {a}") | ||
ts0 = env0.step(a) | ||
ts1 = env1.step(np.array([a]), np.array([0])) | ||
done = ts0.step_type == dm_env.StepType.LAST | ||
o0, o1 = ts0.observation, ts1.observation | ||
for k in obs_spec: | ||
np.testing.assert_allclose(o0[k], getattr(o1, k)[0]) | ||
np.testing.assert_allclose(ts0.step_type, ts1.step_type[0]) | ||
np.testing.assert_allclose(ts0.reward, ts1.reward[0], atol=1e-8) | ||
np.testing.assert_allclose(ts0.discount, ts1.discount[0]) | ||
|
||
def run_align_check_entry( | ||
self, domain: str, tasks: List[str], spec_cls: Any, envpool_cls: Any | ||
) -> None: | ||
for task in tasks: | ||
env0 = suite.load(domain, task) | ||
env1 = envpool_cls(spec_cls(spec_cls.gen_config(task_name=task))) | ||
self.run_space_check(env0, env1) | ||
self.run_align_check(env0, env1, domain, task) | ||
|
||
def test_humanoid_CMU(self) -> None: | ||
self.run_align_check_entry( | ||
"humanoid_CMU", ["stand", "run"], DmcHumanoidCMUEnvSpec, | ||
DmcHumanoidCMUDMEnvPool | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
absltest.main() |
81 changes: 81 additions & 0 deletions
81
envpool/mujoco/dmc/mujoco_dmc_suite_ext_render_deterministic_test.py
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,81 @@ | ||
# Copyright 2022 Garena Online Private Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Unit tests for Mujoco dm_control deterministic check.""" | ||
|
||
from typing import Any, List, Optional | ||
|
||
import dm_env | ||
import numpy as np | ||
from absl.testing import absltest | ||
|
||
from envpool.mujoco.dmc import DmcHumanoidCMUDMEnvPool, DmcHumanoidCMUEnvSpec | ||
|
||
|
||
class _MujocoDmcSuiteExtDeterministicTest(absltest.TestCase): | ||
|
||
def check( | ||
self, | ||
spec_cls: Any, | ||
envpool_cls: Any, | ||
task: str, | ||
obs_keys: List[str], | ||
blacklist: Optional[List[str]] = None, | ||
num_envs: int = 4, | ||
) -> None: | ||
np.random.seed(0) | ||
env0 = envpool_cls( | ||
spec_cls(spec_cls.gen_config(num_envs=num_envs, seed=0, task_name=task)) | ||
) | ||
env1 = envpool_cls( | ||
spec_cls(spec_cls.gen_config(num_envs=num_envs, seed=0, task_name=task)) | ||
) | ||
env2 = envpool_cls( | ||
spec_cls(spec_cls.gen_config(num_envs=num_envs, seed=1, task_name=task)) | ||
) | ||
act_spec = env0.action_spec() | ||
for t in range(3000): | ||
action = np.array( | ||
[ | ||
np.random.uniform( | ||
low=act_spec.minimum, high=act_spec.maximum, size=act_spec.shape | ||
) for _ in range(num_envs) | ||
] | ||
) | ||
ts0 = env0.step(action) | ||
obs0 = ts0.observation | ||
obs1 = env1.step(action).observation | ||
obs2 = env2.step(action).observation | ||
for k in obs_keys: | ||
o0 = getattr(obs0, k) | ||
o1 = getattr(obs1, k) | ||
o2 = getattr(obs2, k) | ||
np.testing.assert_allclose(o0, o1) | ||
if blacklist and k in blacklist: | ||
continue | ||
if np.abs(o0).sum() > 0 and ts0.step_type[0] != dm_env.StepType.FIRST: | ||
self.assertFalse(np.allclose(o0, o2), (t, k, o0, o2)) | ||
|
||
def test_humanoid_CMU(self) -> None: | ||
obs_keys = [ | ||
"joint_angles", "head_height", "extremities", "torso_vertical", | ||
"com_velocity", "velocity" | ||
] | ||
for task in ["stand", "run"]: | ||
self.check( | ||
DmcHumanoidCMUEnvSpec, DmcHumanoidCMUDMEnvPool, task, obs_keys | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
absltest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied from google-ai-edge/mediapipe#840