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

Unit test for HITL tool and/or SandboxDriver #1654

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

Conversation

rpartsey
Copy link
Collaborator

@rpartsey rpartsey commented Oct 27, 2023

Motivation and Context

Initial version of the SandboxDriver unit test.

Known issues:

  • sometimes sim generated keyframe has slightly different agents positions even though we force them to be fixed by adding "fixed_agent_starting_pose" config argument (for the context if "fixed_agent_starting_pose" is in config we fix numpy and sim.pathfinder seeds). probably because float numbers representation? This causes test to fail sometimes.

How Has This Been Tested

Running pytest examples/siro_sandbox/test_sandbox_app.py locally (requires hab3_bench_assets assets).

Types of changes

  • Development Adding test.

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 Oct 27, 2023
Comment on lines 22 to 24
@patch("utils.gui.replay_gui_app_renderer.ReplayRenderer", spec=True)
@patch("utils.gui.replay_gui_app_renderer.ImageFramebufferDrawer", spec=True)
@patch("utils.gui.replay_gui_app_renderer.TextDrawer", spec=True)
Copy link
Collaborator Author

@rpartsey rpartsey Oct 27, 2023

Choose a reason for hiding this comment

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

Copy link
Contributor

@eundersander eundersander left a comment

Choose a reason for hiding this comment

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

Good progress! See comments below.

@@ -108,6 +108,11 @@ def __init__(
)
self._count_obj_collisions = self._config.count_obj_collisions

self._fixed_starting_position = (
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to get a review from someone more familiar with rearrange_task.py on the changes in this file.

args=default_args,
config=default_config,
gui_input=gui_input,
line_render=app_renderer._replay_renderer.debug_line_render(0),
Copy link
Contributor

Choose a reason for hiding this comment

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

Would a solution like I did here perhaps be simpler and more elegant, if our goal is only to test SandboxDriver?

Copy link
Collaborator Author

@rpartsey rpartsey Oct 30, 2023

Choose a reason for hiding this comment

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

Agree, thanks for the suggestion. Advantage of DummyClass over the patching is that this way testing SandboxDriver doesn't require importing and instantiating ReplayRenderer.

Updated code.

from habitat_baselines.config.default import get_config as get_baselines_config


@pytest.mark.skipif(
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious if we can run this as part of CI. I started a slack thread here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As Andrew replied the Slack tread this assets are actually already being downloaded in the multi-agent trainer CI.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. Can you link to a successful CI run of this file here as a reply? It's not clear to me at a glance if this file is getting included in the tests as part of CI install_and_test_ubuntu.

with open("examples/siro_sandbox/test_sandbox_app_keyframe.txt", "r") as f:
expected_keyframe = f.read()

assert post_sim_update_dict["keyframes"][0] == expected_keyframe
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you provide instructions here (as a code comment) for how to update examples/siro_sandbox/test_sandbox_app_keyframe.txt if/when this test breaks due to desired changes to the app behavior?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

with open("examples/siro_sandbox/test_sandbox_app_keyframe.txt", "r") as f:
expected_keyframe = f.read()

assert post_sim_update_dict["keyframes"][0] == expected_keyframe
Copy link
Contributor

Choose a reason for hiding this comment

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

In addition to this equality check on the entire keyframe contents (which I like), can you also sanity-check the contents of the keyframe? There should be at least one keyframe, one load, one creation, and one stateUpdate, and the comment for that set of checks should be "the first keyframe should create and pose at least one render asset instance".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@eundersander eundersander left a comment

Choose a reason for hiding this comment

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

Added some more comments.

from habitat_baselines.config.default import get_config as get_baselines_config


@pytest.mark.skipif(
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. Can you link to a successful CI run of this file here as a reply? It's not clear to me at a glance if this file is getting included in the tests as part of CI install_and_test_ubuntu.

@@ -243,6 +248,10 @@ def reset(self, episode: Episode, fetch_observations: bool = True):
self._is_episode_active = True

if self._should_place_articulated_agent:
if self._fixed_agent_starting_pose:
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you happy with this implementation? I see two old comments that suggest this wasn't quite working correctly yet:

From your PR description:

slightly different agents positions even though we force them to be fixed by adding "fixed_agent_starting_pose" config argument (for the context if "fixed_agent_starting_pose" is in config we fix numpy and sim.pathfinder seeds). probably because float numbers representation? This causes test to fail sometimes.

From this Slack thread:

So, I would expect that setting env.seed(my_seed) would be enough to have deterministic behaviour, but it is not, agent positions are set to different positions every time. Is it working as expected @Andrew Szot @Alex Clegg?

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.

None yet

3 participants