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 MjSpec introspection with visual.rgba, visual.headlight, and visual.global_. #2291

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

AaronYoung5
Copy link

Fixes issue mentioned here in #2289.

Copy link

google-cla bot commented Dec 14, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Collaborator

@yuvaltassa yuvaltassa left a comment

Choose a reason for hiding this comment

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

What about the other members of mjVisual (map, scale, quality)?

Can you please do the CLA thing?

@yuvaltassa
Copy link
Collaborator

Also, thank you! 😊 🙏

@AaronYoung5
Copy link
Author

rgba/headlight have arrays (which map/scale/quality don't), so I think those types need to be explicitly defined in the generated code which calling _binding_code on rgba/headlight does.

CLA is done. Thanks!

@yuvaltassa
Copy link
Collaborator

Got it, makes sense.

Question: are you sure we need the underscore suffix? I.e. did you try not adding it and got an actual error? Sometimes the syntax highlighting will make you think you need it but global is actually OK.

@AaronYoung5
Copy link
Author

AaronYoung5 commented Dec 15, 2024

Yeah, I get the following error.

$ python -c 'import mujoco; print(mujoco.MjSpec().visual.global)'
  File "<string>", line 1
    import mujoco; print(mujoco.MjSpec().visual.global)
                                                ^^^^^^
SyntaxError: invalid syntax

EDIT: after looking into it a bit, seems like all python keywords (i.e. help("keywords")) are not allowed to be used as identifiers. And PEP-8 says to append an underscore to the name if it collides.

Also, thanks for the quick responses!!

@quagla
Copy link
Contributor

quagla commented Dec 16, 2024

Great, thanks for doing this! Is there anything that prevents you to put the code inside _value_binding_code like I did for e.g. mjStatistic? I don't think the top-level function of the binding generation makes it easy to maintain the code. That would also make it easier to generalize it to arrays.

@AaronYoung5
Copy link
Author

Thanks for taking the time!

I don't think _value_binding_code has access to the subfields, which are the array types that need to be defined explicitly, right? Like since only the ValueType is passed, it can't iteratively define the arrays. The latest commit might be more maintainable, as you suggested

@yuvaltassa
Copy link
Collaborator

Can you remove the trailing spaces please?

Lines 986, 988 and 989 in specs.cc

@AaronYoung5
Copy link
Author

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants