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

Integrate KRM with RearrangeSim #1927

Merged
merged 19 commits into from
May 2, 2024
Merged

Integrate KRM with RearrangeSim #1927

merged 19 commits into from
May 2, 2024

Conversation

aclegg3
Copy link
Contributor

@aclegg3 aclegg3 commented Apr 29, 2024

Motivation and Context

This PR integrates the KinematicRelationshipManager from #1909 into the RearrangeSim for kinematic_mode.

When kinematic_mode is set:

  • KRM is created and relationships initialized from the RearrangeEpisode
  • KRM relationships are applied within the update loop
  • RearrangeGraspManager severs kinematic relationships when a grasp is triggered.

Also adds some typing and docstrings style refactors.
Also updates the test rearrange episode datasets across the stack to "v2" following facebookresearch/habitat-sim#2381

TODO:

  • New relationships need to be established when a grasp is released and the object is snapped or placed onto a new surface. This is not done here, because the current logic does not handle snapping objects onto a surface in kinematic mode. Only the dynamic modality is implemented fully.

How Has This Been Tested

Not explicitly tested yet. Existing integration tests for RearrangeSim only.

Types of changes

  • [Development] A pull request that add new features to the habitat-lab task and environment codebase. Development Pull Requests must be small (less that 500 lines of code change), have unit testing, very extensive documentation and examples. These are typically new tasks, environments, sensors, etc... The review process for these Pull Request is longer because these changes will be maintained by our core team of developers, so make sure your changes are easy to understand!

Checklist

  • My code follows the code style of this project.
  • I have updated the documentation if required.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes if required.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Apr 29, 2024
@aclegg3
Copy link
Contributor Author

aclegg3 commented Apr 30, 2024

CI was failing because the rearrange v1 dataset was mapping object placements to Receptacle.name instead of Receptacle.unique_name.
I re-processed this mapping and uploaded as v2. CI is currently testing against the updated version from facebookresearch/habitat-sim#2381

self._sim.kinematic_relationship_manager.relationship_graph.remove_obj_relations(
snap_obj_id, parents_only=True
)
# update root parent transforms so new parent state is registered
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this? I understand that the line above removes the relationship with the parent. Won't the root parent transforms stay the same when we pick an object? Why do we need to store them in prev_root_obj_state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we disconnect an object from its parents, the object becomes a root parent. We need to cache the new root parent's global transform so it can be applied to update any children.

This is the essential logic which allows, for example, picking up a tray with cups on it and moving the cups along with the tray. The tray is a new root parent and its transform must be tracked.

@@ -109,6 +112,7 @@ def __init__(self, config: "DictConfig"):
self.viz_ids: Dict[Any, Any] = defaultdict(lambda: None)
self._handle_to_object_id: Dict[str, int] = {}
self._markers: Dict[str, MarkerInfo] = {}
self._targets: Dict[str, mn.Matrix4] = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

What are those _targets? How are they relevant to KRM?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a clean-up refactor, not related to KRM. IMO, self. variables should all be declared in init(), even if they are initialized in an internal function. This allows any comments and typing to be co-located. More straightforward paradigm than trying to hunt around for the first declaration of the variable in some internal function.

)
if done:
break
for _ in range(2):
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't removing the with env cause segfaults like in the llm codebase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a test file, so it won't get pulled in elsewhere. I also added an explicit close() afterward. I don't think this change really does anything, but I thought it was more clear what was happening.

Copy link
Contributor

@xavierpuigf xavierpuigf left a comment

Choose a reason for hiding this comment

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

Looks good, thanks! Could you comment on how the v2 dataset and targets variable relate to the KRM?

@aclegg3
Copy link
Contributor Author

aclegg3 commented May 2, 2024

Looks good, thanks! Could you comment on how the v2 dataset and targets variable relate to the KRM?

targets variable: I answered that here. TL;DR: unrelated clean-up refactor

v2 dataset: details on the changes are here. TL;DR: the v1 dataset did not comply to the required spec for RearrangeEpisode.name_to_receptacle which is expected by the KRM implementation to initialize the parent->child relationships at the start of the episode.

Copy link
Contributor

@0mdc 0mdc left a comment

Choose a reason for hiding this comment

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

LGTM!

@aclegg3 aclegg3 merged commit 3480e44 into main May 2, 2024
3 checks passed
@aclegg3 aclegg3 deleted the alex-04_29-krm_integration branch May 2, 2024 21:50
dannymcy pushed a commit to dannymcy/habitat-lab that referenced this pull request Jun 26, 2024
* integrate KRM with RearrangeSim

* replace all references to reaplica_cad/rearrange/v1/ datasets with v2/ paths instead
dannymcy pushed a commit to dannymcy/habitat-lab that referenced this pull request Jul 8, 2024
* integrate KRM with RearrangeSim

* replace all references to reaplica_cad/rearrange/v1/ datasets with v2/ paths instead
dannymcy pushed a commit to dannymcy/habitat-lab that referenced this pull request Jul 8, 2024
* integrate KRM with RearrangeSim

* replace all references to reaplica_cad/rearrange/v1/ datasets with v2/ paths instead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants