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

mjpython passive viewer corrupts variable named model (and others) #2265

Open
2 tasks done
jaraujo98 opened this issue Dec 3, 2024 · 0 comments
Open
2 tasks done
Assignees
Labels
bug Something isn't working

Comments

@jaraujo98
Copy link

Intro

Hi!

I'm a graduate student using MuJoCo for robotics research.

My setup

MuJoCo 3.2.5, Python 3.12.7, arm64, macOS 15.1.1

What's happening? What did you expect?

When using the passive viewer under mjpython, if there's a variable named model in the global scope, this variable will get overwritten with the MjModel passed to the passive viewer. After digging a little bit, I suspect that it has to do with this line on mjpython.mm:

model, data, handle_return, key_callback, show_left_ui, show_right_ui = task

After launching the passive viewer, any variables with those names will be redefined.

Steps for reproduction

Run the provided code under mjpython. On my machine, the it prints the following

Before launching passive viewer: <__main__.Model object at 0x102e2cef0> (var.value='model')
Before launching passive viewer: <__main__.Model object at 0x102e2cf20> (var.value='data')
Before launching passive viewer: <__main__.Model object at 0x102e2cf50> (var.value='handle_return')
Before launching passive viewer: <__main__.Model object at 0x102e2cfb0> (var.value='key_callback')
Before launching passive viewer: <__main__.Model object at 0x102e2d040> (var.value='show_left_ui')
Before launching passive viewer: <__main__.Model object at 0x102e2d070> (var.value='show_right_ui')

(some mjpython messages...)

After launching passive viewer: <mujoco._structs.MjModel object at 0x1049a4170> (hasattr(var, 'value')=False)
After launching passive viewer: <mujoco._structs.MjData object at 0x103b48470> (hasattr(var, 'value')=False)
After launching passive viewer: <queue.Queue object at 0x103b6cbf0> (hasattr(var, 'value')=False)
After launching passive viewer: None (hasattr(var, 'value')=False)
After launching passive viewer: True (hasattr(var, 'value')=False)
After launching passive viewer: True (hasattr(var, 'value')=False)

The second set of print statements should be unchanged.

Minimal model for reproduction

No response

Code required for reproduction

import mujoco as mj
import mujoco.viewer as mjv


class Model:
    def __init__(self, value):
        self.value = value


model = Model("model")
data = Model("data")
handle_return = Model("handle_return")
key_callback = Model("key_callback")
show_left_ui = Model("show_left_ui")
show_right_ui = Model("show_right_ui")

xml = """
<mujoco>
  <worldbody>
    <geom name="red_box" type="box" size=".2 .2 .2" rgba="1 0 0 1"/>
    <geom name="green_sphere" pos=".2 .2 .2" size=".1" rgba="0 1 0 1"/>
  </worldbody>
</mujoco>
"""
m = mj.MjModel.from_xml_string(xml)
d = mj.MjData(m)

for var in [model, data, handle_return, key_callback, show_left_ui, show_right_ui]:
    print(f"Before launching passive viewer: {var} ({var.value=})")
viewer = mjv.launch_passive(m, d)
for var in [model, data, handle_return, key_callback, show_left_ui, show_right_ui]:
    print(f"After launching passive viewer: {var} ({hasattr(var, 'value')=})")

Confirmations

@jaraujo98 jaraujo98 added the bug Something isn't working label Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants