-
Notifications
You must be signed in to change notification settings - Fork 102
[ENVIRONMENT] Wildfire Environment to simulate Wildfires for OpenEnv (FastAPI, RL-compatible) #108
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
Conversation
|
Hi @shankerram3! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Updated README with sample rendering code for wildfree simulation.
Added sections on wildfire simulation motivation, research goals, and citations to the README.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new wildfire simulation environment to the OpenEnv framework. The environment models fire spread dynamics influenced by wind, humidity, and limited resources (water and firebreaks), enabling RL agents to learn fire containment strategies.
Key Changes
- Implements
WildfireEnvironmentwith physics-based fire spread mechanics including wind direction effects, humidity suppression, and multi-tick burn lifetime - Adds Docker containerization support with build scripts and Dockerfile for deployment
- Provides client-side API with visualization utilities for rendering the grid state
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
src/envs/wildfire_env/server/wildfire_environment.py |
Core server implementation with fire spread logic, reward shaping, and action handling |
src/envs/wildfire_env/models.py |
Data models for actions, observations, and state |
src/envs/wildfire_env/client.py |
HTTP client implementation with grid rendering utility |
src/envs/wildfire_env/server/app.py |
FastAPI application entry point |
src/envs/wildfire_env/server/Dockerfile |
Docker container configuration |
src/envs/wildfire_env/server/build_docker.sh |
Docker build script |
src/envs/wildfire_env/README.md |
Comprehensive documentation with usage examples |
src/envs/wildfire_env/__init__.py |
Package initialization and exports |
src/envs/wildfire_env/server/__init__.py |
Server package initialization |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # --- Required abstract property implementation --- | ||
| @property | ||
| def state(self) -> WildfireState: | ||
| """Return the current environment state.""" | ||
| return self._state |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent indentation detected. Lines 364-368 have mixed indentation levels. Line 364 has excessive leading whitespace, line 367 has only 1 space of indentation instead of the expected 8 spaces for a method body. Standardize to use consistent 4-space indentation throughout.
| # --- Required abstract property implementation --- | |
| @property | |
| def state(self) -> WildfireState: | |
| """Return the current environment state.""" | |
| return self._state | |
| # --- Required abstract property implementation --- | |
| @property | |
| def state(self) -> WildfireState: | |
| """Return the current environment state.""" | |
| return self._state |
src/envs/wildfire_env/models.py
Outdated
| burned_count: int # total ash (0) cells (cumulative) | ||
| reward_hint: float = 0.0 | ||
| remaining_water: int = 0 | ||
| remaining_breaks: int = 0# optional shaping info |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment '# optional shaping info' on line 28 is misplaced. It should be on line 26 or 27, or removed entirely since it doesn't accurately describe the resource fields on lines 27-28. The comment appears to be a leftover from line 26's reward_hint field.
| remaining_breaks: int = 0# optional shaping info | |
| remaining_breaks: int = 0 |
src/envs/wildfire_env/client.py
Outdated
| rows = [] | ||
| for y in range(h): | ||
| rows.append("".join(legend.get(g[y*w+x], "?") for x in range(w))) | ||
| meta = f"step={obs.step} wind={obs.wind_dir} hum={obs.humidity:.2f} burning={obs.burning_count} burned= {obs.burned_count}" |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excessive whitespace after 'burned=' creates inconsistent spacing in the output string. Replace the multiple spaces with a single space for consistent formatting.
| meta = f"step={obs.step} wind={obs.wind_dir} hum={obs.humidity:.2f} burning={obs.burning_count} burned= {obs.burned_count}" | |
| meta = f"step={obs.step} wind={obs.wind_dir} hum={obs.humidity:.2f} burning={obs.burning_count} burned= {obs.burned_count}" |
| ) | ||
|
|
||
| def _parse_state(self, payload: dict) -> WildfireState: | ||
| return WildfireState(**payload) |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing blank lines before function definition. PEP 8 requires two blank lines before top-level function definitions. Add a blank line between line 18 and line 19.
| return WildfireState(**payload) | |
| return WildfireState(**payload) |
src/envs/wildfire_env/README.md
Outdated
| ``` | ||
|
|
||
| --- | ||
| ## Sample rendering to see wildfree simulation |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'wildfree' to 'wildfire'.
| ## Sample rendering to see wildfree simulation | |
| ## Sample rendering to see wildfire simulation |
| @@ -0,0 +1,321 @@ | |||
| import os | |||
| import random, uuid | |||
| from typing import List | |||
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'List' is not used.
| from typing import List |
| from dataclasses import replace | ||
|
|
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'replace' is not used.
| from dataclasses import replace |
|
|
||
| import os | ||
| import random, uuid | ||
| from typing import List |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'List' is not used.
| from typing import List |
| import os | ||
| import random, uuid | ||
| from typing import List | ||
| from dataclasses import replace |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'replace' is not used.
| from dataclasses import replace |
Darktex
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wowwww this is soo cool!!! Thank you for the contribution :)
I can see a few small things that we should change, but otherwise we are almost ready to land.
Also, could you add an example? examples/wildfire.py would be awesome...
| @@ -0,0 +1,10 @@ | |||
| # server/app.py | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, what does this directory do? .ipynb_checkpoints doesn't look like a directory that you wanna check in! :D
src/envs/wildfire_env/README.md
Outdated
|
|
||
| from IPython.display import clear_output, display | ||
| import matplotlib.colors as mcolors | ||
| sys.path.append("/workspace/OpenEnv/src") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded path
src/envs/wildfire_env/server/app.py
Outdated
| from ..models import WildfireAction, WildfireObservation | ||
| from .wildfire_environment import WildfireEnvironment | ||
|
|
||
| W = int(os.getenv("WILDFIRE_W", "16")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming is inconsistent, because in wildfire_environment.py you actually use WILDFIRE_WIDTH. Same thing for height
src/envs/wildfire_env/README.md
Outdated
| from envs.wildfire_env.server.wildfire_environment import WildfireEnvironment | ||
|
|
||
|
|
||
| client = WildfireEnv("http://localhost:8020") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use port 8000 for these examples
src/envs/wildfire_env/README.md
Outdated
| time.sleep(0.3) | ||
|
|
||
|
|
||
| res = client.step(WildfireAction(action="WAIT")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actual action is lowercase "wait" though
src/envs/wildfire_env/README.md
Outdated
| import numpy as np | ||
| import time, sys | ||
|
|
||
| from IPython.display import clear_output, display |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is jupyter specific but won't work in standalone Python
| remaining_breaks: int = 0# optional shaping info | ||
|
|
||
| @dataclass | ||
| class WildfireState(State): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add burn_timers here. They currently get added dynamically upon reset which breaks type safety
| ) | ||
|
|
||
| # per-cell burn timers (persist across steps) | ||
| self._state.burn_timers = [0] * (self.w * self.h) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment in models.py
This commit addresses all the review comments from PR meta-pytorch#108: 1. Remove .ipynb_checkpoints directories from version control - Deleted all checkpoint files that were accidentally committed 2. Fix hardcoded file paths in README - Removed hardcoded path: sys.path.append("/workspace/OpenEnv/src") - Changed port from 8020 to 8000 for consistency - Removed unnecessary import of WildfireEnvironment from example 3. Standardize environment variable naming - Changed WILDFIRE_W to WILDFIRE_WIDTH in server/app.py - Changed WILDFIRE_H to WILDFIRE_HEIGHT in server/app.py - Now consistent with documentation and other env vars 4. Fix action case consistency - Changed "WAIT" to "wait" in README example - Ensures consistency with lowercase action names 5. Add note about Jupyter-specific dependencies - Added note in README explaining IPython requirements - References new standalone example file 6. Add burn_timers to WildfireState dataclass - Added burn_timers field to models.py for type safety - Prevents runtime attribute assignment outside dataclass 7. Create examples/wildfire.py demonstration file - New standalone Python example without Jupyter dependencies - Demonstrates basic firefighting strategy - Includes visualization using render_grid function 8. Code cleanup - Fixed formatting in models.py (moved misplaced comment) - Removed unused imports (List, replace) from wildfire_environment.py - Improved import organization and PEP 8 compliance - Fixed typo: "wildfree" to "wildfire" in README All changes maintain backward compatibility while improving code quality and usability.
Address final Copilot AI review comments: 1. Add blank line before render_grid function (PEP 8) - Added two blank lines between class and module-level function 2. Fix excessive whitespace in client.py - Removed extra spaces after "burned=" in metadata string 3. Fix inconsistent indentation in wildfire_environment.py - Corrected state property indentation to use 4-space standard - Fixed comment alignment - Fixed docstring and return statement indentation All code now follows PEP 8 style guidelines.
This script is required by the pr-new-env.yml workflow to deploy new environments to Hugging Face Spaces during PR validation. The script: - Accepts --env, --space-suffix, and --hub-tag parameters - Prepares files using prepare_hf_deployment.sh - Clones or creates HF Space repository - Deploys the environment to Hugging Face - Provides detailed logging and error handling Fixes CI/CD workflow error: chmod: cannot access 'scripts/deploy_to_hf.sh'
- Remove .ipynb_checkpoints directory from version control - Add .ipynb_checkpoints/ to .gitignore to prevent future commits This addresses the code quality feedback from PR meta-pytorch#108 review. Most other issues mentioned in the review (environment variable naming, port references, burn_timers in dataclass, spelling errors, unused imports) were already addressed in previous commits on this branch.
No description provided.