10000 render new marker offsets, add option to visualize marker error by charles-zhng · Pull Request #63 · talmolab/stac-mjx · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

render new marker offsets, add option to visualize marker error #63

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

Merged
merged 6 commits into from
Oct 6, 2024

Conversation

charles-zhng
Copy link
Collaborator
@charles-zhng charles-zhng commented Sep 24, 2024

marker positions werent properly rendered before (still have not confirmed why), but a working solution is to create new marker sites instead of updating the relative positions via learned offsets as we were doing previously.

Also added the option in viz_stac to render a red line showing the error btwn markers and keypoints.

Summary by CodeRabbit

  • New Features

    • Enhanced performance of processing speed in visualizations.
    • Added optional parameter for rendering to control marker error visibility.
    • Updated video content in the demo notebook.
    • Improved rendering capabilities with new visual options, including shadows and reflections.
  • Bug Fixes

    • Improved handling of offsets within the rendering process.
  • Documentation

    • Code formatting adjustments for better readability and clarity in function parameters.

Copy link
Contributor
coderabbitai bot commented Sep 24, 2024

Walkthrough

The pull request introduces several modifications across multiple files, focusing on performance enhancements, code readability improvements, and adjustments to rendering and optimization processes. Key changes include an increase in processing speed in a Jupyter notebook, the addition of a new return value in a function, and updates to rendering methods to incorporate new parameters and improve visual output.

Changes

File Change Summary
demos/viz_usage.ipynb Performance improvements noted with increased processing speed; HTML structure for video updated; function call parameters reformatted for readability.
stac_mjx/compute_stac.py offset_optimization function modified to return an additional value, offset_opt_param, expanding the output information.
stac_mjx/controller.py Adjustments to rendering methods, including color transparency changes, new optional parameters, and updates to forward kinematics function calls.
stac_mjx/stac.py Enhancements to the Stac class with RGBA value adjustments, return value changes in offset_optimization, new parameters in render, and scene option adjustments.
stac_mjx/viz.py viz_stac function updated to include an additional parameter, show_marker_error, and changes in data structure access for keypoint names.

Possibly related PRs

  • add demo_viz.p #45: The changes in demos/viz_usage.ipynb include modifications to video playback settings and data paths, which are relevant to the main PR's updates to the same notebook file, indicating a direct connection in terms of content adjustments.
  • Remove globals #43: This PR involves significant modifications to the stac_mjx/controller.py file, which includes changes to rendering and optimization processes that may relate to the overall functionality being enhanced in the main PR, particularly in how visualizations are handled.
  • basic python api #31: The updates in stac_mjx/main.py regarding the run_stac function and its parameters may indirectly relate to the changes in the main PR, as they both involve enhancements to the STAC functionality and user interaction with the API.

Suggested reviewers

  • talmo

🐰 In the code, we hop and play,
With faster speeds, we leap away!
A sprinkle of change, a dash of flair,
New features bloom, with love and care.
Let's render bright, and optimize,
In our coding burrow, the magic lies! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
codecov bot commented Sep 24, 2024

Codecov Report

Attention: Patch coverage is 0% with 22 lines in your changes missing coverage. Please review.

Project coverage is 42.75%. Comparing base (57174a8) to head (d4f8f7a).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
stac_mjx/stac.py 0.00% 21 Missing ⚠️
stac_mjx/compute_stac.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #63      +/-   ##
==========================================
- Coverage   43.55%   42.75%   -0.80%     
==========================================
  Files           9        9              
  Lines         535      545      +10     
==========================================
  Hits          233      233              
- Misses        302      312      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (4)
stac_mjx/viz.py (1)

21-21: LGTM! Consider adding a type hint for consistency.

The addition of the show_marker_error parameter aligns well with the PR objective to add an option for visualizing marker error. The default value of False ensures backward compatibility.

For consistency with other parameters, consider adding a type hint:

-    show_marker_error=False,
+    show_marker_error: bool = False,
demos/viz_usage.ipynb (1)

108-114: Consider removing empty code cells.

