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
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2756b8f
no yet working
vincentpierre Apr 6, 2023
026ad35
movement is working
vincentpierre Apr 6, 2023
2a15ab1
moving camera
vincentpierre Apr 6, 2023
af2e92c
wip
vincentpierre Apr 6, 2023
547cf0b
oops
vincentpierre Apr 6, 2023
d45d5c7
removing action code
vincentpierre Apr 7, 2023
5b102fd
Updating the new actions of the examples
vincentpierre Apr 7, 2023
658f88a
removing more code and configurations
vincentpierre Apr 7, 2023
36a869e
changes for bug fixes
vincentpierre Apr 10, 2023
514f329
not testing sim in lab
vincentpierre Apr 10, 2023
0284ab7
changing a few more configs
vincentpierre Apr 10, 2023
fa416ea
changing config
vincentpierre Apr 10, 2023
6e221dc
new approach
vincentpierre Apr 10, 2023
2ed17c9
this is not going to work beause of pathfinding
vincentpierre Apr 11, 2023
114f1a9
CMD-Z
vincentpierre Apr 12, 2023
b6da3c8
CMD-Z on configs
vincentpierre Apr 12, 2023
1ce2ad5
fixing tests
vincentpierre Apr 13, 2023
9d55fb3
COMMAND - ZZZZZZ
vincentpierre Apr 13, 2023
9854d89
simplify
vincentpierre Apr 13, 2023
4fe7102
simplify
vincentpierre Apr 13, 2023
a9cf6bb
edit README
vincentpierre Apr 13, 2023
1552cd1
readding tests
vincentpierre Apr 13, 2023
899a6ae
removing _try_register_rearrange_task`
vincentpierre Apr 14, 2023
d81c1ad
readding code that I deleted in my previous commit because apparently…
vincentpierre Apr 17, 2023
a01a5ef
addressing comments
vincentpierre May 3, 2023
f100aeb
addressing Alex comment
vincentpierre May 5, 2023
2aee7f2
Merge branch 'main' into habitat1_lab_actions
vincentpierre May 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 74 additions & 113 deletions examples/new_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,169 +12,130 @@
We will use the strafe action outline in the habitat_sim example
"""

import attr
from dataclasses import dataclass

import magnum as mn
import numpy as np

import habitat
import habitat_sim
from habitat.config.default_structured_configs import ActionConfig
from habitat.sims.habitat_simulator.actions import (
HabitatSimActions,
HabitatSimV1ActionSpaceConfiguration,
)
from habitat.tasks.nav.nav import SimulatorTaskAction


@attr.s(auto_attribs=True, slots=True)
class NoisyStrafeActuationSpec:
move_amount: float
# Classic strafing is to move perpendicular (90 deg) to the forward direction
strafe_angle: float = 90.0
noise_amount: float = 0.05
# This is the configuration for our action.
@dataclass
class StrafeActionConfig(ActionConfig):
move_amount: float = 0.0 # We will change this in the configuration
noise_amount: float = 0.0


def _strafe_impl(
scene_node: habitat_sim.SceneNode,
# This is a helper that implements strafing that we will use in our actions
def _strafe_body(
sim,
move_amount: float,
strafe_angle: float,
strafe_angle_degrees: float,
noise_amount: float,
):
forward_ax = (
np.array(scene_node.absolute_transformation().rotation_scaling())
@ habitat_sim.geo.FRONT
# Get the state of the agent
agent_state = sim.get_agent_state()
# Convert from np.quaternion (quaternion.quaternion) to mn.Quaternion
normalized_quaternion = agent_state.rotation
agent_mn_quat = mn.Quaternion(
normalized_quaternion.imag, normalized_quaternion.real
)
strafe_angle = np.deg2rad(strafe_angle)
forward = agent_mn_quat.transform_vector(-mn.Vector3.z_axis())
strafe_angle = np.deg2rad(strafe_angle_degrees)
Skylion007 marked this conversation as resolved.
Show resolved Hide resolved
strafe_angle = np.random.uniform(
(1 - noise_amount) * strafe_angle, (1 + noise_amount) * strafe_angle
)

rotation = habitat_sim.utils.quat_from_angle_axis(
strafe_angle, habitat_sim.geo.UP
)
move_ax = habitat_sim.utils.quat_rotate_vector(rotation, forward_ax)

strafe_angle = mn.Rad(strafe_angle)
rotation = mn.Quaternion.rotation(strafe_angle, mn.Vector3.y_axis())
move_amount = np.random.uniform(
(1 - noise_amount) * move_amount, (1 + noise_amount) * move_amount
)
scene_node.translate_local(move_ax * move_amount)


@habitat_sim.registry.register_move_fn(body_action=True)
class NoisyStrafeLeft(habitat_sim.SceneNodeControl):
def __call__(
self,
scene_node: habitat_sim.SceneNode,
actuation_spec: NoisyStrafeActuationSpec,
):
print(f"strafing left with noise_amount={actuation_spec.noise_amount}")
_strafe_impl(
scene_node,
actuation_spec.move_amount,
actuation_spec.strafe_angle,
actuation_spec.noise_amount,
)


@habitat_sim.registry.register_move_fn(body_action=True)
class NoisyStrafeRight(habitat_sim.SceneNodeControl):
def __call__(
self,
scene_node: habitat_sim.SceneNode,
actuation_spec: NoisyStrafeActuationSpec,
):
print(
f"strafing right with noise_amount={actuation_spec.noise_amount}"
)
_strafe_impl(
scene_node,
actuation_spec.move_amount,
-actuation_spec.strafe_angle,
actuation_spec.noise_amount,
)


@habitat.registry.register_action_space_configuration
class NoNoiseStrafe(HabitatSimV1ActionSpaceConfiguration):
def get(self):
config = super().get()

config[HabitatSimActions.STRAFE_LEFT] = habitat_sim.ActionSpec(
"noisy_strafe_left",
NoisyStrafeActuationSpec(0.25, noise_amount=0.0),
)
config[HabitatSimActions.STRAFE_RIGHT] = habitat_sim.ActionSpec(
"noisy_strafe_right",
NoisyStrafeActuationSpec(0.25, noise_amount=0.0),
)

return config


@habitat.registry.register_action_space_configuration
class NoiseStrafe(HabitatSimV1ActionSpaceConfiguration):
def get(self):
config = super().get()

config[HabitatSimActions.STRAFE_LEFT] = habitat_sim.ActionSpec(
"noisy_strafe_left",
NoisyStrafeActuationSpec(0.25, noise_amount=0.05),
)
config[HabitatSimActions.STRAFE_RIGHT] = habitat_sim.ActionSpec(
"noisy_strafe_right",
NoisyStrafeActuationSpec(0.25, noise_amount=0.05),
)

return config
delta_position = rotation.transform_vector(forward) * move_amount
final_position = sim.pathfinder.try_step( # type: ignore
agent_state.position, agent_state.position + delta_position
)
sim.get_observations_at(
position=final_position, # new position
rotation=agent_state.rotation, # unchanged
keep_agent_at_new_pose=True, # we want to move the agent over there
)


# We define and register our actions as follows.
# the __init__ method receives a sin and config argument.
@habitat.registry.register_task_action
class StrafeLeft(SimulatorTaskAction):
def __init__(self, *args, config, sim, **kwargs):
super().__init__(*args, config=config, sim=sim, **kwargs)
self._sim = sim
self._move_amount = config.move_amount
self._noise_amount = config.noise_amount

def _get_uuid(self, *args, **kwargs) -> str:
return "strafe_left"

def step(self, *args, **kwargs):
return self._sim.step(HabitatSimActions.STRAFE_LEFT)
print(
Skylion007 marked this conversation as resolved.
Show resolved Hide resolved
f"Calling {self._get_uuid()} d={self._move_amount}m noise={self._noise_amount}"
)
_strafe_body(self._sim, self._move_amount, 90, self._noise_amount)


@habitat.registry.register_task_action
class StrafeRight(SimulatorTaskAction):
def __init__(self, *args, config, sim, **kwargs):
super().__init__(*args, config=config, sim=sim, **kwargs)
self._sim = sim
self._move_amount = config.move_amount
self._noise_amount = config.noise_amount

def _get_uuid(self, *args, **kwargs) -> str:
return "strafe_right"

def step(self, *args, **kwargs):
return self._sim.step(HabitatSimActions.STRAFE_RIGHT)
print(
f"Calling {self._get_uuid()} d={self._move_amount}m noise={self._noise_amount}"
)
_strafe_body(self._sim, self._move_amount, -90, self._noise_amount)


def main():
HabitatSimActions.extend_action_space("STRAFE_LEFT")
HabitatSimActions.extend_action_space("STRAFE_RIGHT")

config = habitat.get_config(
config_path="benchmark/nav/pointnav/pointnav_habitat_test.yaml"
)
with habitat.config.read_write(config):
# Add a simple action config to the config.habitat.task.actions dictionary
config.habitat.task.actions["STRAFE_LEFT"] = ActionConfig(
type="StrafeLeft"
# Here we do it via code, but you can easily add them to a yaml config as well
config.habitat.task.actions["STRAFE_LEFT"] = StrafeActionConfig(
type="StrafeLeft",
move_amount=0.25,
noise_amount=0.0,
)
config.habitat.task.actions["STRAFE_RIGHT"] = ActionConfig(
type="StrafeRight"
config.habitat.task.actions["STRAFE_RIGHT"] = StrafeActionConfig(
type="StrafeRight",
move_amount=0.25,
noise_amount=0.0,
)
config.habitat.task.actions["NOISY_STRAFE_LEFT"] = StrafeActionConfig(
type="StrafeLeft",
move_amount=0.25,
noise_amount=0.05, # We add some noise to the configuration here
)
config.habitat.task.actions["NOISY_STRAFE_RIGHT"] = StrafeActionConfig(
type="StrafeRight",
move_amount=0.25,
noise_amount=0.05, # We add some noise to the configuration here
)

config.habitat.simulator.action_space_config = "NoNoiseStrafe"

with habitat.Env(config=config) as env:
env.reset()
env.step("STRAFE_LEFT")
env.step("STRAFE_RIGHT")

with habitat.config.read_write(config):
config.habitat.simulator.action_space_config = "NoiseStrafe"

with habitat.Env(config=config) as env:
env.reset()
env.step("STRAFE_LEFT")
env.step("STRAFE_RIGHT")
env.step("NOISY_STRAFE_LEFT")
env.step("NOISY_STRAFE_RIGHT")


if __name__ == "__main__":
Expand Down
2 changes: 0 additions & 2 deletions examples/tutorials/colabs/Habitat2_Quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@
" additional_object_paths:\n",
" - \"data/objects/ycb/configs/\"\n",
" debug_render: False\n",
" action_space_config: v0\n",
" concur_render: False\n",
" auto_sleep: False\n",
" agents:\n",
Expand All @@ -510,7 +509,6 @@
" # ARM_REST: [0.6, 0.0, 0.9]\n",
" ctrl_freq: 120.0\n",
" ac_freq_ratio: 4\n",
" forward_step_size: 0.25\n",
"\n",
" # Grasping\n",
" hold_thresh: 0.09\n",
Expand Down
2 changes: 0 additions & 2 deletions examples/tutorials/nb_python/Habitat2_Quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ class NavPickSuccessMeasurementConfig(MeasurementConfig):
additional_object_paths:
- "data/objects/ycb/configs/"
debug_render: False
action_space_config: v0
concur_render: False
auto_sleep: False
agents:
Expand All @@ -456,7 +455,6 @@ class NavPickSuccessMeasurementConfig(MeasurementConfig):
# ARM_REST: [0.6, 0.0, 0.9]
ctrl_freq: 120.0
ac_freq_ratio: 4
forward_step_size: 0.25

# Grasping
hold_thresh: 0.09
Expand Down
4 changes: 2 additions & 2 deletions habitat-lab/habitat/config/CONFIG_KEYS.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ defaults:
| habitat.task.actions.move_forward | In Navigation tasks only, this discrete action will move the robot forward by a fixed amount determined by the `habitat.simulator.forward_step_size` amount. |
| habitat.task.actions.turn_left | In Navigation tasks only, this discrete action will rotate the robot to the left by a fixed amount determined by the `habitat.simulator.turn_angle` amount. |
| habitat.task.actions.turn_right | In Navigation tasks only, this discrete action will rotate the robot to the right by a fixed amount determined by the `habitat.simulator.turn_angle` amount. |
| habitat.task.actions.look_up | In Navigation tasks only, this discrete action will rotate the robot's camera up by a fixed amount determined by the `habitat.simulator.tilt_angle` amount. |
| habitat.task.actions.look_down | In Navigation tasks only, this discrete action will rotate the robot's camera down by a fixed amount determined by the `habitat.simulator.tilt_angle` amount. |
| habitat.task.actions.look_up | In Navigation tasks only, this discrete action will rotate the robot's camera up by a fixed amount determined by the `tilt_angle` amount of the look_up action. |
| habitat.task.actions.look_down | In Navigation tasks only, this discrete action will rotate the robot's camera down by a fixed amount determined by the `tilt_angle` amount of the look_down action. |

## Navigation Measures
A measure is a way to collect data about the environment at each step that is not sensor information. Measures can contain privileged information for the user (like a top down map) or for training (like rewards).
Expand Down
4 changes: 0 additions & 4 deletions habitat-lab/habitat/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ habitat:
step_repetition_range: 0.2
simulator:
type: Sim-v0
action_space_config: v0
action_space_config_arguments: {}
forward_step_size: 0.25
create_renderer: false
requires_textures: true
Expand All @@ -134,8 +132,6 @@ habitat:
scene_dataset: default
additional_object_paths: []
seed: ${habitat.seed}
turn_angle: 10
tilt_angle: 15
default_agent_id: 0
debug_render: false
debug_render_robot: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ habitat:
max_episode_steps: 1000
simulator:
turn_angle: 30
tilt_angle: 30
action_space_config: v1
agents:
main_agent:
sim_sensors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ habitat:
max_episode_steps: 1000
simulator:
turn_angle: 30
tilt_angle: 30
action_space_config: v1
agents:
main_agent:
sim_sensors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ defaults:
habitat:
environment:
max_episode_steps: 500

simulator:
turn_angle: 30
tilt_angle: 30
action_space_config: "v1"
agents:
main_agent:
sim_sensors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ defaults:
habitat:
environment:
max_episode_steps: 500

simulator:
turn_angle: 30
tilt_angle: 30
action_space_config: "v1"
agents:
main_agent:
sim_sensors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ habitat:

simulator:
turn_angle: 30
tilt_angle: 30
action_space_config: "v1"
agents:
main_agent:
sim_sensors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ defaults:
habitat:
environment:
max_episode_steps: 500

simulator:
turn_angle: 30
tilt_angle: 30
action_space_config: "v1"
agents:
main_agent:
sim_sensors:
Expand Down
Loading