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

feat: adding sokoban environment #185

Merged
merged 95 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
9876dda
ci: increment version
clement-bonnet Jun 9, 2023
5b79043
Merge branch 'main' of github.com:instadeepai/jumanji into main
clement-bonnet Jun 12, 2023
e00cdb4
Merge branch 'main' of github.com:instadeepai/jumanji into main
clement-bonnet Jun 16, 2023
3096f6c
Merge branch 'main' of github.com:instadeepai/jumanji into main
clement-bonnet Jun 19, 2023
764390a
feat: adding boxoban environment
mvmacfarlane Jul 17, 2023
53a868e
fix: remove unuessesary imgs folder
mvmacfarlane Jul 17, 2023
6d8cc1b
feat: update boxoban md
mvmacfarlane Jul 17, 2023
cdf3edc
feat: update boxoban md
mvmacfarlane Jul 17, 2023
67fa4b3
feat: add environments/api md
mvmacfarlane Jul 17, 2023
48d499d
feat: add boxoban random and a2c agents
mvmacfarlane Jul 17, 2023
c2cdb50
feat: add solved feature in extras
mvmacfarlane Jul 17, 2023
946d56f
fix: pre commit formatting
mvmacfarlane Jul 17, 2023
0bc467f
refactor: remove unessesary code
mvmacfarlane Jul 17, 2023
dcdf7a4
refactor: remove unessessary comments
mvmacfarlane Jul 17, 2023
8c76551
refactor: edit boxoban run doc strings
mvmacfarlane Jul 17, 2023
9d08ec8
refactor: edit boxoban other doc strings
mvmacfarlane Jul 17, 2023
b9f5aec
feat: update boxoban markdown
mvmacfarlane Jul 17, 2023
7ec28ff
feat: update boxoban markdown
mvmacfarlane Jul 17, 2023
68f428d
feat: update boxoban markdown
mvmacfarlane Jul 17, 2023
0d8ce06
fix: update md and doc strings
mvmacfarlane Jul 17, 2023
c048610
fix: fix wrong observation grid spec max value
mvmacfarlane Jul 17, 2023
9a76978
feat: add boxoban to mkdocs
mvmacfarlane Jul 17, 2023
fd0fbe2
style: change boxoban imgs location
mvmacfarlane Jul 17, 2023
ac39454
struct: switch naming to Sokoban
mvmacfarlane Jul 17, 2023
370f73f
struct: switch naming to Sokoban
mvmacfarlane Jul 17, 2023
9765ef4
style: fix formatting
mvmacfarlane Jul 17, 2023
4e266a6
fix: types requirements for dev
clement-bonnet Jul 17, 2023
b952267
feat: load hugging face dataset for sokoban generator
clement-bonnet Jul 17, 2023
747e730
fix: sokoban registration
clement-bonnet Jul 17, 2023
8f64820
feat: a2c sokoban configs
clement-bonnet Jul 18, 2023
70d7d5e
fix: class docstrings
clement-bonnet Jul 18, 2023
0b5dc3f
fix: make generators return state
mvmacfarlane Jul 18, 2023
1ac7b03
feat: add generator tests
mvmacfarlane Jul 18, 2023
ab99775
style: add reward_fn
mvmacfarlane Jul 18, 2023
36c602a
docs: update env docstring
mvmacfarlane Jul 18, 2023
c9ae908
docs: update md with sokoban level counts
mvmacfarlane Jul 18, 2023
64a2379
feat: at deepmind generator tests
mvmacfarlane Jul 18, 2023
fcfb143
style: fix style issues
mvmacfarlane Jul 18, 2023
1f24046
style: fix style issues
mvmacfarlane Jul 18, 2023
44088a8
style: fix style issues
mvmacfarlane Jul 18, 2023
48fe838
style: fix style issues
mvmacfarlane Jul 18, 2023
f7899ee
fix: remove inefficient calculation of agent location
mvmacfarlane Jul 21, 2023
ec27661
Merge branch 'main' into boxoban
clement-bonnet Aug 15, 2023
05d178b
Merge branch 'main' into boxoban
clement-bonnet Aug 19, 2023
70e7e64
fix: black
clement-bonnet Aug 20, 2023
d2bbdbd
Merge branch 'main' of https://github.com/clement-bonnet/jumanji into…
clement-bonnet Aug 20, 2023
d50516d
Merge branch 'main' of github.com:instadeepai/jumanji into boxoban
clement-bonnet Aug 20, 2023
5fd6946
test: remove deepmind gen tests requiring cached dataset
mvmacfarlane Aug 29, 2023
d0fe72b
fix: remove unessesary imports
mvmacfarlane Aug 29, 2023
7280e0c
fix: pre-commit style
mvmacfarlane Aug 29, 2023
557913a
Merge branch 'main' into boxoban
mvmacfarlane Aug 29, 2023
fe8ad1d
feat: save boxoban dataset in .cache
mvmacfarlane Aug 29, 2023
54827c9
refactor: remove commented code
mvmacfarlane Aug 29, 2023
2913197
fix: terminal logic
mvmacfarlane Sep 12, 2023
4ee995f
Merge branch 'instadeepai:main' into boxoban
mvmacfarlane Jan 2, 2024
19f074c
fix: linters
mvmacfarlane Jan 2, 2024
6e4dc3c
Update jumanji/environments/routing/sokoban/env.py
mvmacfarlane Jan 2, 2024
2be45ff
Update jumanji/training/configs/config.yaml
mvmacfarlane Jan 2, 2024
7890040
Update jumanji/training/configs/config.yaml
mvmacfarlane Jan 2, 2024
70709a1
Update jumanji/training/configs/config.yaml
mvmacfarlane Jan 2, 2024
e21783b
feat: simple architecture
mvmacfarlane Jan 2, 2024
9377808
Merge branch 'main' into boxoban
sash-a Jan 10, 2024
1fcbe72
remove comment
mvmacfarlane Jan 22, 2024
263c19e
Merge branch 'boxoban' of https://github.com/mvmacfarlane/jumanji int…
mvmacfarlane Jan 22, 2024
9ecc1e9
remove empty comments
mvmacfarlane Jan 22, 2024
02c98f6
remove comment
mvmacfarlane Jan 22, 2024
3b12047
add nnop constant
mvmacfarlane Jan 22, 2024
f51b4fa
fix: switch action order to confirm with standard
mvmacfarlane Jan 22, 2024
2f33dce
feat: update hugging face pr
mvmacfarlane Jan 22, 2024
3308229
fix: sokoban level num
mvmacfarlane Jan 22, 2024
3d9c44a
remove boxoban name from readme
mvmacfarlane Jan 22, 2024
2ce5db6
fix: remove boxoban references
mvmacfarlane Jan 22, 2024
a032ae2
fix: tests
mvmacfarlane Jan 23, 2024
00e3068
fix: tests
mvmacfarlane Jan 23, 2024
2019921
feat: set default parameters sokoban
mvmacfarlane Jan 23, 2024
b6757e6
fix: remove pr revision
mvmacfarlane Jan 23, 2024
4cf4218
fix: constants
mvmacfarlane Jan 23, 2024
b220b06
fix: code formatting
mvmacfarlane Jan 23, 2024
8b3ce2a
Merge branch 'main' into boxoban
clement-bonnet Jan 24, 2024
69738e3
Update jumanji/environments/routing/sokoban/env.py
mvmacfarlane Feb 3, 2024
759c4b9
Update jumanji/environments/routing/sokoban/env.py
mvmacfarlane Feb 3, 2024
5cf704d
Update jumanji/environments/routing/sokoban/generator.py
mvmacfarlane Feb 3, 2024
66fc4ca
Update jumanji/environments/routing/sokoban/generator.py
mvmacfarlane Feb 3, 2024
81c2194
Update jumanji/environments/routing/sokoban/generator.py
mvmacfarlane Feb 3, 2024
61f1c59
Update jumanji/training/configs/config.yaml
mvmacfarlane Feb 3, 2024
746cc0b
Update jumanji/training/setup_train.py
mvmacfarlane Feb 3, 2024
a15a43b
Update jumanji/environments/routing/sokoban/env.py
mvmacfarlane Feb 3, 2024
1f50051
Update jumanji/environments/routing/sokoban/env.py
mvmacfarlane Feb 3, 2024
73734e2
fix: comment overload
mvmacfarlane Feb 3, 2024
a494ca7
fix: add NOOP usage
mvmacfarlane Feb 3, 2024
153c5ee
fix: clashes with main
mvmacfarlane Feb 3, 2024
23b99cc
fix: gif
mvmacfarlane Feb 3, 2024
5240a59
fix: readme sokoban link
mvmacfarlane Feb 3, 2024
3326ada
fix: readme sokoban link
mvmacfarlane Feb 3, 2024
ff164aa
fix: linters
mvmacfarlane Feb 6, 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
Prev Previous commit
Next Next commit
feat: load hugging face dataset for sokoban generator
  • Loading branch information
