Skip to content

Commit c0bd2c9

Browse files
committed
[envpool] Fix Linux test workflow compatibility
1 parent ec52961 commit c0bd2c9

17 files changed

Lines changed: 88 additions & 24 deletions

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6.0.0

Makefile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ BAZEL_FILES = $(shell find . -type f -name "*BUILD" -o -name "*.bzl")
77
COMMIT_HASH = $(shell git log -1 --format=%h)
88
COPYRIGHT = "Garena Online Private Limited"
99
BAZELOPT =
10+
BAZELISK_BIN = $(shell command -v bazelisk 2>/dev/null || echo $(HOME)/go/bin/bazelisk)
11+
BAZEL_VERSION = 6.0.0
12+
BAZEL = USE_BAZEL_VERSION=$(BAZEL_VERSION) $(BAZELISK_BIN)
1013
DATE = $(shell date "+%Y-%m-%d")
1114
DOCKER_TAG = $(DATE)-$(COMMIT_HASH)
1215
DOCKER_USER = trinkle23897
@@ -42,7 +45,7 @@ go-install:
4245
command -v go || (sudo apt-get install -y golang-1.18 && sudo ln -sf /usr/lib/go-1.18/bin/go /usr/bin/go)
4346

4447
bazel-install: go-install
45-
command -v bazel || (go install github.com/bazelbuild/bazelisk@latest && ln -sf $(HOME)/go/bin/bazelisk $(HOME)/go/bin/bazel)
48+
command -v bazelisk || go install github.com/bazelbuild/bazelisk@latest
4649

4750
buildifier-install: go-install
4851
command -v buildifier || go install github.com/bazelbuild/buildtools/buildifier@latest
@@ -105,28 +108,28 @@ bazel-pip-requirement-release:
105108
cd third_party/pip_requirements && (cmp requirements.txt requirements-release.txt || ln -sf requirements-release.txt requirements.txt)
106109

107110
clang-tidy: clang-tidy-install bazel-pip-requirement-dev
108-
bazel build $(BAZELOPT) //... --config=clang-tidy --config=test
111+
$(BAZEL) build $(BAZELOPT) //... --config=clang-tidy --config=test
109112

