Fix joint ordering in MjSpec.to_xml() for attached models - #3402
Open
anishesg wants to merge 1 commit into
Open
Conversation
The XML writer in `mjXWriter::Body()` now sorts joints and bodies by their compiled id before writing them to the output XML. Previously, joints and bodies were written in the order they appeared in the internal vectors, which could differ from the compiled model's ordering after attach operations. Signed-off-by: anish <anishesg@users.noreply.github.com>
2 tasks
Collaborator
|
Hi, thank you for your contribution! I think the bug should not be addresses only at compile time, but during attach. Could you make it such that the joints are ordering at the end of the mjs_attach function? That probably requires calling mjCModel::ProcessList() at the end of mjCModel::operator+=()? Or if you understand why the ordering mismatch happens, you can try to prevent it, but it may be difficult. Also, when you do that we probably need a test in user_api_test. Thanks! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The XML writer in
mjXWriter::Body()now sorts joints and bodies by their compiled id before writing them to the output XML. Previously, joints and bodies were written in the order they appeared in the internal vectors, which could differ from the compiled model's ordering after attach operations.When a modular MJCF model uses
<attach>to compose sub-models, the internal ordering of joints inbody->jointsmay not match the compiled model's joint ordering (stored injoint->id). This causedMjSpec.to_xml()to export XML that would compile with different joint indices, violating the documented guarantee that exported XML compiles to an equivalent model.The fix sorts joints and bodies by their compiled id values in
xml_native_writer.ccbefore serializing them to XML. This ensures the exported XML will compile with the same joint and body ordering as the original model, preserving qpos/qvel indices and state vector layout.Fixes #3401