Skip to content

Commit

Permalink
[0.2.3][Hydra Migration] Made agents to be of type Dict[str, AgentCon…
Browse files Browse the repository at this point in the history
…fig] and added migration readme (#1007)

* made habitat.simulator.agents be a Dict[str, AgentConfig]

* addressed comments

* refactored sim agents configuration

* moved rearrange agents declarations to agents folder; finised agents configuration updates; updated docs

* updated get_config import

* Cfg sys migration readme (#2)

* added habitat-lab config readme

* addressed most of the comments

* added main_agent alias

* renamed habitat config reagme and added baselines config readme

* Update habitat-lab/habitat/config/default.py

Co-authored-by: Vincent-Pierre BERGES <28320361+vincentpierre@users.noreply.github.com>

* added desctiption for the agents_order field

* added a dot :)

Co-authored-by: Vincent-Pierre BERGES <28320361+vincentpierre@users.noreply.github.com>
  • Loading branch information
rpartsey and vincentpierre authored Nov 29, 2022
1 parent 39eca95 commit b40736f
Show file tree
Hide file tree
Showing 84 changed files with 1,292 additions and 738 deletions.
4 changes: 3 additions & 1 deletion docs/pages/habitat-lab-demo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ the config object.
import numpy as np
from PIL import Image
from habitat_sim.utils.common import d3_40_colors_rgb
from habitat.config.default import get_agent_config
from habitat.config.default_structured_configs import HabitatSimSemanticSensorConfig
def display_sample(rgb_obs, semantic_obs, depth_obs):
Expand All @@ -128,7 +129,8 @@ the config object.
config = habitat.get_config(config_paths="benchmark/nav/pointnav/pointnav_mp3d.yaml")
with read_write(config):
config.habitat.dataset.split = "val"
config.habitat.simulator.agent_0.sim_sensors.update(
agent_config = get_agent_config(sim_config=config.habitat.simulator)
agent_config.sim_sensors.update(
{"semantic_sensor": HabitatSimSemanticSensorConfig(height=256, width=256)}
)
config.habitat.simulator.turn_angle = 30
Expand Down
10 changes: 6 additions & 4 deletions docs/pages/view-transform-warp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ validate that transformation comparing projected and original views.
import habitat
from habitat.config import read_write
from habitat.config.default import get_agent_config
import torch.nn.functional as F
import torch
Expand All @@ -31,14 +32,15 @@ validate that transformation comparing projected and original views.
config = habitat.get_config(config_paths="benchmark/nav/pointnav/pointnav_habitat_test.yaml")
with read_write(config):
config.habitat.dataset.split = "val"
config.habitat.simulator.agent_0.sim_sensors.depth_sensor.normalize_depth = False
agent_config = get_agent_config(sim_config=config.habitat.simulator)
agent_config.sim_sensors.depth_sensor.normalize_depth = False
# Intrinsic parameters, assuming width matches height. Requires a simple refactor otherwise
W = config.habitat.simulator.agent_0.sim_sensors.depth_sensor.width
H = config.habitat.simulator.agent_0.sim_sensors.depth_sensor.height
W = agent_config.sim_sensors.depth_sensor.width
H = agent_config.sim_sensors.depth_sensor.height
assert(W == H)
hfov = float(config.habitat.simulator.agent_0.sim_sensors.depth_sensor.hfov) * np.pi / 180.
hfov = float(agent_config.sim_sensors.depth_sensor.hfov) * np.pi / 180.
env = habitat.Env(config=config)
Expand Down
4 changes: 3 additions & 1 deletion examples/interactive_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

import habitat
import habitat.tasks.rearrange.rearrange_task
from habitat.config.default import get_agent_config
from habitat.config.default_structured_configs import (
GfxReplayMeasureMeasurementConfig,
ThirdRGBSensorConfig,
Expand Down Expand Up @@ -593,7 +594,8 @@ def has_pygame():

if not args.same_task:
sim_config.debug_render = True
sim_config.agent_0.sim_sensors.update(
agent_config = get_agent_config(sim_config=sim_config)
agent_config.sim_sensors.update(
{
"third_rgb_sensor": ThirdRGBSensorConfig(
height=args.play_cam_res, width=args.play_cam_res
Expand Down
2 changes: 1 addition & 1 deletion examples/new_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def main():
HabitatSimActions.extend_action_space("STRAFE_RIGHT")

config = habitat.get_config(
config_paths="benchmark/nav/pointnav/pointnav_habitat_test.yaml"
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
Expand Down
2 changes: 1 addition & 1 deletion examples/register_new_sensors_and_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class AgentPositionSensorConfig(LabSensorConfig):
def main():
# Get the default config node
config = habitat.get_config(
config_paths="benchmark/nav/pointnav/pointnav_habitat_test.yaml"
config_path="benchmark/nav/pointnav/pointnav_habitat_test.yaml"
)
with habitat.config.read_write(config):
my_value = 5
Expand Down
2 changes: 1 addition & 1 deletion examples/shortest_path_follower_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def draw_top_down_map(info, output_size):

def shortest_path_example():
config = habitat.get_config(
config_paths="benchmark/nav/pointnav/pointnav_habitat_test.yaml",
config_path="benchmark/nav/pointnav/pointnav_habitat_test.yaml",
overrides=[
"+habitat/task/measurements@habitat.task.measurements.top_down_map=top_down_map"
],
Expand Down
34 changes: 18 additions & 16 deletions examples/tutorials/colabs/Habitat2_Quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"# Play a teaser video\n",
"from dataclasses import dataclass\n",
"\n",
"from habitat.config.default import get_agent_config\n",
"from habitat.config.default_structured_configs import (\n",
" MeasurementConfig,\n",
" ThirdRGBSensorConfig,\n",
Expand Down Expand Up @@ -99,7 +100,8 @@
" # Added settings to make rendering higher resolution for better visualization\n",
" with habitat.config.read_write(config):\n",
" config.habitat.simulator.concur_render = False\n",
" config.habitat.simulator.agent_0.sim_sensors.update(\n",
" agent_config = get_agent_config(sim_config=config.habitat.simulator)\n",
" agent_config.sim_sensors.update(\n",
" {\"third_rgb_sensor\": ThirdRGBSensorConfig(height=512, width=512)}\n",
" )\n",
" return config\n",
Expand Down Expand Up @@ -413,9 +415,8 @@
"\n",
"defaults:\n",
" - /habitat: habitat_config_base\n",
" - /agent@habitat.simulator.agent_0: agent_base\n",
" - /habitat/simulator/sim_sensors:\n",
" - head_rgb_sensor\n",
" - /habitat/simulator/agents@habitat.simulator.agents.main_agent: agent_base\n",
" - /habitat/simulator/sim_sensors@habitat.simulator.agents.main_agent.sim_sensors.head_rgb_sensor: head_rgb_sensor\n",
" - /habitat/task: task_config_base\n",
" - /habitat/task/actions:\n",
" - arm_action\n",
Expand Down Expand Up @@ -486,18 +487,19 @@
" action_space_config: v0\n",
" concur_render: False\n",
" auto_sleep: False\n",
" agent_0:\n",
" height: 1.5\n",
" is_set_start_state: False\n",
" radius: 0.1\n",
" sim_sensors:\n",
" head_rgb_sensor:\n",
" height: 128\n",
" width: 128\n",
" start_position: [0, 0, 0]\n",
" start_rotation: [0, 0, 0, 1]\n",
" robot_urdf: ./data/robots/hab_fetch/robots/hab_fetch.urdf\n",
" robot_type: \"FetchRobot\"\n",
" agents:\n",
" main_agent:\n",
" height: 1.5\n",
" is_set_start_state: False\n",
" radius: 0.1\n",
" sim_sensors:\n",
" head_rgb_sensor:\n",
" height: 128\n",
" width: 128\n",
" start_position: [0, 0, 0]\n",
" start_rotation: [0, 0, 0, 1]\n",
" robot_urdf: ./data/robots/hab_fetch/robots/hab_fetch.urdf\n",
" robot_type: \"FetchRobot\"\n",
"\n",
" # Agent setup\n",
" # ARM_REST: [0.6, 0.0, 0.9]\n",
Expand Down
6 changes: 3 additions & 3 deletions examples/tutorials/colabs/Habitat_Lab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"source": [
"if __name__ == \"__main__\":\n",
" config = habitat.get_config(\n",
" config_paths=\"./test/habitat_all_sensors_test.yaml\"\n",
" config_path=\"./test/habitat_all_sensors_test.yaml\"\n",
" )\n",
"\n",
" try:\n",
Expand Down Expand Up @@ -321,7 +321,7 @@
"source": [
"if __name__ == \"__main__\":\n",
" config = habitat.get_config(\n",
" config_paths=\"./test/habitat_all_sensors_test.yaml\"\n",
" config_path=\"./test/habitat_all_sensors_test.yaml\"\n",
" )\n",
"\n",
"\n",
Expand Down Expand Up @@ -434,7 +434,7 @@
"source": [
"if __name__ == \"__main__\":\n",
" config = habitat.get_config(\n",
" config_paths=\"./test/habitat_all_sensors_test.yaml\"\n",
" config_path=\"./test/habitat_all_sensors_test.yaml\"\n",
" )\n",
"\n",
" from habitat.config.default_structured_configs import LabSensorConfig\n",
Expand Down
34 changes: 18 additions & 16 deletions examples/tutorials/nb_python/Habitat2_Quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
# Play a teaser video
from dataclasses import dataclass

from habitat.config.default import get_agent_config
from habitat.config.default_structured_configs import (
MeasurementConfig,
ThirdRGBSensorConfig,
Expand Down Expand Up @@ -92,7 +93,8 @@ def insert_render_options(config):
# Added settings to make rendering higher resolution for better visualization
with habitat.config.read_write(config):
config.habitat.simulator.concur_render = False
config.habitat.simulator.agent_0.sim_sensors.update(
agent_config = get_agent_config(sim_config=config.habitat.simulator)
agent_config.sim_sensors.update(
{"third_rgb_sensor": ThirdRGBSensorConfig(height=512, width=512)}
)
return config
Expand Down Expand Up @@ -362,9 +364,8 @@ class NavPickSuccessMeasurementConfig(MeasurementConfig):
defaults:
- /habitat: habitat_config_base
- /agent@habitat.simulator.agent_0: agent_base
- /habitat/simulator/sim_sensors:
- head_rgb_sensor
- /habitat/simulator/agents@habitat.simulator.agents.main_agent: agent_base
- /habitat/simulator/sim_sensors@habitat.simulator.agents.main_agent.sim_sensors.head_rgb_sensor: head_rgb_sensor
- /habitat/task: task_config_base
- /habitat/task/actions:
- arm_action
Expand Down Expand Up @@ -435,18 +436,19 @@ class NavPickSuccessMeasurementConfig(MeasurementConfig):
action_space_config: v0
concur_render: False
auto_sleep: False
agent_0:
height: 1.5
is_set_start_state: False
radius: 0.1
sim_sensors:
head_rgb_sensor:
height: 128
width: 128
start_position: [0, 0, 0]
start_rotation: [0, 0, 0, 1]
robot_urdf: ./data/robots/hab_fetch/robots/hab_fetch.urdf
robot_type: "FetchRobot"
agents:
main_agent:
height: 1.5
is_set_start_state: False
radius: 0.1
sim_sensors:
head_rgb_sensor:
height: 128
width: 128
start_position: [0, 0, 0]
start_rotation: [0, 0, 0, 1]
robot_urdf: ./data/robots/hab_fetch/robots/hab_fetch.urdf
robot_type: "FetchRobot"
# Agent setup
# ARM_REST: [0.6, 0.0, 0.9]
Expand Down
6 changes: 3 additions & 3 deletions examples/tutorials/nb_python/Habitat_Lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def display_sample(
# %%
if __name__ == "__main__":
config = habitat.get_config(
config_paths="./test/habitat_all_sensors_test.yaml"
config_path="./test/habitat_all_sensors_test.yaml"
)

try:
Expand Down Expand Up @@ -245,7 +245,7 @@ def display_sample(
# %%
if __name__ == "__main__":
config = habitat.get_config(
config_paths="./test/habitat_all_sensors_test.yaml"
config_path="./test/habitat_all_sensors_test.yaml"
)


Expand Down Expand Up @@ -338,7 +338,7 @@ def get_observation(self, observations, *args, episode, **kwargs):
# %%
if __name__ == "__main__":
config = habitat.get_config(
config_paths="./test/habitat_all_sensors_test.yaml"
config_path="./test/habitat_all_sensors_test.yaml"
)

from habitat.config.default_structured_configs import LabSensorConfig
Expand Down
2 changes: 1 addition & 1 deletion examples/visualization_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def example_pointnav_draw_target_birdseye_view_agent_on_border():

def example_get_topdown_map():
config = habitat.get_config(
config_paths="benchmark/nav/pointnav/pointnav_habitat_test.yaml"
config_path="benchmark/nav/pointnav/pointnav_habitat_test.yaml"
)
dataset = habitat.make_dataset(
id_dataset=config.habitat.dataset.type, config=config.habitat.dataset
Expand Down
2 changes: 1 addition & 1 deletion examples/vln_reference_path_follower_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def reference_path_example(mode):
Args:
mode: 'geodesic_path' or 'greedy'
"""
config = habitat.get_config(config_paths="test/habitat_r2r_vln_test.yaml")
config = habitat.get_config(config_path="test/habitat_r2r_vln_test.yaml")
with habitat.config.read_write(config):
config.habitat.task.measurements.update(
{"top_down_map": TopDownMapMeasurementConfig()}
Expand Down
14 changes: 7 additions & 7 deletions habitat-baselines/habitat_baselines/agents/slam_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from torch.nn import functional as F

import habitat
from habitat.config.default import get_config
from habitat.config.default import get_agent_config, get_config
from habitat.sims.habitat_simulator.actions import HabitatSimActions
from habitat_baselines.config.default import get_config as cfg_baseline
from habitat_baselines.slambased.mappers import DirectDepthMapper
Expand Down Expand Up @@ -71,11 +71,11 @@ def ResizePIL2(np_img, size=256):


def make_good_config_for_orbslam2(config):
config.habitat.simulator.agent_0.sensors = ["rgb_sensor", "depth_sensor"]
config.habitat.simulator.rgb_sensor.width = 256
config.habitat.simulator.rgb_sensor.height = 256
config.habitat.simulator.depth_sensor.width = 256
config.habitat.simulator.depth_sensor.height = 256
agent_config = get_agent_config(config.habitat.simulator)
agent_config.sim_sensors.rgb_sensor.width = 256
agent_config.sim_sensors.rgb_sensor.height = 256
agent_config.sim_sensors.depth_sensor.width = 256
agent_config.sim_sensors.depth_sensor.height = 256
config.TRAINER.orbslam2.camera_height = (
config.habitat.simulator.depth_sensor.position[1]
)
Expand Down Expand Up @@ -614,7 +614,7 @@ def main():
agent_config = cfg_baseline()
with habitat.config.read_write(config):
config.BASELINE = agent_config.BASELINE
make_good_config_for_orbslam2(config)
make_good_config_for_orbslam2(config)

if args.agent_type == "blind":
agent = BlindAgent(config.TRAINER.orbslam2)
Expand Down
8 changes: 8 additions & 0 deletions habitat-baselines/habitat_baselines/config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Habitat-Lab Configuration System
================================
![Habitat with Hydra](/res/img/habitat_with_hydra.png)

Habitat-Lab's and Habitat-Baselines' configuration system has been changed from [YACS](https://github.com/rbgirshick/yacs)
to [Hydra](https://hydra.cc). Please, see [habitat-lab/habitat/config/README.md](/habitat-lab/habitat/config/README.md)
to find out more about what was changed, what new functionality is enabled and explore typical examples of
how to work with configs.
46 changes: 17 additions & 29 deletions habitat-baselines/habitat_baselines/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,38 @@

import inspect
import os.path as osp
import threading
from typing import Optional

from hydra import compose, initialize_config_dir
from omegaconf import DictConfig, OmegaConf
from omegaconf import DictConfig

from habitat.config.default import get_full_config_path
from habitat.config.default_structured_configs import (
HabitatConfigPlugin,
register_hydra_plugin,
)
from habitat.config.default import get_config as _habitat_get_config
from habitat.config.default_structured_configs import register_hydra_plugin
from habitat_baselines.config.default_structured_configs import (
HabitatBaselinesConfigPlugin,
)

_BASELINES_CFG_DIR = osp.dirname(inspect.getabsfile(inspect.currentframe()))
# Habitat baselines config directory inside the installed package.
# Used to access default predefined configs.
# This is equivalent to doing osp.dirname(osp.abspath(__file__))
DEFAULT_CONFIG_DIR = "habitat-lab/habitat/config/"
CONFIG_FILE_SEPARATOR = ","


lock = threading.Lock()


def get_config(
config_paths: str,
config_path: str,
overrides: Optional[list] = None,
configs_dir: str = _BASELINES_CFG_DIR,
) -> DictConfig:
register_hydra_plugin(HabitatConfigPlugin)
"""
Returns habitat_baselines config object composed of configs from yaml file (config_path) and overrides.
:param config_path: path to the yaml config file.
:param overrides: list of config overrides. For example, :py:`overrides=["habitat_baselines.trainer_name=ddppo"]`.
:param configs_dir: path to the config files root directory (defaults to :ref:`_BASELINES_CFG_DIR`).
:return: composed config object.
"""
register_hydra_plugin(HabitatBaselinesConfigPlugin)

config_path = get_full_config_path(
config_paths, default_configs_dir=_BASELINES_CFG_DIR
)
# If get_config is called from different threads, Hydra might
# get initialized twice leading to issues. This lock fixes it.
with lock, initialize_config_dir(
version_base=None,
config_dir=osp.dirname(config_path),
):
cfg = compose(
config_name=osp.basename(config_path),
overrides=overrides if overrides is not None else [],
)

OmegaConf.set_readonly(cfg, True)
cfg = _habitat_get_config(config_path, overrides, configs_dir)

return cfg
Loading

0 comments on commit b40736f

Please sign in to comment.