clement-bonnet committed Jul 17, 2023
commit b95226730fa062fcd053e8a78cf9471baddc7e0e
10 changes: 6 additions & 4 deletions jumanji/environments/routing/sokoban/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
TARGET_BOX,
WALL,
)
from jumanji.environments.routing.sokoban.generator import DeepMindGenerator, Generator
from jumanji.environments.routing.sokoban.generator import (
Generator,
HuggingFaceDeepMindGenerator,
)
from jumanji.environments.routing.sokoban.types import Observation, State
from jumanji.environments.routing.sokoban.viewer import BoxViewer
from jumanji.types import TimeStep, restart, termination, transition
Expand Down Expand Up @@ -112,9 +115,8 @@ def __init__(
self.num_cols = GRID_SIZE
self.shape = (self.num_rows, self.num_cols)
self.time_limit = time_limit
self.generator = generator or DeepMindGenerator(
difficulty="unfiltered",
split="train",
self.generator = generator or HuggingFaceDeepMindGenerator(
"unfiltered-train",
proportion_of_files=0.01,
)
self._viewer = viewer or BoxViewer(
Expand Down
69 changes: 69 additions & 0 deletions jumanji/environments/routing/sokoban/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import chex
import jax
import jax.numpy as jnp
import numpy as np
import requests
from huggingface_hub import hf_hub_download
from tqdm import tqdm


Expand Down Expand Up @@ -179,6 +181,72 @@ def _download_data(self) -> None:
zip_ref.extractall(self.cache_path)


class HuggingFaceDeepMindGenerator(Generator):
"""Instance generator that generates a random problem from the DeepMind
Boxoban dataset a popular dataset for comparing Reinforcement Learning
algorithms and Planning Algorithms. The dataset has unfiltered, medium and
hard versions. The unfiltered dataset contain train, test and valid
splits. The Medium has train and valid splits available. And the hard set
contains just a small number of problems. The problems are all guaranteed
to be solvable.
"""

def __init__(
self,
dataset_name: str,
proportion_of_files: float = 1.0,
) -> None:
"""Instantiates a `DeepMindGenerator`.

Args:
dataset_name: the name of the dataset to use. Choices are:
- unfiltered-train,
- unfiltered-valid,
- unfiltered-test,
- medium-train,
- medium-test,
- hard.
proportion_of_files: float between (0,1) for the proportion of
files to use in the dataset .
"""

self.dataset_name = dataset_name
self.proportion_of_files = proportion_of_files

dataset_file = hf_hub_download(
repo_id="InstaDeepAI/boxoban-levels", filename=f"{dataset_name}.npy"
)
with open(dataset_file, "rb") as f:
dataset = np.load(f)

# Convert to jax arrays and resize using proportion_of_files
length = int(proportion_of_files * dataset.shape[0])
self._fixed_grids = jnp.asarray(dataset[:length, ..., 0], jnp.uint8)
self._variable_grids = jnp.asarray(dataset[:length, ..., 1], jnp.uint8)

def __call__(self, rng_key: chex.PRNGKey) -> Tuple[chex.Array, chex.Array]:
"""Generate a random Boxoban problem from the Deepmind dataset.

Args:
rng_key: the Jax random number generation key.

Returns:
fixed_grid: Array (uint8) shape (num_rows, num_cols) the fixed
components of the problem.
variable_grid: Array (uint8) shape (num_rows, num_cols) the
variable components of the problem.
"""

key, idx_key = jax.random.split(rng_key)
idx = jax.random.randint(
idx_key, shape=(), minval=0, maxval=self._fixed_grids.shape[0]
)
fixed_grid = self._fixed_grids.take(idx, axis=0)
variable_grid = self._variable_grids.take(idx, axis=0)

return fixed_grid, variable_grid


class ToyGenerator(Generator):
def __call__(
self,
Expand Down Expand Up @@ -254,6 +322,7 @@ def __call__(
variable_grid: Array (uint8) shape (num_rows, num_cols) the
variable components of the problem.
"""
del rng_key

level1 = [
"##########",
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ module = [
"haiku.*",
"hydra.*",
"omegaconf.*",
"huggingface_hub.*",
]
ignore_missing_imports = true