Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
vmoens committed Nov 6, 2024
1 parent 2a07f4c commit 4f7dcc0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/unittest/linux_libs/scripts_habitat/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ conda deactivate && conda activate ./env


# this workflow only tests the libs
mkdir data
python -m habitat_sim.utils.datasets_download --uids rearrange_dataset_v1 rearrange_pick_dataset_v0 rearrange_task_assets --data-path ./data

python -c "import habitat;import habitat.gym"
python -c """from torchrl.envs.libs.habitat import HabitatEnv
env = HabitatEnv('HabitatRenderPick-v0')
Expand Down
19 changes: 18 additions & 1 deletion torchrl/envs/libs/habitat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from torchrl._utils import _make_ordinal_device
from torchrl.data.utils import DEVICE_TYPING
from torchrl.envs.common import EnvBase
from torchrl.envs.libs.gym import GymEnv, set_gym_backend
from torchrl.envs.libs.gym import GymEnv, set_gym_backend, GymWrapper
from torchrl.envs.utils import _classproperty

_has_habitat = importlib.util.find_spec("habitat") is not None
Expand Down Expand Up @@ -106,6 +106,23 @@ def __init__(self, env_name, **kwargs):
]
super().__init__(env_name=env_name, **kwargs)

@classmethod
def from_config(cls, cfg):
"""Creates a HabitatEnv from the config.
Examples:
>>> config = habitat.get_config(
... "benchmark/nav/objectnav/objectnav_hssd-hab.yaml"
... )
>>> env = HabitatEnv(config)
"""
import habitat.gym

wrapper = cls.__new__(cls)
wrapper.__dict__.update(GymWrapper(habitat.gym.make_gym_from_config(cfg)).__dict__)
return wrapper

@_classproperty
def available_envs(cls):
if not _has_habitat:
Expand Down

0 comments on commit 4f7dcc0

Please sign in to comment.