-
Notifications
You must be signed in to change notification settings - Fork 123
[Enhancement] Add Doom-Env - Doom Slayer goes to OpenEnv School to learn RL #228
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
Open
AlirezaShamsoshoara
wants to merge
48
commits into
meta-pytorch:main
Choose a base branch
from
AlirezaShamsoshoara:alidev_doom_env_01
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
a2c6225
add the .dockerignore file
AlirezaShamsoshoara 1bc2c00
add the readme file
AlirezaShamsoshoara 791b46f
add the init for the doom
AlirezaShamsoshoara 45e99e3
add the uv.lock
AlirezaShamsoshoara 0b754bb
add the client code
AlirezaShamsoshoara 9ff9988
add the model
AlirezaShamsoshoara 5f86fd5
add the openenv yaml file to doom env
AlirezaShamsoshoara 602ea5a
add the pyproject toml file for doom
AlirezaShamsoshoara a198cf8
add the DockerFile for Doom server
AlirezaShamsoshoara 85b6dae
add the doom env environment to the server path
AlirezaShamsoshoara 142c921
add the app for the server
AlirezaShamsoshoara caf9358
add the init for the server - Doom
AlirezaShamsoshoara 1d4ce86
add the example to the doom
AlirezaShamsoshoara d3c4a2b
add vizdoom.ini to gitignore
AlirezaShamsoshoara 74d9825
give the opportunity to the user to be able to render the observation
AlirezaShamsoshoara 351bbaf
update the README for the new docker format
AlirezaShamsoshoara c5ad51a
update the Dockerfile
AlirezaShamsoshoara 55cdb2d
add the requirements for the server to install them in the docker image
AlirezaShamsoshoara 7071952
add the doom slayer drawing
AlirezaShamsoshoara 1b17ec4
a code to generate gifs to cover default scnearios
AlirezaShamsoshoara e66f1de
add all gifs to the assets
AlirezaShamsoshoara e5c939e
add the gifs to top of the README file
AlirezaShamsoshoara 3ca8ba9
update gif files and the project structure in README
AlirezaShamsoshoara 08a6eb1
add two more gifs for symmetric view on README
AlirezaShamsoshoara 92c96ab
move the example from the root of env to the example folder
AlirezaShamsoshoara faf6bdc
fix relative path issue for importing
AlirezaShamsoshoara d8b0fab
update pyproject.toml to consider standard for uvicorn
AlirezaShamsoshoara 5ae10c5
fix the issue of the _step_payload that it cannot serialize to json p…
AlirezaShamsoshoara cd7292b
support the visualization when running the docker
AlirezaShamsoshoara 3aa48bd
fix the issue of wrong visualization resolution for the docker run
AlirezaShamsoshoara fc3a9d5
update the usage for the doom visualizer file
AlirezaShamsoshoara 8a22dce
add doomenv to the docker build yaml
AlirezaShamsoshoara 6fac432
add the doom.md to the doc path
AlirezaShamsoshoara cb35e3d
update the lock and app to be compatible with openenv docker push and…
AlirezaShamsoshoara dec7e6c
fix the color issue in readme for openenv push feature
AlirezaShamsoshoara 03aaf74
update the dockerfile to fix the issue of relative path
AlirezaShamsoshoara e6eeb6f
add the environment card for the doom_env in the doc environments
AlirezaShamsoshoara 046e4b4
add doom guy drawing
AlirezaShamsoshoara 5a0cf44
resize the image and align to the center via html
AlirezaShamsoshoara 6e0cf9c
align the project structure
AlirezaShamsoshoara f45dd98
update the README file to include the HF OpenEnv space for Doom-env
AlirezaShamsoshoara 235a3fd
start the unittest part for the doom - add init
AlirezaShamsoshoara 5f36434
add the conftest for the class types
AlirezaShamsoshoara 87c571e
add the test models
AlirezaShamsoshoara da22ab4
add the test doom client
AlirezaShamsoshoara f131b62
add the test for doom environment
AlirezaShamsoshoara f68e802
add the test for doom integration with a server setup
AlirezaShamsoshoara 56ae7dd
update the README for doom unittests
AlirezaShamsoshoara 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
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 |
|---|---|---|
|
|
@@ -108,4 +108,8 @@ outputs/ | |
| /uv.lock | ||
| .uv/ | ||
|
|
||
| # ViZDoom generated files | ||
| **/_vizdoom.ini | ||
| _vizdoom.ini | ||
|
|
||
| *.backup*/ | ||
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 @@ | ||
| --8<-- "../../src/envs/doom_env/README.md" |
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,245 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| """ | ||
| Example usage of the Doom Environment. | ||
|
|
||
| This script demonstrates how to use the Doom environment with OpenEnv. | ||
| It can be run in two modes: | ||
| 1. With Docker: Uses the Docker image to run the environment | ||
| 2. Local: Directly uses the DoomEnvironment class (requires ViZDoom installed) | ||
|
|
||
| Both modes support rendering if the appropriate libraries are installed. | ||
| """ | ||
|
|
||
| import argparse | ||
| import sys | ||
| import time | ||
| from pathlib import Path | ||
|
|
||
| import numpy as np | ||
|
|
||
| # Add src to path | ||
| sys.path.insert(0, str(Path(__file__).parent.parent / "src")) | ||
|
|
||
|
|
||
| def run_with_docker(render: bool = False, num_steps: int = 100): | ||
| """Run Doom environment using Docker container.""" | ||
| from envs.doom_env import DoomAction, DoomEnv | ||
|
|
||
| print("Starting Doom environment with Docker...") | ||
| try: | ||
| # Create environment from Docker image | ||
| env = DoomEnv.from_docker_image("doom-env:latest") | ||
|
|
||
| # Reset to start a new episode | ||
| result = env.reset() | ||
| print(f"✓ Environment reset") | ||
| print(f" Screen shape: {result.observation.screen_shape}") | ||
| print(f" Available actions: {result.observation.available_actions}") | ||
| print(f" Game variables: {result.observation.game_variables}") | ||
|
|
||
| if render: | ||
| print(f"\n✓ Rendering enabled") | ||
| print(f" Note: Rendering uses the observation from the server") | ||
| print( | ||
| f" For best performance, consider using local mode with window_visible=True" | ||
| ) | ||
| print(f" Alternative: Use the web interface at http://localhost:8000/web") | ||
| print( | ||
| f" Make sure opencv-python or matplotlib is installed locally for rendering" | ||
| ) | ||
|
|
||
| # Run for a few steps | ||
| print(f"\nRunning episode for {num_steps} steps...") | ||
| for i in range(num_steps): | ||
| # Take a random action from available actions | ||
| available_actions = result.observation.available_actions | ||
| if available_actions: | ||
| action_id = int( | ||
| np.random.choice(available_actions) | ||
| ) # Convert to Python int | ||
| else: | ||
| action_id = 0 | ||
|
|
||
| result = env.step(DoomAction(action_id=action_id)) | ||
|
|
||
| # Render if requested | ||
| if render: | ||
| env.render() | ||
|
|
||
| if i % 10 == 0 or result.observation.done: | ||
| print(f"Step {i+1}:") | ||
| print(f" Action: {action_id}") | ||
| print(f" Reward: {result.reward}") | ||
| print(f" Done: {result.observation.done}") | ||
| if result.observation.game_variables: | ||
| print(f" Game vars: {result.observation.game_variables}") | ||
|
|
||
| if result.observation.done: | ||
| print(f"\n✓ Episode finished at step {i+1}!") | ||
| break | ||
|
|
||
| # Small delay for rendering to be visible | ||
| if render: | ||
| time.sleep(0.03) | ||
|
|
||
| finally: | ||
| print("\nCleaning up...") | ||
| env.close() | ||
| print("✓ Environment closed") | ||
|
|
||
|
|
||
| def run_local(render: bool = False, num_steps: int = 100): | ||
| """Run Doom environment locally without Docker.""" | ||
| try: | ||
| from envs.doom_env.models import DoomAction | ||
| from envs.doom_env.server.doom_env_environment import DoomEnvironment | ||
| except ImportError as e: | ||
| print(f"Error: Could not import environment components: {e}") | ||
| print("Make sure ViZDoom is installed: pip install vizdoom") | ||
| return | ||
|
|
||
| print("Starting Doom environment locally...") | ||
| try: | ||
| # Create environment | ||
| # Note: When using local mode, you can enable window_visible=True | ||
| # for native ViZDoom rendering (most efficient) | ||
| env = DoomEnvironment( | ||
| scenario="basic", | ||
| screen_resolution="RES_320X240", # Higher resolution for better visibility | ||
| screen_format="RGB24", | ||
| window_visible=render, # Use native ViZDoom window if rendering | ||
| use_discrete_actions=True, | ||
| ) | ||
|
|
||
| # Reset to start a new episode | ||
| obs = env.reset() | ||
| print(f"✓ Environment reset") | ||
| print(f" Screen shape: {obs.screen_shape}") | ||
| print(f" Available actions: {obs.available_actions}") | ||
| print(f" Game variables: {obs.game_variables}") | ||
|
|
||
| if render: | ||
| print(f"\n✓ Rendering enabled") | ||
| if env.window_visible: | ||
| print(f" Using native ViZDoom window (most efficient)") | ||
| else: | ||
| print(f" Using Python rendering (cv2/matplotlib)") | ||
|
|
||
| # Run for a few steps | ||
| print(f"\nRunning episode for {num_steps} steps...") | ||
| for i in range(num_steps): | ||
| # Take a random action | ||
| if obs.available_actions: | ||
| action_id = int( | ||
| np.random.choice(obs.available_actions) | ||
| ) # Convert to Python int | ||
| else: | ||
| action_id = 0 | ||
|
|
||
| obs = env.step(DoomAction(action_id=action_id)) | ||
|
|
||
| # Render if requested and not using native window | ||
| if render and not env.window_visible: | ||
| env.render() | ||
|
|
||
| if i % 10 == 0 or obs.done: | ||
| print(f"Step {i+1}:") | ||
| print(f" Action: {action_id}") | ||
| print(f" Reward: {obs.reward}") | ||
| print(f" Done: {obs.done}") | ||
| if obs.game_variables: | ||
| print(f" Game vars: {obs.game_variables}") | ||
|
|
||
| if obs.done: | ||
| print(f"\n✓ Episode finished at step {i+1}!") | ||
| break | ||
|
|
||
| # Small delay for rendering to be visible | ||
| if render: | ||
| time.sleep(0.03) | ||
|
|
||
| # Visualize final frame statistics | ||
| if not obs.done: | ||
| screen = np.array(obs.screen_buffer).reshape(obs.screen_shape) | ||
| print(f"\nFinal screen statistics:") | ||
| print(f" Shape: {screen.shape}") | ||
| print(f" Dtype: {screen.dtype}") | ||
| print(f" Min: {screen.min()}, Max: {screen.max()}") | ||
|
|
||
| except Exception as e: | ||
| print(f"Error running environment: {e}") | ||
| import traceback | ||
|
|
||
| traceback.print_exc() | ||
| finally: | ||
| if "env" in locals(): | ||
| env.close() | ||
| print("✓ Environment closed") | ||
|
|
||
|
|
||
| def main(): | ||
| """Main entry point.""" | ||
| parser = argparse.ArgumentParser( | ||
| description="Run Doom environment example", | ||
| formatter_class=argparse.RawDescriptionHelpFormatter, | ||
| epilog=""" | ||
| Examples: | ||
| # Run with Docker (default) | ||
| python example.py | ||
|
|
||
| # Run with Docker and rendering | ||
| python example.py --render | ||
|
|
||
| # Run locally without Docker | ||
| python example.py --local | ||
|
|
||
| # Run locally with rendering (uses native ViZDoom window) | ||
| python example.py --local --render | ||
|
|
||
| # Run for more steps | ||
| python example.py --local --render --steps 300 | ||
|
|
||
| Note: Rendering requires opencv-python or matplotlib: | ||
| pip install opencv-python | ||
| # or | ||
| pip install matplotlib | ||
| """, | ||
| ) | ||
| parser.add_argument( | ||
| "--docker", action="store_true", default=False, help="Run with Docker container" | ||
| ) | ||
| parser.add_argument( | ||
| "--local", action="store_true", help="Run locally without Docker" | ||
| ) | ||
| parser.add_argument( | ||
| "--render", | ||
| action="store_true", | ||
| help="Enable rendering (shows game window or visualization)", | ||
| ) | ||
| parser.add_argument( | ||
| "--steps", | ||
| type=int, | ||
| default=100, | ||
| help="Number of steps to run (default: 100)", | ||
| ) | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| # Default to docker if neither specified | ||
| if not args.local and not args.docker: | ||
| args.docker = True | ||
|
|
||
| if args.local: | ||
| run_local(render=args.render, num_steps=args.steps) | ||
| else: | ||
| run_with_docker(render=args.render, num_steps=args.steps) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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.