Three empty code cells have been added at the end of the notebook. While these might be intended as placeholders for future code, they currently don't serve any purpose and may unnecessarily clutter the notebook. Consider removing these empty cells if you don't have immediate plans to use them.

stac_mjx/controller.py (2)

262-262: Add tests for compute_stac.offset_optimization

The line where self._offsets is updated is critical, but it's not covered by tests. It's important to ensure that this function behaves as expected, especially since it affects the offsets used throughout the model.

Would you like assistance in creating unit tests for this function or should we open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 262-262: stac_mjx/controller.py#L262
Added line #L262 was not covered by tests


530-543: Visualize marker errors with tendons when show_marker_error is True

The conditional block adds tendons between the keypoint sites and the new marker sites to visualize the errors. However, this new functionality is not covered by tests.

Would you like help in writing tests to ensure this visualization feature works correctly or should we open a GitHub issue to track this task?

Tools
Ruff

533-533: Local variable rgba is assigned to but never used

Remove assignment to unused variable rgba

(F841)

GitHub Check: codecov/patch

[warning] 530-531: stac_mjx/controller.py#L530-L531
Added lines #L530 - L531 were not covered by tests


[warning] 533-534: stac_mjx/controller.py#L533-L534
Added lines #L533 - L534 were not covered by tests


[warning] 541-542: stac_mjx/controller.py#L541-L542
Added lines #L541 - L542 were not covered by tests

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7c8b5a5 and b6d8a69.

Files selected for processing (4)
  • demos/viz_usage.ipynb (3 hunks)
  • stac_mjx/compute_stac.py (1 hunks)
  • stac_mjx/controller.py (7 hunks)
  • stac_mjx/viz.py (3 hunks)
Additional context used
Gitleaks
demos/viz_usage.ipynb

69-69: Identified a pattern that may indicate AWS credentials, risking unauthorized cloud resource access and data breaches on AWS platforms.

(aws-access-token)

GitHub Check: codecov/patch
stac_mjx/compute_stac.py

[warning] 175-175: stac_mjx/compute_stac.py#L175
Added line #L175 was not covered by tests

stac_mjx/controller.py

[warning] 262-262: stac_mjx/controller.py#L262
Added line #L262 was not covered by tests


[warning] 393-393: stac_mjx/controller.py#L393
Added line #L393 was not covered by tests


[warning] 515-515: stac_mjx/controller.py#L515
Added line #L515 was not covered by tests


[warning] 518-519: stac_mjx/controller.py#L518-L519
Added lines #L518 - L519 were not covered by tests


[warning] 530-531: stac_mjx/controller.py#L530-L531
Added lines #L530 - L531 were not covered by tests


[warning] 533-534: stac_mjx/controller.py#L533-L534
Added lines #L533 - L534 were not covered by tests


[warning] 541-542: stac_mjx/controller.py#L541-L542
Added lines #L541 - L542 were not covered by tests


[warning] 544-545: stac_mjx/controller.py#L544-L545
Added lines #L544 - L545 were not covered by tests


[warning] 548-548: stac_mjx/controller.py#L548
Added line #L548 was not covered by tests


[warning] 553-553: stac_mjx/controller.py#L553
Added line #L553 was not covered by tests


[warning] 555-555: stac_mjx/controller.py#L555
Added line #L555 was not covered by tests


[warning] 557-560: stac_mjx/controller.py#L557-L560
Added lines #L557 - L560 were not covered by tests


[warning] 582-582: stac_mjx/controller.py#L582
Added line #L582 was not covered by tests

stac_mjx/viz.py

[warning] 49-49: stac_mjx/viz.py#L49
Added line #L49 was not covered by tests

Ruff
stac_mjx/controller.py

533-533: Local variable rgba is assigned to but never used

Remove assignment to unused variable rgba

(F841)

Additional comments not posted (9)
stac_mjx/viz.py (1)

65-65: LGTM! Verify render method implementation.

The show_marker_error parameter is correctly passed to the stac.render() method, implementing the new feature as described in the PR objectives.

