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

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

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

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.
  • 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/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 both PRs involve modifications to the demos/viz_usage.ipynb file, specifically related to video playback settings and performance metrics, indicating a direct connection in terms of functionality and content adjustments.

🐰 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! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

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

📒 Files selected for processing (1)
  • stac_mjx/controller.py (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • stac_mjx/controller.py

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 23 lines in your changes missing coverage. Please review.

Project coverage is 41.77%. Comparing base (7c8b5a5) to head (21d7e3c).

Files with missing lines Patch % Lines
stac_mjx/controller.py 0.00% 21 Missing ⚠️
stac_mjx/compute_stac.py 0.00% 1 Missing ⚠️
stac_mjx/viz.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #63      +/-   ##
==========================================
- Coverage   42.56%   41.77%   -0.79%     
==========================================
  Files           9        9              
  Lines         531      541      +10     
==========================================
  Hits          226      226              
- Misses        305      315      +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

stac_mjx/viz.py Show resolved Hide resolved
stac_mjx/controller.py Outdated Show resolved Hide resolved
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)

stac_mjx/controller.py Outdated Show resolved Hide resolved
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.

@@ -45,7 +46,7 @@ def viz_stac(
d = pickle.load(file)
qposes = np.array(d["qpos"])
kp_data = np.array(d["kp_data"])
kp_names = d["kp_names"]
kp_names = d["KP_NAMES"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this broken before?

@@ -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?

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