-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Question] recommended way to convert gymnasium/gym v26 envs to SB3 VecEnvs #1356
Comments
Hello, Also relevant: https://github.com/DLR-RM/rl-baselines3-zoo/blob/feat/gymnasium-support/rl_zoo3/gym_patches.py#L27-L50 But gym API is for single env only normally. |
Thanks for the links, the patched time limit works perfectly, but the problem is I can't get that to work with other wrappers like VecTransposeImage and VecFrameStack, which have the 4 return types with I found that ss actually has a ss.concat_vec_envs_v1() wrapper which works with base_class='stable_baselines3', and wraps it into a vector env, so I think (?) I can use that instead of writing my own vector env wrapper like DLR-RM/rl-baselines3-zoo#355. Although I guess in this case maybe the best option is to write a wrapper which turns the pettingzoo env into vector envs that have the right return types to work with VecFrameStack and VecTransposeImage, as you said that API using done was going to continue to be the standard for SB3 internally. |
it looks like you are mixing gym wrappers and VecEnv wrappers, as you notices they don't work together.
yes, probably the best option. |
Just as an update I got this working by modifying Working code using ss:
|
Good to hear =)
As explained in its paper/blog posrt, SB3 is focused on single agent model free RL. The only custom
Closing as the original question is solved. |
❓ Question
Posting this here to not spam the Gymnasium integration PR (#1327) as afaik it’s just a use case question rather than an issue with the PR. Will edit with example code to make things more clear but I mainly just want to know the best practices for converting envs with step() functions returning truncated and terminated bools into SB3’s API using done signals.
I would like to make vector envs but I run into issues due to the differing number of return types (5 vs 4). My initial thought was to ignore truncation and set done to equal termination, but reading discussions and documentation it seems like it’s best to set done equal to truncated or terminated. PR comments here say to use a TimeLimit wrapper as well, to capture the truncation signal. Is this then the best practice?
Example code of wrapping the env with this TimeLimit wrapper and doing this conversion would be greatly appreciated.
Relevant references:
https://github.com/DLR-RM/stable-baselines3/blob/feat/gymnasium-support/docs/guide/vec_envs.rst
openai/gym#3102 (comment)
https://gymnasium.farama.org/content/migration-guide/
#780 (comment)
Edit: a bit more context for what my issue was (converting the step function):
#1327 (comment)
Full code below: sb3_train.py (updating older training script with older pettingzoo using gym rather than gymnasium):
Utils helper file (also updating original script with old pettingzoo/gym rather than gymnasium):
Error:
Checklist
The text was updated successfully, but these errors were encountered: