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

Fix sequential loading with multiple environments #307

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
b4fc19d
Development dockerfile
rhaps0dy Jan 5, 2024
954d7fb
Dummy Sokoban environment
rhaps0dy Jan 5, 2024
09eff51
Fixed some of the tests
rhaps0dy Jan 5, 2024
58e20b5
Fixed more of the tests
rhaps0dy Jan 7, 2024
57cfac1
Don't build all the other environments
rhaps0dy Jan 8, 2024
4db8a61
Basic sokoban
rhaps0dy Jan 9, 2024
a9db23f
simpler dev docker with updated CUDA
rhaps0dy Jan 10, 2024
7eb159d
Implemented env
rhaps0dy Jan 10, 2024
621de30
Debugged env
rhaps0dy Jan 11, 2024
eccacf6
Format
rhaps0dy Jan 12, 2024
4a52fa5
Order bug in moving player
rhaps0dy Jan 15, 2024
3fb0c5c
Fix directions
rhaps0dy Jan 16, 2024
ac948ca
Rewards are doubles
rhaps0dy Jan 16, 2024
2dc167d
Reverse left/right
rhaps0dy Jan 16, 2024
0c4b1f2
Reverse again, debugging code.
rhaps0dy Jan 16, 2024
96c5636
Print action names
rhaps0dy Jan 16, 2024
c4e0638
Print arena thihngs
rhaps0dy Jan 16, 2024
57302ea
Typo in where in arena to look
rhaps0dy Jan 16, 2024
0a2f05b
Don't print actions anymore
rhaps0dy Jan 16, 2024
bd50d73
Working with bug
rhaps0dy Jan 20, 2024
a85d4fd
solve type error
rhaps0dy Jan 20, 2024
0853a48
Make sure env does indeed truncate at the correct number of steps
rhaps0dy Jan 20, 2024
af25a1f
Only give a reward if the number of boxes left is 0
rhaps0dy Jan 21, 2024
a0bba8e
Display the unmatched boxes info
rhaps0dy Jan 21, 2024
9de2c16
Add unmatched boxes to spec
rhaps0dy Jan 21, 2024
ae6a2d7
Print reward boxes
rhaps0dy Jan 21, 2024
9d3d388
Revert "Print reward boxes"
rhaps0dy Jan 21, 2024
448be93
Revert "Add unmatched boxes to spec"
rhaps0dy Jan 21, 2024
653dab6
Random episode length every time
rhaps0dy Feb 8, 2024
4a6e768
CircleCI now runs linters and tests (#2)
rhaps0dy Mar 7, 2024
89fff4c
Add option to load a fixed number of levels sequentially (#1)
taufeeque9 Mar 8, 2024
4a12f55
A* implementation for Sokoban (#4)
taufeeque9 Mar 9, 2024
4f2db77
only add files in the levels_dir (#6)
taufeeque9 Mar 18, 2024
e3e2e7e
Upgrade pytorch and cuda
rhaps0dy Mar 22, 2024
ed640fd
Clang-format changed
rhaps0dy Mar 23, 2024
9186551
Make fixed initializers the default ones
rhaps0dy Mar 23, 2024
66a8088
Upgrade pytorch and cuda (#7)
rhaps0dy Mar 25, 2024
7562370
Better heuristic function that improves runtime on difficult levels (#5)
taufeeque9 Mar 29, 2024
58eae4e
Don't truncate episodes that finish at the last step.
rhaps0dy Apr 15, 2024
f83f79b
The start of a test
rhaps0dy Apr 15, 2024
bc5ba8e
Fix variable name
rhaps0dy Apr 15, 2024
8ce206a
Test that environment terminates/truncates correctly
rhaps0dy Apr 15, 2024
42254d2
Make sure the tests pass in CI
rhaps0dy Apr 15, 2024
e4876f8
Prevent JVM from running out of memory
rhaps0dy Apr 15, 2024
1621daf
Load other levels first
rhaps0dy Apr 15, 2024
0e9785c
reduce action space to 4
taufeeque9 Apr 24, 2024
1d6e81b
Fix review
rhaps0dy Apr 25, 2024
d467459
Fix incorrect truncation
rhaps0dy Apr 25, 2024
534a086
Explicitly skip astar_log test
rhaps0dy Apr 25, 2024
497309d
Make environment truncate correctly (#8)
rhaps0dy Apr 25, 2024
b56251c
remove modulo on action
taufeeque9 Apr 25, 2024
0183b4b
reduce action space to 4 (#9)
taufeeque9 Apr 25, 2024
2c18ac4
remove test skipping
taufeeque9 Apr 25, 2024
d8ccb0b
fix action mapping error in test
taufeeque9 Apr 25, 2024
129f0ed
sort files while loading levels and fix test_astar_log
taufeeque9 Apr 25, 2024
a74ce4f
fix test and lint
taufeeque9 Apr 25, 2024
3c2cf13
fix lint
taufeeque9 Apr 25, 2024
9c6a5cc
fix lint
taufeeque9 Apr 25, 2024
9b32dd0
Fix astar_log test (#10)
rhaps0dy Apr 26, 2024
1abbeb8
fix delayed reset bug
taufeeque9 May 27, 2024
268c93d
update the reset function
taufeeque9 May 28, 2024
4098670
Explain why ResetWithoutWrite with comment
rhaps0dy May 28, 2024
6b1b577
Cap line to 80
rhaps0dy May 28, 2024
ce439db
Fix delayed resetting on solving a level or on truncation (#11)
taufeeque9 May 28, 2024
c25428b
add fix in level loader and test
taufeeque9 Jun 27, 2024
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
81 changes: 81 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
version: 2.1

parameters:
action:
type: enum
enum: [oncommit, docker]
default: oncommit

docker_img_version:
# Docker image version for running tests.
type: string
default: "8d8cf1a-envpool-ci"

workflows:
test-jobs:
when:
equal: [oncommit, << pipeline.parameters.action >>]
jobs:
- lint:
context:
- ghcr-auth
- tests:
context:
- ghcr-auth

jobs:
lint:
docker:
- image: ghcr.io/alignmentresearch/learned-planners:<< pipeline.parameters.docker_img_version >>
auth:
username: "$GHCR_DOCKER_USER"
password: "$GHCR_DOCKER_TOKEN"
resource_class: medium
working_directory: /app
steps:
- checkout
# Copied from .github/workflows/lint.yml
- run:
name: flake8
command: |
make flake8
- run:
name: isort and yapf
command: |
make py-format
- run:
name: cpplint
command: |
make cpplint
- run:
name: clang-format
command: |
make clang-format
- run:
name: clang-tidy
command: |
make clang-tidy
- run:
name: buildifier
command: |
make buildifier
- run:
name: addlicense
command: |
make addlicense
# Skip mypy, docstyle and spelling

tests:
docker:
- image: ghcr.io/alignmentresearch/learned-planners:<< pipeline.parameters.docker_img_version >>
auth:
username: "$GHCR_DOCKER_USER"
password: "$GHCR_DOCKER_TOKEN"
resource_class: large
working_directory: /app
steps:
- checkout
- run:
name: Run tests
command: |
BAZEL_OPT=--host_jvm_args=-Xmx3g make bazel-test
5 changes: 5 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# 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.

# Disable google-runtime-references, because passing by reference is less
# error-prone than passing by pointer. They actually removed it from their style
# guide (https://www.mail-archive.com/cfe-commits@lists.llvm.org/msg203119.html)
---
Checks: '
bugprone-*,
Expand All @@ -29,6 +33,7 @@ Checks: '
-readability-magic-numbers,
-readability-static-accessed-through-instance,
-readability-uppercase-literal-suffix,
-google-runtime-references,
'
CheckOptions:
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
Expand Down
4 changes: 4 additions & 0 deletions .dir-locals.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
;; Don't format Python in this directory with the Emacs formatter, it conflicts
;; with `make format`.
((python-mode . nil)
(js-json-mode . nil))
4 changes: 3 additions & 1 deletion CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
filter=-build/c++11,+build/c++17,-build/include_subdir
# Disable runtime-references, it's not in the Google style guide anymore
# and is less error prone. See .clang-tidy
filter=-build/c++11,+build/c++17,-build/include_subdir,-runtime/references
20 changes: 13 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ PYTHON_FILES = $(shell find . -type f -name "*.py")
CPP_FILES = $(shell find $(PROJECT_NAME) -type f -name "*.h" -o -name "*.cc")
BAZEL_FILES = $(shell find . -type f -name "*BUILD" -o -name "*.bzl")
COMMIT_HASH = $(shell git log -1 --format=%h)
COPYRIGHT = "Garena Online Private Limited"
COPYRIGHT = "FAR AI"
COPYRIGHT_YEAR = "2023-2024"
BAZELOPT =
DATE = $(shell date "+%Y-%m-%d")
DOCKER_TAG = $(DATE)-$(COMMIT_HASH)
Expand Down Expand Up @@ -74,11 +75,14 @@ mypy: mypy-install
# c++ linter

cpplint: cpplint-install
cpplint $(CPP_FILES)
cpplint --root . $(CPP_FILES)

clang-format: clang-format-install
clang-format --style=file -i $(CPP_FILES) -n --Werror

clang-format-fix: clang-format-install
clang-format --style=file -i $(CPP_FILES) --Werror

# bazel file linter

buildifier: buildifier-install
Expand All @@ -87,13 +91,15 @@ buildifier: buildifier-install
# bazel build/test

bazel-pip-requirement-dev:
cd third_party/pip_requirements && (cmp requirements.txt requirements-dev.txt || ln -sf requirements-dev.txt requirements.txt)
# Modified to only install dependencies relevant to testing Sokoban (which is the same as release)
cd third_party/pip_requirements && (cmp requirements.txt requirements-sokoban.txt || ln -sf requirements-sokoban.txt requirements.txt)

bazel-pip-requirement-release:
cd third_party/pip_requirements && (cmp requirements.txt requirements-release.txt || ln -sf requirements-release.txt requirements.txt)

clang-tidy: clang-tidy-install bazel-pip-requirement-dev
bazel build $(BAZELOPT) //... --config=clang-tidy --config=test
# Only lint the things we actually build
bazel build $(BAZELOPT) //envpool/core/... //envpool/sokoban/... --config=clang-tidy --config=test

bazel-debug: bazel-install bazel-pip-requirement-dev
bazel run $(BAZELOPT) //:setup --config=debug -- bdist_wheel
Expand All @@ -111,15 +117,15 @@ bazel-release: bazel-install bazel-pip-requirement-release
cp bazel-bin/setup.runfiles/$(PROJECT_NAME)/dist/*.whl ./dist

bazel-test: bazel-install bazel-pip-requirement-dev
bazel test --test_output=all $(BAZELOPT) //... --config=test --spawn_strategy=local --color=yes
bazel test --test_output=all $(BAZELOPT) //envpool/core/... //envpool/sokoban/... --config=test --spawn_strategy=local --color=yes

bazel-clean: bazel-install
bazel clean --expunge

# documentation

addlicense: addlicense-install
addlicense -c $(COPYRIGHT) -l apache -y 2023 -check $(PROJECT_FOLDER)
addlicense -c $(COPYRIGHT) -l apache -y "$(COPYRIGHT_YEAR)" -check $(PROJECT_FOLDER)

docstyle: doc-install
pydocstyle $(PROJECT_NAME) && doc8 docs && cd docs && make html SPHINXOPTS="-W"
Expand All @@ -144,7 +150,7 @@ format: py-format-install clang-format-install buildifier-install addlicense-ins
yapf -ir $(PYTHON_FILES)
clang-format -style=file -i $(CPP_FILES)
buildifier -r -lint=fix $(BAZEL_FILES)
addlicense -c $(COPYRIGHT) -l apache -y 2023 $(PROJECT_FOLDER)
addlicense -c $(COPYRIGHT) -l apache -y "$(COPYRIGHT_YEAR)" $(PROJECT_FOLDER)

# Build docker images

Expand Down
30 changes: 10 additions & 20 deletions docker/dev.dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
# Need docker >= 20.10.9, see https://stackoverflow.com/questions/71941032/why-i-cannot-run-apt-update-inside-a-fresh-ubuntu22-04
FROM nvidia/cuda:12.1.1-cudnn8-devel-ubuntu22.04

FROM nvidia/cuda:12.2.2-cudnn8-devel-ubuntu22.04

ARG DEBIAN_FRONTEND=noninteractive
ARG HOME=/root
ARG PATH=$PATH:$HOME/go/bin

ENV DEBIAN_FRONTEND=noninteractive
ENV PATH=$PATH:$HOME/go/bin

RUN apt-get update \
&& apt-get install -y python3-pip python3-dev golang-1.18 git wget curl zsh tmux vim \
&& apt-get install -y python3-pip python3-dev golang-1.18 git wget curl tmux vim ssh \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN ln -s /usr/bin/python3 /usr/bin/python
RUN ln -sf /usr/lib/go-1.18/bin/go /usr/bin/go
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
WORKDIR $HOME
RUN git clone https://github.com/gpakosz/.tmux.git
RUN ln -s -f .tmux/.tmux.conf
RUN cp .tmux/.tmux.conf.local .
RUN echo "set-option -g default-shell /bin/zsh" >> .tmux.conf.local
RUN echo "set-option -g history-limit 10000" >> .tmux.conf.local
RUN echo "export PATH=$PATH:$HOME/go/bin" >> .zshrc

# Install Bazel
RUN go install github.com/bazelbuild/bazelisk@latest && ln -sf $HOME/go/bin/bazelisk $HOME/go/bin/bazel
RUN go install github.com/bazelbuild/buildtools/buildifier@latest
RUN $HOME/go/bin/bazel version

RUN useradd -ms /bin/zsh github-action

RUN apt-get update \
&& apt-get install -y clang-format clang-tidy swig qtdeclarative5-dev \
&& rm -rf /var/lib/apt/lists/*
ARG USE_BAZEL_VERSION=6.4.0
RUN $HOME/go/bin/bazel version

WORKDIR /app
COPY . .
19 changes: 2 additions & 17 deletions envpool/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ py_library(
name = "entry",
srcs = ["entry.py"],
deps = [
"//envpool/atari:atari_registration",
"//envpool/box2d:box2d_registration",
"//envpool/classic_control:classic_control_registration",
"//envpool/mujoco:mujoco_dmc_registration",
"//envpool/mujoco:mujoco_gym_registration",
"//envpool/procgen:procgen_registration",
"//envpool/toy_text:toy_text_registration",
"//envpool/vizdoom:vizdoom_registration",
"//envpool/sokoban:registration",
],
)

Expand All @@ -47,15 +40,7 @@ py_library(
deps = [
":entry",
":registration",
"//envpool/atari",
"//envpool/box2d",
"//envpool/classic_control",
"//envpool/mujoco:mujoco_dmc",
"//envpool/mujoco:mujoco_gym",
"//envpool/procgen",
"//envpool/python",
"//envpool/toy_text",
"//envpool/vizdoom",
"//envpool/sokoban",
],
)

Expand Down
2 changes: 2 additions & 0 deletions envpool/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@
import envpool.vizdoom.registration # noqa: F401
except ImportError:
pass

import envpool.sokoban.registration # noqa: F401
109 changes: 109 additions & 0 deletions envpool/sokoban/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Copyright 2023-2024 FAR AI
#
# 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.

load("@pip_requirements//:requirements.bzl", "requirement")
load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")

package(default_visibility = ["//visibility:public"])

py_library(
name = "sokoban",
srcs = ["__init__.py"],
data = [":sokoban_envpool.so"],
deps = ["//envpool/python:api"],
)

py_library(
name = "registration",
srcs = ["registration.py"],
deps = [
"//envpool:registration",
],
)

cc_library(
name = "sokoban_envpool_h",
hdrs = [
"level_loader.h",
"sokoban_envpool.h",
"utils.h",
],
deps = [
"//envpool/core:async_envpool",
"//envpool/core:env",
"//envpool/core:env_spec",
],
)

cc_library(
name = "sokoban_node_h",
hdrs = [
"level_loader.h",
"sokoban_node.h",
"utils.h",
],
deps = ["//third_party/astar_stl:astar_stl_h"],
)

cc_binary(
name = "astar_log",
srcs = [
"astar_log.cc",
"level_loader.cc",
"sokoban_node.cc",
],
deps = [
":sokoban_node_h",
],
)

cc_binary(
name = "astar_log_level",
srcs = [
"astar_log_level.cc",
"level_loader.cc",
"sokoban_node.cc",
],
deps = [
":sokoban_node_h",
],
)

py_test(
name = "test",
srcs = ["sokoban_py_envpool_test.py"],
main = "sokoban_py_envpool_test.py",
deps = [
":registration",
":sokoban",
"//envpool",
requirement("numpy"),
requirement("pytest"),
],
)

pybind_extension(
name = "sokoban_envpool",
srcs = [
"level_loader.cc",
"sokoban_envpool.cc",
],
linkopts = [
"-ldl",
],
deps = [
":sokoban_envpool_h",
"//envpool/core:py_envpool",
],
)
Loading
Loading