Skip to content
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
wants to merge 76 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 63 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 May 30, 2022
1525024
feat(pix-obs dmc): init Render method
Benjamin-eecs May 31, 2022
fecae8e
feat(pix-obs dmc): physicsrender method finished without segmentation
Benjamin-eecs Jun 3, 2022
781ca97
feat(pix-obs dmc): physicsrender method finished without segmentation
Benjamin-eecs Jun 4, 2022
3599c84
Merge remote-tracking branch 'upstream/main' into feature/pixel_obs_dmc
Benjamin-eecs Jun 4, 2022
adb2392
feat(pix-obs dmc): init bazel BUILD
Benjamin-eecs Jun 4, 2022
c200d6f
Merge remote-tracking branch 'upstream/main' into feature/pixel_obs_dmc
Benjamin-eecs Jun 12, 2022
b0b3e51
fix(pix-obs dmc): merge upstream
Benjamin-eecs Jun 12, 2022
29f217f
Merge branch 'main' into feature/pixel_obs_dmc
Benjamin-eecs Jun 15, 2022
4a1c3d7
fix(pix-obs dmc): fix glfw
Benjamin-eecs Jun 16, 2022
d275b6e
Merge branch 'feature/pixel_obs_dmc' of https://github.com/Benjamin-e…
Benjamin-eecs Jun 16, 2022
f8e6036
fix(pix-obs dmc): fix glfw
Benjamin-eecs Jun 16, 2022
a2d754b
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs Jun 16, 2022
c4eaca1
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs Jun 16, 2022
242b2f0
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs Jun 16, 2022
5b6a77c
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs Jun 16, 2022
e346072
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs Jun 16, 2022
950af99
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs Jun 16, 2022
dd643f4
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs Jun 16, 2022
fca61e0
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs Jun 16, 2022
93afd2f
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs Jun 16, 2022
3621eec
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs Jun 16, 2022
15d5651
fix(pix-obs dmc): fix mujoco_env
Benjamin-eecs Jun 16, 2022
f67e988
fix(pix-obs dmc): fix lint
Benjamin-eecs Jun 16, 2022
feeac6b
Merge remote-tracking branch 'upstream/main' into dev
Benjamin-eecs Jun 27, 2022
f1e1750
Merge remote-tracking branch 'upstream/main' into dev
Benjamin-eecs Jul 1, 2022
774d6ba
resolve conflicts
Benjamin-eecs Jul 15, 2022
f89b425
fix: pass lint
Benjamin-eecs Jul 16, 2022
a1ed423
fix: update mujoco BUILD file
Benjamin-eecs Aug 15, 2022
6ae1612
Merge remote-tracking branch 'upstream/main' into feature/pixel_obs_dmc
Benjamin-eecs Aug 15, 2022
a5f1060
fix: update mujoco BUILD file
Benjamin-eecs Aug 15, 2022
f8e0e4b
fix: use EGL header
Benjamin-eecs Aug 15, 2022
ec8aeb3
fix: update types
Benjamin-eecs Aug 15, 2022
c40b533
fix: update types
Benjamin-eecs Aug 15, 2022
2a706bd
fix: update types
Benjamin-eecs Aug 15, 2022
881734b
fix: update stack wrapper
Benjamin-eecs Aug 15, 2022
a7e8138
fix: update stack wrapper
Benjamin-eecs Aug 15, 2022
5ab45df
fix: update mujoco env argument
Benjamin-eecs Aug 15, 2022
ce36612
fix: update mujoco env arguments
Benjamin-eecs Aug 15, 2022
66b0c8c
fix: update mujoco env arguments
Benjamin-eecs Aug 15, 2022
3e4169c
fix: update mujoco env arguments
Benjamin-eecs Aug 15, 2022
138c382
fix: update egl bazel build file
Benjamin-eecs Aug 15, 2022
0dee3d1
fix: update egl bazel build file
Benjamin-eecs Aug 15, 2022
d4e3a41
fix: update egl bazel build file
Benjamin-eecs Aug 15, 2022
10f36ff
fix: update egl bazel build file
Benjamin-eecs Aug 15, 2022
fd0a3ad
fix: update egl bazel build file
Benjamin-eecs Aug 15, 2022
e0a2e85
fix: update egl bazel build file
Benjamin-eecs Aug 15, 2022
4b168ee
fix: update egl bazel build file
Benjamin-eecs Aug 15, 2022
bf4a08b
fix: egl initialization error
Benjamin-eecs Aug 18, 2022
ba0a868
fix: switch to osmesa gl backend
Benjamin-eecs Aug 22, 2022
71c53e9
fix: switch to osmesa gl backend
Benjamin-eecs Aug 22, 2022
8a0bc15
fix: switch to osmesa gl backend
Benjamin-eecs Aug 22, 2022
129057a
fix: switch to osmesa gl backend
Benjamin-eecs Aug 22, 2022
e760f24
fix: switch to osmesa gl backend
Benjamin-eecs Aug 22, 2022
ff02df9
fix: switch to osmesa gl backend
Benjamin-eecs Aug 22, 2022
0832add
fix: switch to osmesa gl backend
Benjamin-eecs Aug 22, 2022
e4a4f28
fix: switch to osmesa gl backend
Benjamin-eecs Aug 22, 2022
314db6e
fix: switch to osmesa gl backend
Benjamin-eecs Aug 22, 2022
55bebfb
fix: switch to osmesa gl backend
Benjamin-eecs Aug 22, 2022
699397c
fix: switch to osmesa gl backend
Benjamin-eecs Aug 22, 2022
6368c9d
fix: switch to osmesa gl backend
Benjamin-eecs Aug 22, 2022
b61fc58
fix: switch to osmesa gl backend
Benjamin-eecs Aug 22, 2022
15f0a3a
fix: switch to osmesa gl backend
Benjamin-eecs Aug 22, 2022
42dd819
fix: switch to osmesa gl backend
Benjamin-eecs Aug 22, 2022
9f0bbd5
fix: switch to osmesa gl backend
Benjamin-eecs Aug 22, 2022
778db9b
chore: comment on the unfixed code
Benjamin-eecs Aug 22, 2022
b94f4f1
fix: pass lint
Benjamin-eecs Aug 22, 2022
329ec06
Merge branch 'main' into feature/pixel_obs_dmc
Benjamin-eecs Oct 31, 2022
5ce57c0
Merge branch 'main' into feature/pixel_obs_dmc
Benjamin-eecs Nov 6, 2022
62238fa
Merge branch 'main' into feature/pixel_obs_dmc
Benjamin-eecs Dec 8, 2022
9055bc8
merge: sync with upstream main
Benjamin-eecs Mar 25, 2023
b5bfee5
merge: sync with upstream main
Benjamin-eecs Mar 25, 2023
6998490
merge: sync with upstream main
Benjamin-eecs Mar 25, 2023
2212d00
merge: sync with upstream main
Benjamin-eecs Mar 25, 2023
cb03ed2
Merge branch 'sail-sg:main' into feature/pixel_obs_dmc
Benjamin-eecs Mar 26, 2023
a29237c
Merge branch 'sail-sg:main' into feature/pixel_obs_dmc
Benjamin-eecs Apr 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build --action_env=BAZEL_LINKOPTS=-static-libgcc
build --action_env=CUDA_DIR=/usr/local/cuda
build --incompatible_strict_action_env --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --client_env=BAZEL_CXXOPTS=-std=c++17
build:debug --cxxopt=-DENVPOOL_TEST --compilation_mode=dbg -s
build:test --cxxopt=-DENVPOOL_TEST --copt=-g0 --copt=-O3 --copt=-DNDEBUG --copt=-msse --copt=-msse2 --copt=-mmmx
build:test --cxxopt=-DENVPOOL_TEST --copt=-g0 --copt=-O3 --copt=-DNDEBUG --copt=-msse --copt=-msse2 --copt=-mmmx --copt=-DMESA_EGL_NO_X11_HEADERS --copt=-DEGL_NO_X11 --copt=-DMJ_OSMESA
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build:release --copt=-g0 --copt=-O3 --copt=-DNDEBUG --copt=-msse --copt=-msse2 --copt=-mmmx

build:clang-tidy --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect
Expand Down
4 changes: 4 additions & 0 deletions envpool/mujoco/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,15 @@ cc_library(
"dmc/walker.h",
],
data = [":gen_mujoco_dmc_xml"],
linkopts = [
"-lOSMesa",
],
deps = [
"//envpool/core:async_envpool",
"@mujoco//:mujoco_lib",
"@pugixml",
],
alwayslink = 1,
)

pybind_extension(
Expand Down
103 changes: 103 additions & 0 deletions envpool/mujoco/dmc/mujoco_dmc_suite_ext_render_align_test.py
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()
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()
Loading