From 79fee79fd0df1d735d7792fc78ff27fcfce14fbe Mon Sep 17 00:00:00 2001 From: Jiayi Weng Date: Mon, 23 May 2022 14:31:52 -0400 Subject: [PATCH 1/6] add mujoco source --- envpool/mujoco/BUILD | 9 --- envpool/workspace0.bzl | 68 +++++++++++++++++-- third_party/ccd/BUILD | 0 third_party/ccd/ccd.BUILD | 20 ++++++ third_party/lodepng/BUILD | 0 third_party/lodepng/lodepng.BUILD | 7 ++ third_party/mujoco/mujoco.BUILD | 26 ++++--- third_party/pip_requirements/requirements.txt | 4 +- third_party/qhull/BUILD | 0 third_party/qhull/qhull.BUILD | 8 +++ third_party/tinyobjloader/BUILD | 0 third_party/tinyobjloader/tinyobjloader.BUILD | 8 +++ third_party/tinyxml2/BUILD | 0 third_party/tinyxml2/tinyxml2.BUILD | 7 ++ 14 files changed, 132 insertions(+), 25 deletions(-) create mode 100644 third_party/ccd/BUILD create mode 100644 third_party/ccd/ccd.BUILD create mode 100644 third_party/lodepng/BUILD create mode 100644 third_party/lodepng/lodepng.BUILD create mode 100644 third_party/qhull/BUILD create mode 100644 third_party/qhull/qhull.BUILD create mode 100644 third_party/tinyobjloader/BUILD create mode 100644 third_party/tinyobjloader/tinyobjloader.BUILD create mode 100644 third_party/tinyxml2/BUILD create mode 100644 third_party/tinyxml2/tinyxml2.BUILD diff --git a/envpool/mujoco/BUILD b/envpool/mujoco/BUILD index 48523957..8c5d5d29 100644 --- a/envpool/mujoco/BUILD +++ b/envpool/mujoco/BUILD @@ -17,13 +17,6 @@ genrule( cmd = "mkdir -p $(OUTS) && cp -r $(SRCS) $(OUTS)", ) -genrule( - name = "gen_mujoco_so", - srcs = ["@mujoco//:mujoco_so"], - outs = ["libmujoco.so.2.1.5"], - cmd = "cp $< $@", -) - cc_library( name = "mujoco_gym_env", hdrs = [ @@ -107,7 +100,6 @@ py_library( srcs = ["dmc/__init__.py"], data = [ ":gen_mujoco_dmc_xml", - ":gen_mujoco_so", ":mujoco_dmc_envpool.so", ], deps = ["//envpool/python:api"], @@ -118,7 +110,6 @@ py_library( srcs = ["gym/__init__.py"], data = [ ":gen_mujoco_gym_xml", - ":gen_mujoco_so", ":mujoco_gym_envpool.so", ], deps = ["//envpool/python:api"], diff --git a/envpool/workspace0.bzl b/envpool/workspace0.bzl index 63189320..f4f36648 100644 --- a/envpool/workspace0.bzl +++ b/envpool/workspace0.bzl @@ -315,14 +315,74 @@ def workspace(): build_file = "//third_party/vizdoom_extra_maps:vizdoom_extra_maps.BUILD", ) + maybe( + http_archive, + name = "tinyxml2", + sha256 = "cc2f1417c308b1f6acc54f88eb70771a0bf65f76282ce5c40e54cfe52952702c", + strip_prefix = "tinyxml2-9.0.0", + urls = [ + "https://github.com/leethomason/tinyxml2/archive/refs/tags/9.0.0.tar.gz", + "https://ml.cs.tsinghua.edu.cn/~jiayi/envpool/leethomason/tinyxml2/9.0.0.tar.gz", + ], + build_file = "//third_party/tinyxml2:tinyxml2.BUILD", + ) + + maybe( + http_archive, + name = "lodepng", + sha256 = "28a7e91b0476caed45b9b98b42eb765301fa5c9f15146d760c8ded2437ed0dff", + strip_prefix = "lodepng-5601b8272a6850b7c5d693dd0c0e16da50be8d8d", + urls = [ + "https://github.com/lvandeve/lodepng/archive/5601b8272a6850b7c5d693dd0c0e16da50be8d8d.tar.gz", + "https://ml.cs.tsinghua.edu.cn/~jiayi/envpool/lvandeve/lodepng/5601b8272a6850b7c5d693dd0c0e16da50be8d8d.tar.gz", + ], + build_file = "//third_party/lodepng:lodepng.BUILD", + ) + + maybe( + http_archive, + name = "tinyobjloader", + sha256 = "f9061d790905416a8a6c6f3dbfee77c7665636de0a9dc750ce799b513ddba83c", + strip_prefix = "tinyobjloader-2.0.0rc9", + urls = [ + "https://github.com/tinyobjloader/tinyobjloader/archive/refs/tags/v2.0.0rc9.tar.gz", + "https://ml.cs.tsinghua.edu.cn/~jiayi/envpool/tinyobjloader/tinyobjloader/v2.0.0rc9.tar.gz", + ], + build_file = "//third_party/tinyobjloader:tinyobjloader.BUILD", + ) + + maybe( + http_archive, + name = "ccd", + sha256 = "542b6c47f522d581fbf39e51df32c7d1256ac0c626e7c2b41f1040d4b9d50d1e", + strip_prefix = "libccd-2.1", + urls = [ + "https://github.com/danfis/libccd/archive/refs/tags/v2.1.tar.gz", + "https://ml.cs.tsinghua.edu.cn/~jiayi/envpool/danfis/libccd/v2.1.tar.gz", + ], + build_file = "//third_party/ccd:ccd.BUILD", + ) + + maybe( + http_archive, + name = "qhull", + sha256 = "09e5e4c5b2b8a9e617a46876fef5a3d33e70aa1d08a163ff05d37701327c3be7", + strip_prefix = "qhull-8.1-alpha1", + urls = [ + "https://github.com/qhull/qhull/archive/refs/tags/v8.1-alpha1.tar.gz", + "https://ml.cs.tsinghua.edu.cn/~jiayi/envpool/qhull/qhull/v8.1-alpha1.tar.gz", + ], + build_file = "//third_party/qhull:qhull.BUILD", + ) + maybe( http_archive, name = "mujoco", - sha256 = "3f1804d28833295a310aac23279401936f2558dee63cd3778429577e4ab55dff", - strip_prefix = "mujoco-2.1.5", + sha256 = "5bd3847aca1f53e2467b680f797fe74ce6a1c20870e0fee534cfda38a25ea1d5", + strip_prefix = "mujoco-2.2.0", urls = [ - "https://github.com/deepmind/mujoco/releases/download/2.1.5/mujoco-2.1.5-linux-x86_64.tar.gz", - "https://ml.cs.tsinghua.edu.cn/~jiayi/envpool/deepmind/mujoco/mujoco-2.1.5-linux-x86_64.tar.gz", + "https://github.com/deepmind/mujoco/archive/refs/tags/2.2.0.tar.gz", + "https://ml.cs.tsinghua.edu.cn/~jiayi/envpool/deepmind/mujoco/2.2.0.tar.gz", ], build_file = "//third_party/mujoco:mujoco.BUILD", ) diff --git a/third_party/ccd/BUILD b/third_party/ccd/BUILD new file mode 100644 index 00000000..e69de29b diff --git a/third_party/ccd/ccd.BUILD b/third_party/ccd/ccd.BUILD new file mode 100644 index 00000000..6c256dee --- /dev/null +++ b/third_party/ccd/ccd.BUILD @@ -0,0 +1,20 @@ +load("@envpool//third_party:common.bzl", "template_rule") + +package(default_visibility = ["//visibility:public"]) + +template_rule( + name = "ccd_config", + src = "src/ccd/config.h.cmake.in", + out = "src/ccd/config.h", + substitutions = { + "#cmakedefine CCD_SINGLE": "", + "#cmakedefine CCD_DOUBLE": "#define CCD_DOUBLE", + }, +) + +cc_library( + name = "ccd", + srcs = glob(["src/*.h"]) + glob(["src/*.c"]) + [":ccd_config"], + hdrs = glob(["src/ccd/*.h"]), + includes = ["src"], +) diff --git a/third_party/lodepng/BUILD b/third_party/lodepng/BUILD new file mode 100644 index 00000000..e69de29b diff --git a/third_party/lodepng/lodepng.BUILD b/third_party/lodepng/lodepng.BUILD new file mode 100644 index 00000000..2e302bc1 --- /dev/null +++ b/third_party/lodepng/lodepng.BUILD @@ -0,0 +1,7 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "lodepng", + srcs = ["lodepng.cpp"], + hdrs = ["lodepng.h"], +) diff --git a/third_party/mujoco/mujoco.BUILD b/third_party/mujoco/mujoco.BUILD index d6eaa3a7..ef800aee 100644 --- a/third_party/mujoco/mujoco.BUILD +++ b/third_party/mujoco/mujoco.BUILD @@ -2,14 +2,20 @@ package(default_visibility = ["//visibility:public"]) cc_library( name = "mujoco_lib", - srcs = glob(["lib/*"]), - hdrs = glob(["include/*.h"]), - includes = ["include/"], - linkopts = ["-Wl,-rpath,'$$ORIGIN'"], - linkstatic = 0, -) - -filegroup( - name = "mujoco_so", - srcs = ["lib/libmujoco.so.2.1.5"], + srcs = glob(["src/**/*.h"]) + glob(["src/**/*.c"]) + glob(["src/**/*.cc"]) + glob(["src/**/*.inc"]), + hdrs = glob(["include/mujoco/*.h"]), + includes = [ + "include", + "include/mujoco", + "src", + ], + linkstatic = 1, + visibility = ["//visibility:public"], + deps = [ + "@ccd", + "@lodepng", + "@qhull", + "@tinyobjloader", + "@tinyxml2", + ], ) diff --git a/third_party/pip_requirements/requirements.txt b/third_party/pip_requirements/requirements.txt index 7b7ebaad..a5d3db7c 100644 --- a/third_party/pip_requirements/requirements.txt +++ b/third_party/pip_requirements/requirements.txt @@ -2,12 +2,12 @@ absl-py cloudpickle dm-env dm-tree -dm-control +dm-control>=1.0.3.post1 filelock gym pygame box2d -mujoco +mujoco>=2.2.0 mjc-mwe>=0.0.3 mujoco_py>=2.1.2.14 h5py diff --git a/third_party/qhull/BUILD b/third_party/qhull/BUILD new file mode 100644 index 00000000..e69de29b diff --git a/third_party/qhull/qhull.BUILD b/third_party/qhull/qhull.BUILD new file mode 100644 index 00000000..2e280db6 --- /dev/null +++ b/third_party/qhull/qhull.BUILD @@ -0,0 +1,8 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "qhull", + srcs = glob(["src/libqhull_r/*.h"]) + glob(["src/libqhull_r/*.c"]), + hdrs = glob(["src/libqhull_r/*.h"]), + includes = ["src/libqhull_r"], +) diff --git a/third_party/tinyobjloader/BUILD b/third_party/tinyobjloader/BUILD new file mode 100644 index 00000000..e69de29b diff --git a/third_party/tinyobjloader/tinyobjloader.BUILD b/third_party/tinyobjloader/tinyobjloader.BUILD new file mode 100644 index 00000000..ac29279d --- /dev/null +++ b/third_party/tinyobjloader/tinyobjloader.BUILD @@ -0,0 +1,8 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "tinyobjloader", + srcs = ["tiny_obj_loader.cc"], + hdrs = ["tiny_obj_loader.h"], + includes = ["."], +) diff --git a/third_party/tinyxml2/BUILD b/third_party/tinyxml2/BUILD new file mode 100644 index 00000000..e69de29b diff --git a/third_party/tinyxml2/tinyxml2.BUILD b/third_party/tinyxml2/tinyxml2.BUILD new file mode 100644 index 00000000..298cde85 --- /dev/null +++ b/third_party/tinyxml2/tinyxml2.BUILD @@ -0,0 +1,7 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "tinyxml2", + srcs = ["tinyxml2.cpp"], + hdrs = ["tinyxml2.h"], +) From e86794251b324fce2be3b7783ab2e460c2a0c23c Mon Sep 17 00:00:00 2001 From: Jiayi Weng Date: Mon, 23 May 2022 16:26:31 -0400 Subject: [PATCH 2/6] increase tolerance --- envpool/mujoco/dmc/mujoco_dmc_align_test.py | 25 +++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/envpool/mujoco/dmc/mujoco_dmc_align_test.py b/envpool/mujoco/dmc/mujoco_dmc_align_test.py index a47726ac..3d6ead14 100644 --- a/envpool/mujoco/dmc/mujoco_dmc_align_test.py +++ b/envpool/mujoco/dmc/mujoco_dmc_align_test.py @@ -150,7 +150,8 @@ def sample_action(self, action_spec: dm_env.specs.Array) -> np.ndarray: ) def run_align_check( - self, env0: dm_env.Environment, env1: Any, domain: str, task: str + self, env0: dm_env.Environment, env1: Any, domain: str, task: str, + total_step: int ) -> None: logging.info(f"align check for {domain} {task}") obs_spec, action_spec = env0.observation_spec(), env0.action_spec() @@ -163,7 +164,7 @@ def run_align_check( logging.info(f"reset qpos {ts.observation.qpos0[0]}") cnt = 0 done = False - while not done: + while not done and cnt <= total_step: cnt += 1 a = self.sample_action(action_spec) # logging.info(f"{cnt} {a}") @@ -172,19 +173,24 @@ def run_align_check( 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(o0[k], getattr(o1, k)[0], atol=1e-5) 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.reward, ts1.reward[0], atol=1e-5) 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 + self, + domain: str, + tasks: List[str], + spec_cls: Any, + envpool_cls: Any, + total_step: int = 1000, ) -> 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) + self.run_align_check(env0, env1, domain, task, total_step) def test_acrobot(self) -> None: self.run_align_check_entry( @@ -223,13 +229,13 @@ def test_fish(self) -> None: def test_hopper(self) -> None: self.run_align_check_entry( - "hopper", ["hop", "stand"], DmcHopperEnvSpec, DmcHopperDMEnvPool + "hopper", ["hop", "stand"], DmcHopperEnvSpec, DmcHopperDMEnvPool, 400 ) def test_humanoid(self) -> None: self.run_align_check_entry( "humanoid", ["stand", "walk", "run", "run_pure_state"], - DmcHumanoidEnvSpec, DmcHumanoidDMEnvPool + DmcHumanoidEnvSpec, DmcHumanoidDMEnvPool, 100 ) def test_manipulator(self) -> None: @@ -256,7 +262,8 @@ def test_reacher(self) -> None: def test_walker(self) -> None: self.run_align_check_entry( - "walker", ["run", "stand", "walk"], DmcWalkerEnvSpec, DmcWalkerDMEnvPool + "walker", ["run", "stand", "walk"], DmcWalkerEnvSpec, DmcWalkerDMEnvPool, + 200 ) From 01eddc10fbc207bfa2c12507b26821a841b61bc5 Mon Sep 17 00:00:00 2001 From: Jiayi Weng Date: Mon, 23 May 2022 16:39:14 -0400 Subject: [PATCH 3/6] increase tolerance gym --- envpool/mujoco/gym/mujoco_gym_align_test.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/envpool/mujoco/gym/mujoco_gym_align_test.py b/envpool/mujoco/gym/mujoco_gym_align_test.py index 37478fc2..d3be3c81 100644 --- a/envpool/mujoco/gym/mujoco_gym_align_test.py +++ b/envpool/mujoco/gym/mujoco_gym_align_test.py @@ -124,7 +124,10 @@ def test_half_cheetah(self) -> None: env0 = mjc_mwe.HalfCheetahEnv() env1 = GymHalfCheetahGymEnvPool( GymHalfCheetahEnvSpec( - GymHalfCheetahEnvSpec.gen_config(gym_reset_return_info=True) + GymHalfCheetahEnvSpec.gen_config( + gym_reset_return_info=True, + max_episode_steps=99, + ) ) ) self.run_space_check(env0, env1) @@ -186,6 +189,7 @@ def test_humanoid(self) -> None: terminate_when_unhealthy=False, exclude_current_positions_from_observation=False, gym_reset_return_info=True, + max_episode_steps=999, ) ) ) From 767301914ef5f9791e83434226f3dc3a3a375545 Mon Sep 17 00:00:00 2001 From: Jiayi Weng Date: Mon, 23 May 2022 21:06:08 -0400 Subject: [PATCH 4/6] align flags --- third_party/mujoco/mujoco.BUILD | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/third_party/mujoco/mujoco.BUILD b/third_party/mujoco/mujoco.BUILD index ef800aee..6d12c2eb 100644 --- a/third_party/mujoco/mujoco.BUILD +++ b/third_party/mujoco/mujoco.BUILD @@ -4,11 +4,23 @@ cc_library( name = "mujoco_lib", srcs = glob(["src/**/*.h"]) + glob(["src/**/*.c"]) + glob(["src/**/*.cc"]) + glob(["src/**/*.inc"]), hdrs = glob(["include/mujoco/*.h"]), + copts = [ + "-mavx", + "-Wno-int-in-bool-context", + "-Wno-maybe-uninitialized", + "-Wno-sign-compare", + "-Wno-stringop-overflow", + "-Wno-stringop-truncation", + ], includes = [ "include", "include/mujoco", "src", ], + linkopts = [ + "-fuse-ld=gold", + "-Wl,--gc-sections", + ], linkstatic = 1, visibility = ["//visibility:public"], deps = [ From 221c8844c308e3f6922e9183ea5649d08f72f179 Mon Sep 17 00:00:00 2001 From: Jiayi Weng Date: Tue, 24 May 2022 18:01:49 -0400 Subject: [PATCH 5/6] change source code archive hash because of https://github.com/deepmind/mujoco/issues/296 --- envpool/workspace0.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/envpool/workspace0.bzl b/envpool/workspace0.bzl index 426761fb..309d8d21 100644 --- a/envpool/workspace0.bzl +++ b/envpool/workspace0.bzl @@ -378,7 +378,7 @@ def workspace(): maybe( http_archive, name = "mujoco", - sha256 = "5bd3847aca1f53e2467b680f797fe74ce6a1c20870e0fee534cfda38a25ea1d5", + sha256 = "98cab2735817456c028e96ba34b2ee2c94cc4fab33ebcae15ab46fcc45a762ad", strip_prefix = "mujoco-2.2.0", urls = [ "https://github.com/deepmind/mujoco/archive/refs/tags/2.2.0.tar.gz", From 00a17108aa61698790b1bfe7049a89bbddbee474 Mon Sep 17 00:00:00 2001 From: Jiayi Weng Date: Tue, 24 May 2022 21:19:10 -0400 Subject: [PATCH 6/6] build wheel --- .github/workflows/release.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1150e846..35d96f5c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,10 +1,10 @@ name: Release PyPI Wheel -# on: [push, pull_request] -on: - push: - branches: - - main +on: [push, pull_request] +# on: +# push: +# branches: +# - main jobs: release: