Skip to content

Commit

Permalink
Merge pull request #83 from mgoulao/master
Browse files Browse the repository at this point in the history
Add environment list
  • Loading branch information
pseudo-rnd-thoughts authored Jan 31, 2023
2 parents 7f8c890 + b1e76d6 commit f594b29
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
- name: Generate Environments page
run: xvfb-run -a -s "-screen 0 1024x768x24 -ac +extension GLX +render -noreset" python docs/_scripts/gen_docs_page.py

- name: Generate Environments page
run: xvfb-run -a -s "-screen 0 1024x768x24 -ac +extension GLX +render -noreset" python docs/_scripts/gen_envs_display.py

- name: Build
run: sphinx-build -b dirhtml -v docs _build

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
- --show-source
- --statistics
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black"]
Expand Down
2 changes: 1 addition & 1 deletion docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
environments/**/*.md
environments/**/list.html
content/env_list.html
18 changes: 9 additions & 9 deletions docs/_scripts/gen_docs_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ def trim(docstring):
# Docstring
res_env_md += f"{docstring}\n"

file_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"environments",
f"{env_name_snake_case}.md",
)

file = open(file_path, "w+", encoding="utf-8")
file.write(res_env_md)
file.close()
file_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"environments",
f"{env_name_snake_case}.md",
)

file = open(file_path, "w+", encoding="utf-8")
file.write(res_env_md)
file.close()
61 changes: 61 additions & 0 deletions docs/_scripts/gen_envs_display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os

import gymnasium as gym

import miniworld


def create_grid_cell(env_id):
env_name = env_id.split("-")[-2]
return f"""
<a href="/environments/{env_name}">
<div class="env-grid__cell">
<div class="cell__image-container">
<img src="/_static/environments/{env_name.lower()}.jpg">
</div>
<div class="cell__title">
<span>{env_name}</span>
</div>
</div>
</a>
"""


def generate_page(env_list):
cells = [create_grid_cell(env_id) for env_id in env_list]
cells = "\n".join(cells)

return f"""
<div class="env-grid">
{cells}
</div>
"""


if __name__ == "__main__":
miniworld_env_ids = sorted(list(miniworld.envs.env_ids))
filtered_env_ids = []
previous_env_name = None

for env_id in miniworld_env_ids:
print(env_id)
env_spec = gym.spec(env_id)

# MiniWorld-Hallway -> Hallway
env_name = env_spec.name.split("-")[1]
# We are not adding sub envs like YMazeLeft
if previous_env_name is None or previous_env_name not in env_name:
previous_env_name = env_name
filtered_env_ids.append(env_id)

file_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"content",
"env_list.html",
)

res = generate_page(filtered_env_ids)

file = open(file_path, "w+", encoding="utf-8")
file.write(res)
file.close()
File renamed without changes
File renamed without changes
Binary file added docs/_static/img/miniworld_homepage.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions docs/content/env_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Environment List

```{raw} html
:file: env_list.html
```
5 changes: 3 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ content/troubleshooting
:glob:
:caption: Environments
content/env_list.md
environments/*
```

Expand All @@ -33,9 +34,9 @@ Contribute to the Docs <https://github.com/Farama-Foundation/Miniworld/tree/mast
# Miniworld


```{figure} _static/environments/collecthealth.jpg
```{figure} _static/img/miniworld_homepage.gif
:width: 400px
:alt: Observation from Collect Health environment
:alt: Sequence of observations from Collect Health environment
```

**The Gymnasium interface allows to initialize and interact with the Miniworld default environments as follows:**
Expand Down

0 comments on commit f594b29

Please sign in to comment.