Skip to content
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

fix render_mode attribute not being set by sb3 wrapper. #242

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions supersuit/vector/sb3_vector_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def __init__(self, venv):
self.num_envs = venv.num_envs
self.observation_space = venv.observation_space
self.action_space = venv.action_space
self.render_mode = venv.render_mode
self.reset_infos = []

def reset(self, seed=None, options=None):
Expand Down
38 changes: 31 additions & 7 deletions test/test_vector/test_render.py
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry but this should be in a separate class or file, SB3 is does not officially support pettingzoo at all, even though it does work we can’t guarantee anything. RGB array rendering means it saves it as a numpy object, so we still want the existing test, but also testing that SB3 works is fine I suppose as well. I may make another PR though making these wrappers more similar to pettingzoo where they inherit all of the underlying env properties, rather than just the render mode and ones we specify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok so won't merge this one but rather merge your enhanced sb3 wrapper ?
Let me know if we should just close this and let me add the test to your PR

Copy link
Contributor

Choose a reason for hiding this comment

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

I honestly don't remember what I did with the SB3 wrapper, I think it's fine to test something with SB3 as you do here, but it needs to be in addition to the previous test, not replacing the previous one.

I will look into the changes Florian made to PettingZoo to fix the attributes inheritance and such, and see if it's possible to do here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok cool.
But I'm not replacing any tests here. The only one that was here was already commented because it fails. I updated the code to match the latest SS version but it still failed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see, hmm well in that case we should probably try to make that test not fail in an ideal world at least

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed but I think it is outside the scope of this PR as it is not related to the attribute erasing (see the below error message)

X connection to :0 broken (explicit kill or server shutdown).
XIO:  fatal IO error 2 (No such file or directory) on X server ":0"
      after 88 requests (88 known processed) with 0 events remaining.
XIO:  fatal IO error 2 (No such file or directory) on X server ":0"
      after 88 requests (88 known processed) with 0 events remaining.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh that's bizarre... alright well fair enough I guess this is better than nothing

Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
from pettingzoo.butterfly import pistonball_v6
import supersuit as ss
from stable_baselines3.common.vec_env import VecVideoRecorder

from supersuit import pettingzoo_env_to_vec_env_v1

def schedule(episode_idx):
print(episode_idx)
return episode_idx <= 1

def make_env():
env = pistonball_v6.parallel_env()
env = pettingzoo_env_to_vec_env_v1(env)
return env

def make_sb3_record_env():
env = pistonball_v6.parallel_env(render_mode="rgb_array")
print(env.render_mode)
env = ss.pettingzoo_env_to_vec_env_v1(env)
envs = ss.concat_vec_envs_v1(env, 1, num_cpus=0, base_class="stable_baselines3")
envs = VecVideoRecorder(envs, f"/tmp", schedule)
return envs


def test_record_video_sb3():
envs = make_sb3_record_env()
envs.reset()
for _ in range(100):
envs.step([envs.action_space.sample() for _ in range(envs.num_envs)])
envs.close()


# def make_env():
# env = pistonball_v6.parallel_env(render_mode="rgb_array")
# env = ss.pettingzoo_env_to_vec_env_v1(env)
# return env


# unfortunately this test does not pass
# def test_vector_render_multiproc():
# env = make_env()
# num_envs = 3
# venv = concat_vec_envs_v1(env, num_envs, num_cpus=num_envs, base_class='stable_baselines3')
# venv = ss.concat_vec_envs_v1(
# env, num_envs, num_cpus=num_envs, base_class="stable_baselines3"
# )
# venv.reset()
# arr = venv.render(mode="rgb_array")
# arr = venv.render()
# venv.reset()
# assert len(arr.shape) == 3 and arr.shape[2] == 3
# venv.reset()
Expand Down
Loading