You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue is with Multi-Task and Meta-RL rendering. The user may want to render in multiple environments in succession and go back to previous environments and render after X steps of training. However it seems that when a user tries to do this, the context of the Mujoco renderer does not make the previously created viewer the current context. In these cases you get rendered frames that look like the ones from the linked issue above.
I think the fix is to change the if statement in this function to >= 1. This forces the viewer to be current context. However, I don't know if this is a fix that will cause issues with single environments. It shouldn't because calling the make context current function on a context that is already current should be a defined behaviour.
Code example
import metaworld
import random
import matplotlib.pyplot as plt
mt50 = metaworld.MT50() # Construct the benchmark, sampling tasks
training_envs = []
forname, env_clsinmt50.train_classes.items():
env = env_cls(render_mode="rgb_array")
task = random.choice([task fortaskin mt50.train_tasks
if task.env_name == name])
env.set_task(task)
env.camera_name="corner3"
training_envs.append(env)
# 1. works (image 1)plt.imshow(training_envs[34].render()) # pick-place-v2plt.show()
# 2. works (image 2)plt.imshow(training_envs[1].render()) # basketball-v2plt.show()
# 3. does not work anymore (image 3)plt.imshow(training_envs[34].render()) # pick-place-v2plt.show()
System info
No response
Additional context
No response
Checklist
I have checked that there is no similar issue in the repo
The text was updated successfully, but these errors were encountered:
I tested the performance impact of the proposed change and observed a 1.42% performance degradation of rendering with render_mode="rgb_array" (but can a more complex environment may incur a bigger performance degradation).
importgymnasiumimportgymnasium.utils.performanceenv=gymnasium.make("Ant-v5", render_mode="rgb_array")
env.reset(seed=1234)
print(f"renders per second: {gymnasium.utils.performance.benchmark_render(env, target_duration=600)}")
$ py test3.py && py test3.py
renders per second: 401.82104986400776 # old version
renders per second: 396.10183664784245 # version with [reginald-mclean](https://github.com/reginald-mclean)'s proposed patch
I believe the proper solution would be to call self.mujoco_renderer.make_context_current() on the Meta-World side, whenever contexts are switched
Describe the bug
This issue was originally opened in Meta-World by @ManfredStoiber. There are images of the rendering issue in the linked issue.
The issue is with Multi-Task and Meta-RL rendering. The user may want to render in multiple environments in succession and go back to previous environments and render after X steps of training. However it seems that when a user tries to do this, the context of the Mujoco renderer does not make the previously created viewer the current context. In these cases you get rendered frames that look like the ones from the linked issue above.
I think the fix is to change the if statement in this function to >= 1. This forces the viewer to be current context. However, I don't know if this is a fix that will cause issues with single environments. It shouldn't because calling the make context current function on a context that is already current should be a defined behaviour.
Code example
System info
No response
Additional context
No response
Checklist
The text was updated successfully, but these errors were encountered: