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

(1) Fixed error when using config habitat_hitl.episodes_filter='4' (2) Fixed episodes_filter episode order not respected (3) added check for data folder in current working directory #1774

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions examples/hitl/basic_viewer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Inspect Habitat environments, episodes, and agent policy evaluation in real time
## Installing and using HITL apps
See [habitat-hitl/README.md](../../../habitat-hitl/README.md)

## To run
cd path/to/habitat-lab # Or wherever data/ is symlinked

## Example launch command

```bash
Expand Down
4 changes: 4 additions & 0 deletions examples/hitl/minimal/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Minimal HITL application

A minimal HITL app that loads and steps a Habitat environment, with a fixed overhead camera. See [`habitat_hitl/README.md`](../../../habitat-hitl/README.md#minimal-hitl-application)

# To run

cd path/to/habitat-lab # Or wherever data/ is symlinked
9 changes: 8 additions & 1 deletion habitat-hitl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@ Example HITL apps are configured to run at 30 steps per second (SPS). If your sy
* Be sure to include Bullet physics, e.g. `python setup.py install --bullet`.
4. Install the `habitat-hitl` package.
* From the `habitat-lab` root directory, run `pip install -e habitat-hitl`.
5. Download required assets for our example HITL applications:
5. Download required assets for our example HITL applications (Note that the dataset downloader should be run from habitat-lab/.):
```bash
python -m habitat_sim.utils.datasets_download \
--uids hab3-episodes habitat_humanoids hab_spot_arm ycb hssd-hab \
--data-path data/
```

## Data directory and running location

HITL apps (and Habitat libraries in general) expect a `data/` directory in the running location (aka current working directory). Notice the `--data-path` argument in our installation steps above. Here are two options to consider:

1. Download data to `habitat-lab/data` as shown in our installation steps above. This is the default location for many Habitat tutorials and utilities. Run your HITL app from this location, e.g. `habitat-lab/$ python /path/to/my_hitl_app/my_hitl_app.py`.
2. Download (or symlink) data to your HITL app's root directory, e.g. `/path/to/my_hitl_app/data`. Run your HITL app from this location, e.g. `/path/to/my_hitl_app/$ python my_hitl_app.py`."

## Example HITL applications

Check out our example HITL apps [here](../examples/hitl/).
Expand Down
25 changes: 18 additions & 7 deletions habitat-hitl/habitat_hitl/_internal/hitl_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import json
from datetime import datetime
from functools import wraps
from typing import TYPE_CHECKING, Any, Dict, List, Set
from typing import TYPE_CHECKING, Any, Dict, List

import numpy as np

Expand Down Expand Up @@ -236,34 +236,45 @@ def _make_dataset(self, config):
dataset = make_dataset(
id_dataset=dataset_config.type, config=dataset_config
)

if self._play_episodes_filter_str is not None:
self._play_episodes_filter_str = str(
self._play_episodes_filter_str
)
max_num_digits: int = len(str(len(dataset.episodes)))

def get_play_episodes_ids(play_episodes_filter_str):
play_episodes_ids: Set[str] = set()
play_episodes_ids: List[str] = []
for ep_filter_str in play_episodes_filter_str.split(" "):
if ":" in ep_filter_str:
range_params = map(int, ep_filter_str.split(":"))
play_episodes_ids.update(
play_episodes_ids.extend(
episode_id.zfill(max_num_digits)
for episode_id in map(str, range(*range_params))
)
else:
episode_id = ep_filter_str
play_episodes_ids.add(episode_id.zfill(max_num_digits))
play_episodes_ids.append(
episode_id.zfill(max_num_digits)
)

return play_episodes_ids

play_episodes_ids_set: Set[str] = get_play_episodes_ids(
play_episodes_ids_list = get_play_episodes_ids(
self._play_episodes_filter_str
)
dataset.episodes = [
ep
for ep in dataset.episodes
if ep.episode_id.zfill(max_num_digits) in play_episodes_ids_set
if ep.episode_id.zfill(max_num_digits)
in play_episodes_ids_list
]

dataset.episodes.sort(
key=lambda x: play_episodes_ids_list.index(
x.episode_id.zfill(max_num_digits)
)
)

return dataset

def _get_recent_metrics(self):
Expand Down
10 changes: 10 additions & 0 deletions habitat-hitl/habitat_hitl/core/hitl_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import os

import magnum as mn

from habitat_hitl._internal.config_helper import update_config
Expand Down Expand Up @@ -42,6 +44,14 @@ def _parse_debug_third_person(hitl_config, viewport_multiplier=(1, 1)):


def hitl_main(app_config, create_app_state_lambda=None):
# Add check for data/
if not os.path.exists("data/"):
raise FileNotFoundError(
"Could not find /data in current directory. "
"HITL apps expect 'data/' directory to exist. "
"Either run from habitat-lab directory or symlink data/ folder to your HITL app working directory"
)

hitl_config = omegaconf_to_object(app_config.habitat_hitl)

if hitl_config.experimental.headless.do_headless:
Expand Down