Skip to content

[Feature] Add Safety-Gymnasium environment wrapper#3689

Merged
vmoens merged 4 commits intopytorch:mainfrom
theap06:feat/safety-gymnasium
Apr 29, 2026
Merged

[Feature] Add Safety-Gymnasium environment wrapper#3689
vmoens merged 4 commits intopytorch:mainfrom
theap06:feat/safety-gymnasium

Conversation

@theap06
Copy link
Copy Markdown
Contributor

@theap06 theap06 commented Apr 28, 2026

Adds SafetyGymnasiumWrapper and SafetyGymnasiumEnv for constrained-RL benchmarks. The underlying step API returns a 6-tuple with a parallel cost signal; the wrapper folds cost into the gymnasium info dict so the existing GymWrapper machinery is reused, then registers an info-dict reader that exposes cost as a top-level tensordict key alongside reward.
##Motivation
Fixes #509

Adds SafetyGymnasiumWrapper and SafetyGymnasiumEnv for constrained-RL
benchmarks. The underlying step API returns a 6-tuple with a parallel
cost signal; the wrapper folds cost into the gymnasium info dict so the
existing GymWrapper machinery is reused, then registers an info-dict
reader that exposes "cost" as a top-level tensordict key alongside
"reward".

Adds SafetyGymnasiumWrapper and SafetyGymnasiumEnv for constrained-RL
benchmarks. The underlying step API returns a 6-tuple with a parallel
cost signal; the wrapper folds cost into the gymnasium info dict so the
existing GymWrapper machinery is reused, then registers an info-dict
reader that exposes cost as a top-level tensordict key alongside
reward.
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Apr 28, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3689

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

⏳ No Failures, 16 Pending

As of commit 40ab5e5 with merge base 471e813 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 28, 2026
@github-actions github-actions Bot added Feature New feature Environments Adds or modifies an environment wrapper labels Apr 28, 2026
Comment thread torchrl/envs/libs/safety_gymnasium.py Outdated
Comment thread test/libs/test_safety_gymnasium.py
Comment thread torchrl/envs/libs/safety_gymnasium.py Outdated
Comment thread torchrl/envs/libs/safety_gymnasium.py Outdated
Comment thread torchrl/envs/libs/safety_gymnasium.py Outdated
@theap06 theap06 requested a review from vmoens April 28, 2026 22:10
@github-actions github-actions Bot added Documentation Improvements or additions to documentation CI Has to do with CI setup (e.g. wheels & builds, tests...) labels Apr 28, 2026
Copy link
Copy Markdown
Collaborator

@vmoens vmoens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vmoens vmoens merged commit 77c4d20 into pytorch:main Apr 29, 2026
109 of 110 checks passed
@ParamThakkar123
Copy link
Copy Markdown
Contributor

Looks like the original issue for call for contributions got closed because the PR comment mentioned that this PR fixes the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Has to do with CI setup (e.g. wheels & builds, tests...) CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Documentation Improvements or additions to documentation Environments Adds or modifies an environment wrapper Feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DO NOT CLOSE] Call for contributions

3 participants