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

Build mujoco from source code #141

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
9 changes: 0 additions & 9 deletions envpool/mujoco/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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.2.1"],
cmd = "cp $< $@",
)

cc_library(
name = "mujoco_gym_env",
hdrs = [
Expand Down Expand Up @@ -109,7 +102,6 @@ py_library(
srcs = ["dmc/__init__.py"],
data = [
":gen_mujoco_dmc_xml",
":gen_mujoco_so",
":mujoco_dmc_envpool.so",
],
deps = ["//envpool/python:api"],
Expand All @@ -120,7 +112,6 @@ py_library(
srcs = ["gym/__init__.py"],
data = [
":gen_mujoco_gym_xml",
":gen_mujoco_so",
":mujoco_gym_envpool.so",
],
deps = ["//envpool/python:api"],
Expand Down
25 changes: 16 additions & 9 deletions envpool/mujoco/dmc/mujoco_dmc_suite_align_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,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()
Expand All @@ -171,7 +172,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}")
Expand All @@ -180,19 +181,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(
Expand Down Expand Up @@ -231,13 +237,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:
Expand Down Expand Up @@ -270,7 +276,8 @@ def test_swimmer(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
)


Expand Down
6 changes: 5 additions & 1 deletion envpool/mujoco/gym/mujoco_gym_align_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
)
)
)
Expand Down
66 changes: 63 additions & 3 deletions envpool/workspace0.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,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 = "d1cb3a720546240d894cd315b7fd358a2b96013a1f59b6d718036eca6f6edac2",
sha256 = "e7fa0821c993073b19bd8034df63661e309edcdc2d602101c3f9b28201574ded",
strip_prefix = "mujoco-2.2.1",
urls = [
"https://github.com/deepmind/mujoco/releases/download/2.2.1/mujoco-2.2.1-linux-x86_64.tar.gz",
"https://ml.cs.tsinghua.edu.cn/~jiayi/envpool/deepmind/mujoco/mujoco-2.2.1-linux-x86_64.tar.gz",
"https://github.com/deepmind/mujoco/archive/refs/tags/2.2.1.tar.gz",
"https://ml.cs.tsinghua.edu.cn/~jiayi/envpool/deepmind/mujoco/2.2.1.tar.gz",
],
build_file = "//third_party/mujoco:mujoco.BUILD",
)
Expand Down
Empty file added third_party/ccd/BUILD
Empty file.
20 changes: 20 additions & 0 deletions third_party/ccd/ccd.BUILD
Original file line number Diff line number Diff line change
@@ -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"],
)
Empty file added third_party/lodepng/BUILD
Empty file.
7 changes: 7 additions & 0 deletions third_party/lodepng/lodepng.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "lodepng",
srcs = ["lodepng.cpp"],
hdrs = ["lodepng.h"],
)
31 changes: 23 additions & 8 deletions third_party/mujoco/mujoco.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,32 @@ package(default_visibility = ["//visibility:public"])

cc_library(
name = "mujoco_lib",
srcs = glob(["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 = [
"@ccd",
"@lodepng",
"@qhull",
"@tinyobjloader",
"@tinyxml2",
],
linkopts = ["-Wl,-rpath,'$$ORIGIN'"],
linkstatic = 0,
)

filegroup(
name = "mujoco_so",
srcs = ["lib/libmujoco.so.2.2.1"],
)
Empty file added third_party/qhull/BUILD
Empty file.
8 changes: 8 additions & 0 deletions third_party/qhull/qhull.BUILD
Original file line number Diff line number Diff line change
@@ -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"],
)
Empty file added third_party/tinyobjloader/BUILD
Empty file.
8 changes: 8 additions & 0 deletions third_party/tinyobjloader/tinyobjloader.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "tinyobjloader",
srcs = ["tiny_obj_loader.cc"],
hdrs = ["tiny_obj_loader.h"],
includes = ["."],
)
Empty file added third_party/tinyxml2/BUILD
Empty file.
7 changes: 7 additions & 0 deletions third_party/tinyxml2/tinyxml2.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "tinyxml2",
srcs = ["tinyxml2.cpp"],
hdrs = ["tinyxml2.h"],
)