-
Notifications
You must be signed in to change notification settings - Fork 94
feat: adding sokoban environment #185
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
Merged
Merged
Changes from all commits
Commits
Show all changes
95 commits
Select commit
Hold shift + click to select a range
9876dda
ci: increment version
clement-bonnet 5b79043
Merge branch 'main' of github.com:instadeepai/jumanji into main
clement-bonnet e00cdb4
Merge branch 'main' of github.com:instadeepai/jumanji into main
clement-bonnet 3096f6c
Merge branch 'main' of github.com:instadeepai/jumanji into main
clement-bonnet 764390a
feat: adding boxoban environment
mvmacfarlane 53a868e
fix: remove unuessesary imgs folder
mvmacfarlane 6d8cc1b
feat: update boxoban md
mvmacfarlane cdf3edc
feat: update boxoban md
mvmacfarlane 67fa4b3
feat: add environments/api md
mvmacfarlane 48d499d
feat: add boxoban random and a2c agents
mvmacfarlane c2cdb50
feat: add solved feature in extras
mvmacfarlane 946d56f
fix: pre commit formatting
mvmacfarlane 0bc467f
refactor: remove unessesary code
mvmacfarlane dcdf7a4
refactor: remove unessessary comments
mvmacfarlane 8c76551
refactor: edit boxoban run doc strings
mvmacfarlane 9d08ec8
refactor: edit boxoban other doc strings
mvmacfarlane b9f5aec
feat: update boxoban markdown
mvmacfarlane 7ec28ff
feat: update boxoban markdown
mvmacfarlane 68f428d
feat: update boxoban markdown
mvmacfarlane 0d8ce06
fix: update md and doc strings
mvmacfarlane c048610
fix: fix wrong observation grid spec max value
mvmacfarlane 9a76978
feat: add boxoban to mkdocs
mvmacfarlane fd0fbe2
style: change boxoban imgs location
mvmacfarlane ac39454
struct: switch naming to Sokoban
mvmacfarlane 370f73f
struct: switch naming to Sokoban
mvmacfarlane 9765ef4
style: fix formatting
mvmacfarlane 4e266a6
fix: types requirements for dev
clement-bonnet b952267
feat: load hugging face dataset for sokoban generator
clement-bonnet 747e730
fix: sokoban registration
clement-bonnet 8f64820
feat: a2c sokoban configs
clement-bonnet 70d7d5e
fix: class docstrings
clement-bonnet 0b5dc3f
fix: make generators return state
mvmacfarlane 1ac7b03
feat: add generator tests
mvmacfarlane ab99775
style: add reward_fn
mvmacfarlane 36c602a
docs: update env docstring
mvmacfarlane c9ae908
docs: update md with sokoban level counts
mvmacfarlane 64a2379
feat: at deepmind generator tests
mvmacfarlane fcfb143
style: fix style issues
mvmacfarlane 1f24046
style: fix style issues
mvmacfarlane 44088a8
style: fix style issues
mvmacfarlane 48fe838
style: fix style issues
mvmacfarlane f7899ee
fix: remove inefficient calculation of agent location
mvmacfarlane ec27661
Merge branch 'main' into boxoban
clement-bonnet 05d178b
Merge branch 'main' into boxoban
clement-bonnet 70e7e64
fix: black
clement-bonnet d2bbdbd
Merge branch 'main' of https://github.com/clement-bonnet/jumanji into…
clement-bonnet d50516d
Merge branch 'main' of github.com:instadeepai/jumanji into boxoban
clement-bonnet 5fd6946
test: remove deepmind gen tests requiring cached dataset
mvmacfarlane d0fe72b
fix: remove unessesary imports
mvmacfarlane 7280e0c
fix: pre-commit style
mvmacfarlane 557913a
Merge branch 'main' into boxoban
mvmacfarlane fe8ad1d
feat: save boxoban dataset in .cache
mvmacfarlane 54827c9
refactor: remove commented code
mvmacfarlane 2913197
fix: terminal logic
mvmacfarlane 4ee995f
Merge branch 'instadeepai:main' into boxoban
mvmacfarlane 19f074c
fix: linters
mvmacfarlane 6e4dc3c
Update jumanji/environments/routing/sokoban/env.py
mvmacfarlane 2be45ff
Update jumanji/training/configs/config.yaml
mvmacfarlane 7890040
Update jumanji/training/configs/config.yaml
mvmacfarlane 70709a1
Update jumanji/training/configs/config.yaml
mvmacfarlane e21783b
feat: simple architecture
mvmacfarlane 9377808
Merge branch 'main' into boxoban
sash-a 1fcbe72
remove comment
mvmacfarlane 263c19e
Merge branch 'boxoban' of https://github.com/mvmacfarlane/jumanji int…
mvmacfarlane 9ecc1e9
remove empty comments
mvmacfarlane 02c98f6
remove comment
mvmacfarlane 3b12047
add nnop constant
mvmacfarlane f51b4fa
fix: switch action order to confirm with standard
mvmacfarlane 2f33dce
feat: update hugging face pr
mvmacfarlane 3308229
fix: sokoban level num
mvmacfarlane 3d9c44a
remove boxoban name from readme
mvmacfarlane 2ce5db6
fix: remove boxoban references
mvmacfarlane a032ae2
fix: tests
mvmacfarlane 00e3068
fix: tests
mvmacfarlane 2019921
feat: set default parameters sokoban
mvmacfarlane b6757e6
fix: remove pr revision
mvmacfarlane 4cf4218
fix: constants
mvmacfarlane b220b06
fix: code formatting
mvmacfarlane 8b3ce2a
Merge branch 'main' into boxoban
clement-bonnet 69738e3
Update jumanji/environments/routing/sokoban/env.py
mvmacfarlane 759c4b9
Update jumanji/environments/routing/sokoban/env.py
mvmacfarlane 5cf704d
Update jumanji/environments/routing/sokoban/generator.py
mvmacfarlane 66fc4ca
Update jumanji/environments/routing/sokoban/generator.py
mvmacfarlane 81c2194
Update jumanji/environments/routing/sokoban/generator.py
mvmacfarlane 61f1c59
Update jumanji/training/configs/config.yaml
mvmacfarlane 746cc0b
Update jumanji/training/setup_train.py
mvmacfarlane a15a43b
Update jumanji/environments/routing/sokoban/env.py
mvmacfarlane 1f50051
Update jumanji/environments/routing/sokoban/env.py
mvmacfarlane 73734e2
fix: comment overload
mvmacfarlane a494ca7
fix: add NOOP usage
mvmacfarlane 153c5ee
fix: clashes with main
mvmacfarlane 23b99cc
fix: gif
mvmacfarlane 5240a59
fix: readme sokoban link
mvmacfarlane 3326ada
fix: readme sokoban link
mvmacfarlane ff164aa
fix: linters
mvmacfarlane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,3 +154,4 @@ cython_debug/ | |
| jumanji_env/ | ||
| **/outputs/ | ||
| *.xml | ||
| .sokoban_cache/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| ::: jumanji.environments.routing.sokoban.env.Sokoban | ||
| selection: | ||
| members: | ||
| - __init__ | ||
| - observation_spec | ||
| - action_spec | ||
| - reset | ||
| - step | ||
| - render |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # Sokoban Environment 👾 | ||
|
|
||
| <p align="center"> | ||
| <img src="../env_anim/sokoban.gif" width="500"/> | ||
| </p> | ||
|
|
||
| This is a Jax implementation of the _Sokoban_ puzzle, a dynamic box-pushing environment where the agent's goal is to place all boxes on their targets. This version follows the rules from the DeepMind paper on [Imagination Augmented Agents](https://arxiv.org/abs/1707.06203), with levels based on the Boxoban dataset from [Guez et al., 2018](https://github.com/deepmind/boxoban-levels)[[1]](#ref1). The graphical assets were taken from [gym-sokoban](https://github.com/mpSchrader/gym-sokoban) by Schrader, a diverse Sokoban library implementing many versions of the game in the OpenAI gym framework [[2]](#ref2). | ||
|
|
||
| ## Observation | ||
|
|
||
| - `grid`: An Array (uint8) of shape `(10, 10, 2)`. It represents the variable grid (containing movable objects: boxes and the agent) and the fixed grid (containing fixed objects: walls and targets). | ||
| - `step_count`: An Array (int32) of shape `()`, representing the current number of steps in the episode. | ||
|
|
||
| ## Object Encodings | ||
|
|
||
| | Object | Encoding | | ||
| |--------------|----------| | ||
| | Empty Space | 0 | | ||
| | Wall | 1 | | ||
| | Target | 2 | | ||
| | Agent | 3 | | ||
| | Box | 4 | | ||
|
|
||
| ## Actions | ||
|
|
||
| The agent's action space is an Array (int32) with potential values of `[0,1,2,3]` (corresponding to `[Up, Down, Left, Right]`). If the agent attempts to move into a wall, off the grid, or push a box into a wall or off the grid, the grid state remains unchanged; however, the step count is incremented by one. Chained box pushes are not allowed and will result in no action. | ||
mvmacfarlane marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Reward | ||
|
|
||
| The reward function comprises: | ||
| - `-0.1` for each step taken in the environment. | ||
| - `+1` for each box moved onto a target location and `-1` for each box moved off a target location. | ||
| - `+10` upon successful placement of all four boxes on their targets. | ||
|
|
||
| ## Episode Termination | ||
|
|
||
| The episode concludes when: | ||
| - The step limit of 120 is reached. | ||
| - All 4 boxes are placed on targets (i.e., the problem is solved). | ||
clement-bonnet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Dataset | ||
|
|
||
| The Boxoban dataset offers a collection of puzzle levels. Each level features four boxes and four targets. The dataset has three levels of difficulty: 'unfiltered', 'medium', and 'hard'. | ||
|
|
||
| | Dataset Split | Number of Levels | | ||
| |---------------|------------------| | ||
| | Unfiltered (Training) | 900,000 | | ||
| | Unfiltered (Validation) | 100,000 | | ||
| | Unfiltered (Test) | 1000 | | ||
| | Medium (Training) | 450,000 | | ||
| | Medium (Validation) | 50,000 | | ||
| | Hard | 3332 | | ||
|
|
||
|
|
||
| The dataset generation procedure and more details can be found in Guez et al., 2018 <a href="#ref1">[1]</a>. | ||
|
|
||
| ## Graphics | ||
|
|
||
| | Type | Graphic | | ||
| |------------------|----------------------------------------------------------------------------------------| | ||
| | Wall |  | | ||
| | Floor |  | | ||
| | Target |  | | ||
| | Box on Target |  | | ||
| | Box Off Target |  | | ||
| | Agent Off Target |  | | ||
| | Agent On Target |  | | ||
|
|
||
| ## Registered Versions 📖 | ||
|
|
||
| - `Sokoban-v0`: Sokoban game with levels generated using DeepMind Boxoban dataset (unfiltered train). | ||
|
|
||
| ## References | ||
| <a id="ref1">[1]</a> Guez, A., Mirza, M., Gregor, K., Kabra, R., Racaniere, S., Weber, T., Raposo, D., Santoro, A., Orseau, L., Eccles, T., Wayne, G., Silver, D., Lillicrap, T., Valdes, V. (2018). An investigation of Model-free planning: boxoban levels. Available at [https://github.com/deepmind/boxoban-levels](https://github.com/deepmind/boxoban-levels) | ||
|
|
||
| <a id="ref2">[2]</a> Schrader, M. (2018). Gym-sokoban. Available at [https://github.com/mpSchrader/gym-sokoban](https://github.com/mpSchrader/gym-sokoban) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Copyright 2022 InstaDeep Ltd. All rights reserved. | ||
| # | ||
| # 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. | ||
|
|
||
| from jumanji.environments.routing.sokoban.env import Sokoban | ||
| from jumanji.environments.routing.sokoban.types import Observation, State |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Copyright 2022 InstaDeep Ltd. All rights reserved. | ||
| # | ||
| # 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. | ||
|
|
||
| import jax.numpy as jnp | ||
|
|
||
| # Translating actions to coordinate changes | ||
| MOVES = jnp.array([[-1, 0], [0, 1], [1, 0], [0, -1]]) | ||
| NOOP = -1 | ||
|
|
||
| # Object encodings | ||
| EMPTY = 0 | ||
| WALL = 1 | ||
| TARGET = 2 | ||
| AGENT = 3 | ||
| BOX = 4 | ||
| TARGET_AGENT = 5 | ||
| TARGET_BOX = 6 | ||
|
|
||
| # Environment Variables | ||
| N_BOXES = 4 | ||
| GRID_SIZE = 10 | ||
|
|
||
| # Reward Function | ||
| LEVEL_COMPLETE_BONUS = 10 | ||
| SINGLE_BOX_BONUS = 1 | ||
| STEP_BONUS = -0.1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.