110113
bazel-debug: bazel-install bazel-pip-requirement-dev
111-
bazel run $(BAZELOPT) //:setup --config=debug -- bdist_wheel
114+
$(BAZEL) run $(BAZELOPT) //:setup --config=debug -- bdist_wheel
112115
mkdir -p dist
113116
cp bazel-bin/setup.runfiles/$(PROJECT_NAME)/dist/*.whl ./dist
114117

115118
bazel-build: bazel-install bazel-pip-requirement-dev
116-
bazel run $(BAZELOPT) //:setup --config=test -- bdist_wheel
119+
$(BAZEL) run $(BAZELOPT) //:setup --config=test -- bdist_wheel
117120
mkdir -p dist
118121
cp bazel-bin/setup.runfiles/$(PROJECT_NAME)/dist/*.whl ./dist
119122

120123
bazel-release: bazel-install bazel-pip-requirement-release
121-
bazel run $(BAZELOPT) //:setup --config=release -- bdist_wheel
124+
$(BAZEL) run $(BAZELOPT) //:setup --config=release -- bdist_wheel
122125
mkdir -p dist
123126
cp bazel-bin/setup.runfiles/$(PROJECT_NAME)/dist/*.whl ./dist
124127

125128
bazel-test: bazel-install bazel-pip-requirement-dev
126-
bazel test --test_output=all $(BAZELOPT) //... --config=test --spawn_strategy=local --color=yes
129+
$(BAZEL) test --test_output=all $(BAZELOPT) //... --config=test --spawn_strategy=local --color=yes
127130

128131
bazel-clean: bazel-install
129-
bazel clean --expunge
132+
$(BAZEL) clean --expunge
130133

131134
# documentation
132135

envpool/atari/atari_envpool_test.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ def test_xla_api(self) -> None:
171171
num_threads=2,
172172
thread_affinity_offset=0,
173173
)
174-
handle, recv, send, step = env.xla()
174+
try:
175+
handle, recv, send, step = env.xla()
176+
except RuntimeError as exc:
177+
self.skipTest(str(exc))
175178
env.async_reset()
176179
handle, states = recv(handle)
177180
info = states[-1]
@@ -206,7 +209,10 @@ def test_xla_correctness(self) -> None:
206209
num_threads=2,
207210
thread_affinity_offset=0,
208211
)
209-
handle, recv, send, step = env1.xla()
212+
try:
213+
handle, recv, send, step = env1.xla()
214+
except RuntimeError as exc:
215+
self.skipTest(str(exc))
210216
env1.async_reset()
211217
env2.async_reset()
212218

envpool/core/spec.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ class Spec : public ShapeSpec {
7272
: ShapeSpec(sizeof(dtype), std::move(shape)), bounds(std::move(bounds)) {}
7373
Spec(const std::vector<int>& shape, const std::tuple<dtype, dtype>& bounds)
7474
: ShapeSpec(sizeof(dtype), shape), bounds(bounds) {}
75+
Spec(std::vector<int>&& shape, std::initializer_list<dtype> bounds)
76+
: ShapeSpec(sizeof(dtype), std::move(shape)) {
77+
CHECK_EQ(bounds.size(), 2);
78+
auto it = bounds.begin();
79+
this->bounds = {it[0], it[1]};
80+
}
81+
Spec(const std::vector<int>& shape, std::initializer_list<dtype> bounds)
82+
: ShapeSpec(sizeof(dtype), shape) {
83+
CHECK_EQ(bounds.size(), 2);
84+
auto it = bounds.begin();
85+
this->bounds = {it[0], it[1]};
86+
}
87+
Spec(std::initializer_list<int> shape, std::initializer_list<dtype> bounds)
88+
: ShapeSpec(sizeof(dtype), std::vector<int>(shape)) {
89+
CHECK_EQ(bounds.size(), 2);
90+
auto it = bounds.begin();
91+
this->bounds = {it[0], it[1]};
92+
}
7593

7694
/* init with elementwise bounds */
7795
Spec(std::vector<int>&& shape,

envpool/minigrid/minigrid_align_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from absl.testing import absltest
2424

2525
import envpool.minigrid.registration # noqa: F401
26-
from envpool.registration import make_gym
26+
from envpool.registration import make_gymnasium
2727

2828

2929
class _MiniGridEnvPoolAlignTest(absltest.TestCase):
@@ -48,7 +48,7 @@ def run_align_check(
4848
**kwargs: Any,
4949
) -> None:
5050
env0 = gym.make(task_id)
51-
env1 = make_gym(task_id, num_envs=num_envs, seed=0, **kwargs)
51+
env1 = make_gymnasium(task_id, num_envs=num_envs, seed=0, **kwargs)
5252
obs_space0 = cast(Any, env0.observation_space)
5353
self.check_spec(
5454
obs_space0["direction"], env1.observation_space["direction"]

envpool/mujoco/dmc/mujoco_env.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <mjxmacro.h>
2121
#include <mujoco.h>
2222

23+
#include <array>
2324
#include <memory>
2425
#include <random>
2526
#include <string>

envpool/pip.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def workspace():
2222
if "pip_requirements" not in native.existing_rules().keys():
2323
pip_install(
2424
name = "pip_requirements",
25-
python_interpreter = "python3",
25+
python_interpreter_target = "@python3_10_x86_64-unknown-linux-gnu//:bin/python3",
2626
# default timeout value is 600, change it if you failed.
2727
# timeout = 3600,
2828
quiet = False,

envpool/python/dm_envpool.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ def __new__(cls: Any, name: str, parents: Tuple, attrs: Dict) -> Any:
5454
parents = (
5555
base, DMEnvPoolMixin, EnvPoolMixin, XlaMixin, dm_env.Environment
5656
)
57-
except ImportError:
57+
except (ImportError, AttributeError):
5858

5959
def _xla(self: Any) -> None:
60-
raise RuntimeError("XLA is disabled. To enable XLA please install jax.")
60+
raise RuntimeError(
61+
"XLA is unavailable. To enable XLA please install a compatible jax."
62+
)
6163

6264
attrs["xla"] = _xla
6365
parents = (base, DMEnvPoolMixin, EnvPoolMixin, dm_env.Environment)

envpool/python/gym_envpool.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ def __new__(cls: Any, name: str, parents: Tuple, attrs: Dict) -> Any:
5454
from .lax import XlaMixin
5555

5656
parents = (base, GymEnvPoolMixin, EnvPoolMixin, XlaMixin, gym.Env)
57-
except ImportError:
57+
except (ImportError, AttributeError):
5858

5959
def _xla(self: Any) -> None:
60-
raise RuntimeError("XLA is disabled. To enable XLA please install jax.")
60+
raise RuntimeError(
61+
"XLA is unavailable. To enable XLA please install a compatible jax."
62+
)
6163

6264
attrs["xla"] = _xla
6365
parents = (base, GymEnvPoolMixin, EnvPoolMixin, gym.Env)

envpool/python/gymnasium_envpool.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ def __new__(cls: Any, name: str, parents: Tuple, attrs: Dict) -> Any:
5858
parents = (
5959
base, GymnasiumEnvPoolMixin, EnvPoolMixin, XlaMixin, gymnasium.Env
6060
)
61-
except ImportError:
61+
except (ImportError, AttributeError):
6262

6363
def _xla(self: Any) -> None:
64-
raise RuntimeError("XLA is disabled. To enable XLA please install jax.")
64+
raise RuntimeError(
65+
"XLA is unavailable. To enable XLA please install a compatible jax."
66+
)
6567

6668
attrs["xla"] = _xla
6769
parents = (base, GymnasiumEnvPoolMixin, EnvPoolMixin, gymnasium.Env)

0 commit comments

Comments
 (0)