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

HITL - Rearrange State Machine #1964

Merged
merged 11 commits into from
May 18, 2024
Merged

HITL - Rearrange State Machine #1964

merged 11 commits into from
May 18, 2024

Conversation

0mdc
Copy link
Contributor

@0mdc 0mdc commented May 17, 2024

Motivation and Context

This changeset turns rearrange_v2 into a state machine with the following states:

  1. Reset (initial state)
    • Kicks all users. Intended to reset states between sessions.
    • When all users are disconnected, changes state to lobby.
  2. Lobby
    • Blank screen. New incoming connections are only allowed in this state.
    • When max_client_count users are connected, changes state to rearrange_v2.
  3. Rearrange
    • rearrange_v2 application.
    • When both users signaled that the episode is done, changes state to reset.
state_machine-2024-05-17_13.15.44.mp4

Notes

  • The entry point is now main.py instead of rearrange_v2.py.
  • rearrange_v2.py will be renamed later to simplify merging of concurrent changes.

Depends on:

Limitations

  • In this version, there is no session management. The same episode keeps running indefinitely - there is no reset.
  • When users are kicked, no message is shown.
  • Because ClientHelper depends on connection events, its lifetime is now coupled with RemoteClientState. This will be refactored in a later pass.
  • rearrange_v2 smoke test is disabled until it is stabilized.

How Has This Been Tested

Tested on multiplayer HITL application.

Types of changes

  • [Development]

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 May 17, 2024
Copy link
Contributor

@aclegg3 aclegg3 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 from my context.


from habitat_hitl.app_states.app_service import AppService

START_SESSION_DELAY: Final[float] = 0.5
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment to explain the empirically chosen value? I see the comment below about disconnects, but still curious.

Comment on lines +304 to +308
user_index_to_agent_index_map: Dict[int, int] = {}
for user_index in range(len(self._user_data)):
user_index_to_agent_index_map[user_index] = self._user_data[
user_index
].gui_agent_controller._agent_idx
Copy link
Contributor

Choose a reason for hiding this comment

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

Confirming that user-index is networked humans who have joined and != agent-count/index?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct! This is the "decoupling" work I still have to do.

Comment on lines +317 to +320
return all(
self._user_data[user_index].episode_finished
for user_index in self._users.indices(Mask.ALL)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Interested to see how can I expose user-data for llm-agent to you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably not ideal, but the easiest solution would be to query the agent controller types at initialization and handle things from there.

task_instruction = current_episode.instruction
# TODO: Users will have different instructions.
for user_index in self._users.indices(Mask.ALL):
self._user_data[user_index].task_instruction = task_instruction
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm, I see. I am setting such metadata/data for llm-agent directly from habitat Env class. It'd be good to standardize all data-setting to flow from here.

Therefore, interested to see how can I consume this user-data variable at init/reset time. We can just pass this on to ctrl_helper, right? It'll just be ignore as part of *args, **kwargs for other controllers which have no use for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That should be doable.

If you only need user events, you should be able to bind events from rearrange_v2.on_environment_reset() as you will have access to both variables. I'll be adding them in the next 2 PRs.

Comment on lines +366 to +374
if self._user_data[user_index].show_gui_text:
controls_str += "H: Toggle help\n"
controls_str += "Look: Middle click (drag), I, K\n"
controls_str += "Walk: W, S\n"
controls_str += "Turn: A, D\n"
controls_str += "Finish episode: Zero (0)\n"
controls_str += "Open/close: Double-click\n"
controls_str += "Pick object: Double-click\n"
controls_str += "Place object: Right click (hold)\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an option to see current-instruction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's currently displayed via the status message.

Comment on lines +376 to +379
client_helper = self._app_service.remote_client_state._client_helper
idle_time = client_helper.get_idle_time(user_index)
if idle_time > 10:
controls_str += f"Idle time {idle_time}s\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

Note if you kick users/agents for idle_time > SOME_THRESH this may need to be tweaked for LLM-agent versus human user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The LLM agent will not have an idle counter. I still have to decouple this.

idle_time = client_helper.get_idle_time(user_index)
if idle_time > 10:
controls_str += f"Idle time {idle_time}s\n"

return controls_str

def _get_status_text(self, user_index: int):
Copy link
Contributor

Choose a reason for hiding this comment

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

Ooh! Lovely. I can pass current_high_level_action being executed by LLM-agent here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If time permits, I can also add a text field to viewports so that its rendered into the picture-in-picture view.

Comment on lines +493 to +497
def _is_any_user_active(self) -> bool:
return any(
self._user_data[user_index].gui_input.get_any_input()
for user_index in range(self._app_data.max_user_count)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this work for LLM-agent? Or do you not care? We probably should.

Copy link
Contributor Author

@0mdc 0mdc May 18, 2024

Choose a reason for hiding this comment

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

This should work without changes with LLM agents. user_data, max_user_count and user_index all relate to human users.

In the LLM case, max_user_count will be 1, but agent_count will be 2. I have to decouple these concepts within user_data (will most likely create an analogous agent_data struct).

@0mdc 0mdc merged commit 838f68f into main May 18, 2024
3 of 4 checks passed
@0mdc 0mdc deleted the 0mdc/hitl_state_machine branch May 18, 2024 17:38
@0mdc 0mdc mentioned this pull request May 19, 2024
5 tasks
0mdc added a commit that referenced this pull request May 23, 2024
* Add viewports.

* Add viewports to rearrange_v2.

* Add object visiblity and viewport visbility layers.

* Hide self in viewports.

* Don't render viewports if networking is disabled.

* Turn rearrange_v2 into a state machine. Add lobby.

* Disable rearrange_v2 test.

* Config changes.

* Change episode termination states.

* Add comment to lobby start session delay.
@0mdc 0mdc mentioned this pull request Jun 19, 2024
5 tasks
dannymcy pushed a commit to dannymcy/habitat-lab that referenced this pull request Jun 26, 2024
* Add viewports.

* Add viewports to rearrange_v2.

* Add object visiblity and viewport visbility layers.

* Hide self in viewports.

* Don't render viewports if networking is disabled.

* Turn rearrange_v2 into a state machine. Add lobby.

* Disable rearrange_v2 test.

* Config changes.

* Change episode termination states.

* Add comment to lobby start session delay.
dannymcy pushed a commit to dannymcy/habitat-lab that referenced this pull request Jul 8, 2024
* Add viewports.

* Add viewports to rearrange_v2.

* Add object visiblity and viewport visbility layers.

* Hide self in viewports.

* Don't render viewports if networking is disabled.

* Turn rearrange_v2 into a state machine. Add lobby.

* Disable rearrange_v2 test.

* Config changes.

* Change episode termination states.

* Add comment to lobby start session delay.
dannymcy pushed a commit to dannymcy/habitat-lab that referenced this pull request Jul 8, 2024
* Add viewports.

* Add viewports to rearrange_v2.

* Add object visiblity and viewport visbility layers.

* Hide self in viewports.

* Don't render viewports if networking is disabled.

* Turn rearrange_v2 into a state machine. Add lobby.

* Disable rearrange_v2 test.

* Config changes.

* Change episode termination states.

* Add comment to lobby start session delay.
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