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

Removing Habitat v1 style actions and move to v2 style #1251

Merged

Conversation

vincentpierre
Copy link
Contributor

@vincentpierre vincentpierre commented Apr 7, 2023

Motivation and Context

Following up on our discussion last Tuesday, I made this PR that moves SOME of our sim actions to lab.
Basically, I changed the logic so that actions no longer return observations (except when they do) and the actions no longer step the simulation physics (except when they do). They do when the action is implemented in sim (only move forward, turn left and turn right) because otherwise we cannot do pathfinding and others.
Overall the code for adding new actions is cleaner (see examples/new_actions.py ) and the stepping is also simpler. Please have a look.

Why not move all the actions to lab ? We need sim actions for navigation to calculate the number of actions needed to solve a navigation task in the episode generator. Hence, we need the sim actions to be used in the task.
Couldn't you just reimplement the actions in lab the same way they are in sim? Yes, but I would need to make sure the action configuration are the same in sim and lab, which can be problematic since it forces the sim config to know about the navigation action configs.
Why are we trying to change the way actions are used? We are moving towards having the lab actions as a default since they are easier to use, they are the only actions habitat2.0 uses.

How Has This Been Tested

Unit tests pass, plus I used a script to make sure the new actions (like tilt camera) do the same thing.

Types of changes

  • [Refactoring] Large changes to the code that improve its functionality or performance

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.

@vincentpierre vincentpierre self-assigned this Apr 7, 2023
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Apr 7, 2023
task=self,
is_last_action=is_last_action,
)
return task_action.step(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of the time, task_action will return None, but for some legacy reason, it will sometimes return the observations. This is because sim.step(action) returns observations. In order to avoid rendering observations twice, we will use the observations computed in task_action when they are available.

Comment on lines 317 to 328
observations: Any = None
if isinstance(action_name, tuple): # there are multiple actions
for i, a_name in enumerate(action_name):
self._step_single_action(
observations,
for a_name in action_name:
observations = self._step_single_action(
a_name,
action,
episode,
i == len(action_name) - 1,
)
else:
self._step_single_action(
observations, action_name, action, episode
observations = self._step_single_action(
action_name, action, episode
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After this code, if observations is None, then we will need to get the observations from the simulator and lab sensors. If it is not None, this means the environment was stepped by the action, so we DO NOT call sim.step()

@@ -181,23 +181,6 @@ def register_dataset(cls, to_register=None, *, name: Optional[str] = None):
"dataset", to_register, name, assert_type=Dataset
)

@classmethod
def register_action_space_configuration(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We deprecate registering new action spaces for sim. If you want to add new actions, you can directly add them to the action space of lab. YOU CAN NO LONGER create new sim actions. The only sim actions we have will be hardcoded. They are move forward turn left and turn right. We use them for pathfinding and other tools.

self.habitat_config.action_space_config
)(self.habitat_config).get()

agent_config.action_space = {
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 where the sim action space is hard coded.

@@ -60,19 +60,14 @@ def reset(self, *args, **kwargs):
super().reset(*args, **kwargs)
self.does_want_terminate = False

def step(self, task, *args, is_last_action, **kwargs):
def step(self, task, *args, **kwargs):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Getting rid of is_last_action for simplicity.

@@ -591,14 +583,6 @@ def test_noise_models_rgbd():
"RedwoodDepthNoiseModel"
)

config.habitat.simulator.action_space_config = "pyrobotnoisy"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deprecating pyrobotnoisy and its test

@vincentpierre vincentpierre marked this pull request as ready for review April 13, 2023 18:23
)

self._sim.step_physics(1.0 / 60.0) # type:ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this call? Why is this using a fixed 60Hz? This didn't seem to be here before, why add 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.

The simulator method always steps physics with a dt of 1/60 (see here)
Before, each action was calling sim.step which is INCREDIBLY INEFFICIENT WHEN THERE ARE MORE THAN ONE ACTION, so instead, the actions now just perform the action and so not step the simulator. The stepping of the simulator happens in EmbodiedTask. Since there is no action to perform and the simulator just the physics needs to be stepped, we do not call sim.step (since this method takes as input an action that does not exist) but instead, we manually step the physics with sim.step_physics.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed this step size should be configured somewhere rather than locked at 60Hz.
True this is the default, but better that it is configured than a magic number.

@ASzot
Copy link
Contributor

ASzot commented Apr 14, 2023

All the HabitatSim action registration code inhabitat-lab/habitat/tasks/rearrange/__init__.py should also be removed.

@vincentpierre
Copy link
Contributor Author

All the HabitatSim action registration code in habitat-lab/habitat/tasks/rearrange/__init__.py should also be removed.

Thanks, I think I just forgot about those. I removed them now.

@vincentpierre vincentpierre requested a review from ASzot April 25, 2023 17:52
examples/new_actions.py Outdated Show resolved Hide resolved
)

def step(self, action: Dict[str, Any], episode: Episode):
action_name = action["action"]
if "action_args" not in action or action["action_args"] is None:
action["action_args"] = {}
observations: Any = {}
observations: Any = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
observations: Any = None
observations: Optional = None

for sensor_name in sensor_names:
sensor = self._sim.agents[0]._sensors[sensor_name].node # type: ignore
sensor.rotation = sensor.rotation * mn.Quaternion.rotation(
mn.Rad(np.deg2rad(amount)), mn.Vector3.x_axis()
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use Magnum degree to rad here

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.

Overall looks good to me.

)

self._sim.step_physics(1.0 / 60.0) # type:ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed this step size should be configured somewhere rather than locked at 60Hz.
True this is the default, but better that it is configured than a magic number.

@vincentpierre vincentpierre merged commit 04d9ed2 into facebookresearch:main May 15, 2023
dannymcy pushed a commit to dannymcy/habitat-lab that referenced this pull request Jul 8, 2024
…rch#1251)

* no yet working

* movement is working

* moving camera

* wip

* oops

* removing action code

* Updating the new actions of the examples

* removing more code and configurations

* changes for bug fixes

* not testing sim in lab

* changing a few more configs

* changing config

* new approach

* this is not going to work beause of pathfinding

* CMD-Z

* CMD-Z on configs

* fixing tests

* COMMAND - ZZZZZZ

* simplify

* simplify

* edit README

* readding tests

* removing _try_register_rearrange_task`

* readding code that I deleted in my previous commit because apparently I cannot read.

* addressing comments

* addressing Alex comment

---------

Co-authored-by: vincentpierre <vincentpierre@users.noreply.github.com>
HHYHRHY pushed a commit to SgtVincent/EMOS that referenced this pull request Aug 31, 2024
…rch#1251)

* no yet working

* movement is working

* moving camera

* wip

* oops

* removing action code

* Updating the new actions of the examples

* removing more code and configurations

* changes for bug fixes

* not testing sim in lab

* changing a few more configs

* changing config

* new approach

* this is not going to work beause of pathfinding

* CMD-Z

* CMD-Z on configs

* fixing tests

* COMMAND - ZZZZZZ

* simplify

* simplify

* edit README

* readding tests

* removing _try_register_rearrange_task`

* readding code that I deleted in my previous commit because apparently I cannot read.

* addressing comments

* addressing Alex comment

---------

Co-authored-by: vincentpierre <vincentpierre@users.noreply.github.com>
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.

5 participants