To ensure complete implementation:

  1. Verify that the render method in the STAC class has been updated to handle this new parameter.
  2. Check if appropriate tests have been added for this new functionality.

Run the following script to locate the STAC class definition and its render method:

#!/bin/bash
# Description: Locate STAC class and render method

# Find the file containing the STAC class definition
stac_file=$(rg -l 'class STAC' --type python)

# If found, search for the render method within the STAC class
if [ -n "$stac_file" ]; then
    echo "STAC class found in: $stac_file"
    echo "Render method definition:"
    ast-grep --lang python --pattern $'class STAC {
  $$$
  render($$$) {
    $$$
  }
  $$$
}' "$stac_file"
else
    echo "STAC class not found"
fi
stac_mjx/compute_stac.py (1)

175-175: ⚠️ Potential issue

Approve changes and suggest improvements

The addition of offset_opt_param to the return statement is a good improvement. It aligns with the PR objectives of rendering new marker offsets and potentially visualizing marker error.

However, there are a few points to consider:

  1. The function's docstring should be updated to reflect the new return value.
  2. Unit tests should be added or updated to cover this new return value, as indicated by the static analysis tool.

To address these points, please:

  1. Update the docstring to include offset_opt_param in the Returns section.
  2. Add or update unit tests to cover the new return value.

To ensure the new return value is properly utilized, please run the following script:

This will help us confirm that the new return value is being used appropriately throughout the codebase.

Verification successful

Verified usage of offset_opt_param

The new return value offset_opt_param is properly utilized in the codebase:

  • In stac_mjx/controller.py, offset_opt_param is assigned to self._offsets.
  • In stac_mjx/compute_stac.py, offset_opt_param is assigned from res.params.

No issues found with the current usage.

However, please ensure that:

  1. The function’s docstring in stac_mjx/compute_stac.py is updated to include offset_opt_param in the Returns section.
  2. Unit tests are added or updated to cover the new return value.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of offset_opt_param in other parts of the codebase

# Search for function calls to offset_optimization
echo "Searching for offset_optimization function calls:"
rg --type python 'offset_optimization\(' -A 5

# Search for variable assignments that might capture the new return value
echo "Searching for potential assignments of the new return value:"
rg --type python 'offset_optimization\(.*\)' -A 2

Length of output: 401


Script:

#!/bin/bash
# Description: Verify the usage of offset_opt_param in other parts of the codebase

# Search for function calls to offset_optimization in Python files
echo "Searching for offset_optimization function calls in Python files:"
rg --glob "*.py" 'offset_optimization\(' -A 5

# Search for variable assignments that capture the new return value in Python files
echo "Searching for potential assignments of the new return value in Python files:"
rg --glob "*.py" 'offset_opt_param\s*=' -A 2

Length of output: 1180

Tools
GitHub Check: codecov/patch

[warning] 175-175: stac_mjx/compute_stac.py#L175
Added line #L175 was not covered by tests

demos/viz_usage.ipynb (2)

88-95: Improved readability with multi-line function call.

The reformatting of the stac_mjx.viz_stac function call enhances code readability by clearly presenting each parameter on a separate line. This is a good practice, especially for functions with multiple parameters, as it makes the code easier to read and maintain.


69-69: False positive: No AWS credentials in encoded video data.

A static analysis tool flagged this line as potentially containing AWS credentials. However, this is a false positive. The flagged content is part of a base64 encoded video source in the HTML output of the notebook, not actual code. It does not contain any real AWS credentials or sensitive information.

Tools
Gitleaks

69-69: Identified a pattern that may indicate AWS credentials, risking unauthorized cloud resource access and data breaches on AWS platforms.

(aws-access-token)

stac_mjx/controller.py (5)

146-146: Change sphere site opacity for better visualization

The rgba value for the sphere site has been changed to "0 0 0 0.8", making it slightly transparent. This enhancement can improve the visualization by allowing other objects behind the sphere to be partially visible.


393-395: Confirm consistency when retrieving offsets in _package_data

Offsets are now retrieved directly from self._offsets. Ensure that self._offsets is synchronized with any updates to the model's site positions to prevent discrepancies.

Tools
GitHub Check: codecov/patch

[warning] 393-393: stac_mjx/controller.py#L393
Added line #L393 was not covered by tests


473-473: Introduce show_marker_error parameter in render method

The new optional parameter show_marker_error: bool = False allows users to visualize the error between markers and keypoints by rendering a red line. This is a valuable feature for debugging and improving model accuracy.


513-528: Add new marker sites for offset positions

The code adds new marker sites with names suffixed by _new, representing the new offset positions. This is necessary for visualizing the updated marker positions.

Tools
GitHub Check: codecov/patch

[warning] 515-515: stac_mjx/controller.py#L515
Added line #L515 was not covered by tests


[warning] 518-519: stac_mjx/controller.py#L518-L519
Added lines #L518 - L519 were not covered by tests


582-582: Verify the use of mj_fwdPosition in rendering

The call to mujoco.mj_fwdPosition updates the model's positions without computing velocities or accelerations. Confirm that this is sufficient for rendering purposes and that dynamic simulation is not required here.

Tools
GitHub Check: codecov/patch

[warning] 582-582: stac_mjx/controller.py#L582
Added line #L582 was not covered by tests

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
demos/viz_usage.ipynb (1)

108-114: Consider removing the empty code cell.

An empty code cell has been added at the end of the notebook. If this cell is not intended for immediate use, consider removing it to keep the notebook concise and focused.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b6d8a69 and 6023976.

Files ignored due to path filters (1)
  • demos/demo_viz.p is excluded by !**/*.p
Files selected for processing (1)
  • demos/viz_usage.ipynb (3 hunks)
Additional context used
Gitleaks
demos/viz_usage.ipynb

69-69: Identified a pattern that may indicate AWS credentials, risking unauthorized cloud resource access and data breaches on AWS platforms.

(aws-access-token)

Additional comments not posted (4)
demos/viz_usage.ipynb (4)

62-62: Significant performance improvement observed.

The progress indicator shows a substantial increase in processing speed from 4.36it/s to 18.97it/s. This aligns with the mentioned performance improvements in the summary.


69-69: Updated video content detected.

The base64 encoded video source has been changed, which likely represents updated video content being displayed in the notebook.

Tools
Gitleaks

69-69: Identified a pattern that may indicate AWS credentials, risking unauthorized cloud resource access and data breaches on AWS platforms.

(aws-access-token)


83-95: Improved code formatting for better readability.

The stac_mjx.viz_stac function call has been reformatted with each parameter on a separate line. This change enhances code readability without altering the functionality.


69-69: Potential security concern: Verify the content of the base64 encoded string.

The static analysis tool has flagged this line as potentially containing AWS credentials. While this is likely a false positive due to the nature of base64 encoded video data, it's crucial to verify that no sensitive information is inadvertently included in the encoded string.

To ensure no sensitive data is present, you can decode a small portion of the base64 string and check its contents. Here's a script to do that:

This script will output the hexdump of the first part of the decoded base64 string. Verify that it starts with typical MP4 file headers and doesn't contain any readable text that could be sensitive information.

Tools
Gitleaks

69-69: Identified a pattern that may indicate AWS credentials, risking unauthorized cloud resource access and data breaches on AWS platforms.

(aws-access-token)

Copy link
Contributor
@jf514 jf514 left a comment

Choose a reason for hiding this comment

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

Overall LGTM, but some minor comments.

@@ -538,10 +571,11 @@ def render(
# render while stepping using mujoco
with imageio.get_writer(save_path, fps=self.cfg.model.RENDER_FPS) as video:
for qpos, kps in tqdm(zip(qposes, kp_data)):
# Set keypoints
# Set keypoints--they're in cartesian space, but since they're attached to the worldbody they're the same as offsets
Copy link
Contributor

Choose a reason for hiding this comment

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

Eh, what do you mean by "the same as offsets" in this context?

Copy link
Collaborator Author
@charles-zhng charles-zhng Oct 2, 2024

Choose a reason for hiding this comment

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

The keypoints represented in global cartesian space can be considered offsets relative to the worldbody. I noted this because setting site positions is always relative to the parent body, so one might get confused about why this works with the keypoints' global frame representation. (The keypoint sites are created with the worldbody as the parent)

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be more clear to say "their the same as global (world) coordinates"? Offsets seems relative to me.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
stac_mjx/viz.py (1)

65-65: LGTM: Implementation change is correct, consider adding documentation

The new show_marker_error parameter is correctly passed to the stac.render method. This change is minimal and aligns with the function's role as a wrapper.

Consider updating the function's docstring to include information about the new show_marker_error parameter and its purpose.

stac_mjx/compute_stac.py (1)

179-179: Approve the change and update documentation

The modification to return offset_opt_param is a good addition as it provides direct access to the optimized offset parameters. This change aligns with the PR objectives of rendering new marker offsets.

To maintain code clarity and prevent potential issues:

  1. Update the function's docstring to reflect the new return value.
  2. Ensure that any code calling this function is updated to handle the new three-element tuple return value.

Example docstring update:

    Returns:
        Tuple[mjx.Model, mjx.Data, jp.ndarray]: An updated MJX Model, MJX Data, and the optimized offset parameters
stac_mjx/stac.py (1)

146-146: Adjust RGBA Transparency Value

The RGBA value for the site has been changed to "0 0 0 0.8", which adjusts the alpha transparency to 0.8. Ensure that this level of transparency achieves the desired visual effect and is consistent with other visual elements in the model.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 21d7e3c and d4f8f7a.

📒 Files selected for processing (3)
  • stac_mjx/compute_stac.py (1 hunks)
  • stac_mjx/stac.py (7 hunks)
  • stac_mjx/viz.py (2 hunks)
🔇 Additional comments (10)
stac_mjx/viz.py (2)

21-21: LGTM: New parameter aligns with PR objectives

The addition of the show_marker_error parameter with a default value of False is well-implemented. It provides the new functionality described in the PR objectives while maintaining backward compatibility.


Line range hint 49-49: Verification: kp_names usage is consistent

Addressing a past review comment: The current code uses d["kp_names"], which is consistent with the usage in other parts of the codebase. The previously mentioned change to d["KP_NAMES"] is not present in this version, resolving the potential inconsistency.

To ensure consistency across the codebase, run the following script:

This will help confirm that kp_names is used consistently throughout the project.

✅ Verification successful

Verification: kp_names usage is consistent

After reviewing the usage of kp_names across the codebase, it is confirmed that kp_names is used consistently in stac_mjx/viz.py and other relevant files. The earlier concern about changing d["kp_names"] to d["KP_NAMES"] does not apply, as all references use kp_names uniformly.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent usage of 'kp_names' across the codebase

# Search for 'kp_names' in Python files
rg -i 'kp_names' --glob '*.py'

Length of output: 4293

stac_mjx/compute_stac.py (1)

Line range hint 1-279: Verify implementation of marker error visualization

The PR objectives mention adding an option to visualize marker error. However, there are no visible changes in this file related to this feature.

Please confirm if the visualization feature is implemented in another file or if it's missing from this PR. If it's in another file, consider updating the PR description to clarify where this feature is implemented.

To verify the implementation, you can run the following script:

This script will help identify any new or modified visualization-related code in other files of the repository.

stac_mjx/stac.py (7)

485-485: Update Docstring to Include show_marker_error Parameter

The docstring for the render method now includes the new parameter show_marker_error, accurately describing its purpose and default value. This ensures that the method's documentation is up-to-date.


528-539: Implement Conditional Tendons for Error Visualization

When show_marker_error is True, tendons are added to visualize the error between markers and keypoints:

if show_marker_error:
    for key, v in self.cfg.model.KEYPOINT_MODEL_PAIRS.items():
        tendon = self._root.tendon.add(
            "spatial",
            name=key + "-" + v,
            width="0.001",
            rgba="255 0 0 1",  # Red
            limited=False,
        )
        tendon.add("site", site=key + "_kp")
        tendon.add("site", site=key + "_new")

Verify that the tendons are correctly defined and that they render appropriately without introducing unintended side effects.


471-471: Update Method Signature to Include show_marker_error

The render method now includes a new parameter:

def render(..., show_marker_error: bool = False):

Ensure that all calls to render in the codebase are updated accordingly, and the default behavior remains unaffected for existing usages.

Run the following script to identify all calls to render:

#!/bin/bash
# Description: Find all calls to the 'render' method outside its definition.

# Expected: Review each call to ensure it handles the new parameter if necessary.
rg --type py --pcre2 '(?<!def )render\(' stac_mjx/

511-526: Add New Marker Sites for Offsets in Rendering

The code adds new marker sites for offsets to visualize the adjusted marker positions:

for (key, v), pos in zip(self.cfg.model.KEYPOINT_MODEL_PAIRS.items(), offsets.reshape((-1, 3))):
    parent = self._root.find("body", v)
    parent.add(
        "site",
        name=key + "_new",
        type="sphere",
        size=[0.005],
        rgba="0 0 0 1",
        pos=pos,
        group=2,
    )

Ensure that these new sites are correctly integrated into the model and that their names do not conflict with existing site names.

Run the following script to check for naming conflicts with site names:

#!/bin/bash
# Description: Check for duplicate site names in the model XML files.

# Expected: No duplicate site names should be found.
rg --type xml '<site name="' stac_mjx/ | gawk -F'"' '{print $2}' | sort | uniq -d

578-578: Update Function Call to mujoco.mj_fwdPosition

The function call has been changed from mujoco.mj_forward to mujoco.mj_fwdPosition:

mujoco.mj_fwdPosition(render_mj_model, mj_data)

This computes only the position-related quantities, which can be more efficient when full dynamics are not required. Confirm that no downstream code relies on computations performed by mj_forward that are not covered by mj_fwdPosition.

Run the following script to find any remaining uses of mujoco.mj_forward:

#!/bin/bash
# Description: Find all occurrences of 'mujoco.mj_forward' in the codebase.

# Expected: Ensure that 'mujoco.mj_forward' is only used where full dynamics are necessary.
rg --type py 'mujoco\.mj_forward' stac_mjx/

389-393: ⚠️ Potential issue

Ensure Consistent Assignment of offsets in _package_data

In the _package_data method, offsets is assigned differently based on the batched flag:

if batched:
    offsets = get_batch_offsets(mjx_model, self._body_site_idxs)[0]
else:
    offsets = self._offsets

Verify that self._offsets is correctly initialized before being used here and that the batched and non-batched cases handle offsets consistently.

Run the following script to check initialization and usage of self._offsets:


261-261: ⚠️ Potential issue

Verify Usage of self._offsets After Assignment

You've updated the assignment to include self._offsets:

mjx_model, mjx_data, self._offsets = compute_stac.offset_optimization(...)

Ensure that self._offsets is properly utilized throughout the class after this change, especially in methods that depend on the updated offsets.

Run the following script to verify all usages of self._offsets:

✅ Verification successful

Usage of self._offsets After Assignment Verified

All references to self._offsets in stac_mjx/stac.py have been confirmed to utilize the updated offsets appropriately.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all occurrences of 'self._offsets' within the 'stac_mjx' directory.

# Expected: All references to 'self._offsets' reflect the updated usage.
rg --type py 'self\._offsets' stac_mjx/

Length of output: 442

@charles-zhng
Copy link
Collaborator Author

Still looking into the KP_NAMES vs kp_names thing

Copy link
Contributor
@jf514 jf514 left a comment

Choose a reason for hiding this comment

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

One last minor comment to address, but overall LGTM!

@charles-zhng
Copy link
Collaborator Author

Still looking into the KP_NAMES vs kp_names thing

seems like kp_names is correct. merging now

@charles-zhng charles-zhng merged commit 527c0ee into main Oct 6, 2024
5 checks passed
@jf514 jf514 deleted the render-offsets-pr branch October 25, 2024 19:47
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
0