-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix render_mode attribute not being set by sb3 wrapper (#243)
Co-authored-by: Clément Dumas <[email protected]>
- Loading branch information
1 parent
035cf0f
commit 5b7b2ed
Showing
3 changed files
with
43 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,25 +1,49 @@ | ||
from pettingzoo.butterfly import pistonball_v6 | ||
from stable_baselines3.common.vec_env import VecVideoRecorder | ||
|
||
from supersuit import pettingzoo_env_to_vec_env_v1 | ||
import supersuit as ss | ||
|
||
|
||
def schedule(episode_idx): | ||
print(episode_idx) | ||
return episode_idx <= 1 | ||
|
||
|
||
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, "/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() | ||
env = pettingzoo_env_to_vec_env_v1(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.reset() | ||
# arr = venv.render(mode="rgb_array") | ||
# venv.reset() | ||
# assert len(arr.shape) == 3 and arr.shape[2] == 3 | ||
# venv.reset() | ||
# try: | ||
# venv.close() | ||
# except RuntimeError: | ||
# pass | ||
def test_vector_render_multiproc(): | ||
env = make_env() | ||
num_envs = 1 | ||
venv = ss.concat_vec_envs_v1( | ||
env, num_envs, num_cpus=num_envs, base_class="stable_baselines3" | ||
) | ||
venv.reset() | ||
arr = venv.render() | ||
venv.reset() | ||
assert len(arr.shape) == 3 and arr.shape[2] == 3 | ||
venv.reset() | ||
try: | ||
venv.close() | ||
except RuntimeError: | ||
pass |