Giter VIP home page Giter VIP logo

agenthive's Introduction

AgentHive

AgentHive is the agents module for RoboHive. It contains trained agents as well as the primitives and helper scripts to train new agents for RoboHive environments.

Overview

AgentHive provides the tools and helper scripts for training agents as well as offline and online execution of pre-packaged trained agents. RoboHive can be used with any openAI-Gym compatible algorithmic baselines to train agents for its environment. RoboHive developers have used the following baseline frameworks during developments. The with a goal of expanding over time.

  1. TorchRL
  2. mjRL
  3. Stable Baselines

Pretrained baselines

AgentHive comes prepackaged with as a set of pre-trained baselines. The goal of these baselines is to provide a mechanism for used to enjoy out-of-box capabilities wit RoboHive. We are continuously accepting contributions to grow our pre-trained collections, please send us a pull request.

Agent Utilities

Environment wrappers

AgentHive provides environment wrappers specifically designed to work with RoboHive gym environment. Find examples in test/test_envs.py.

The basic usage is:

env = RoboHiveEnv(env_name="FrankaReachRandom_v2d-v0")

The following kitchen and franka visual environments should be used (they will be executed without flattening/unflattening of the images which is an expensive process):

env_list = ["visual_franka_slide_random-v3",
   "visual_franka_slide_close-v3",
   "visual_franka_slide_open-v3",
   "visual_franka_micro_random-v3",
   "visual_franka_micro_close-v3",
   "visual_franka_micro_open-v3",
   "visual_kitchen_knob1_off-v3",
   "visual_kitchen_knob1_on-v3",
   "visual_kitchen_knob2_off-v3",
   "visual_kitchen_knob2_on-v3",
   "visual_kitchen_knob3_off-v3",
   "visual_kitchen_knob3_on-v3",
   "visual_kitchen_knob4_off-v3",
   "visual_kitchen_knob4_on-v3",
   "visual_kitchen_light_off-v3",
   "visual_kitchen_light_on-v3",
   "visual_kitchen_sdoor_close-v3",
   "visual_kitchen_sdoor_open-v3",
   "visual_kitchen_ldoor_close-v3",
   "visual_kitchen_ldoor_open-v3",
   "visual_kitchen_rdoor_close-v3",
   "visual_kitchen_rdoor_open-v3",
   "visual_kitchen_micro_close-v3",
   "visual_kitchen_micro_open-v3",
   "visual_kitchen_close-v3"
]

To use the environment in parallel, wrap it in a ParallelEnv:

from torchrl.envs import EnvCreator, ParallelEnv
env = ParallelEnv(3, EnvCreator(lambda: RoboHiveEnv(env_name="FrankaReachRandom_v2d-v0")))

To use transforms (normalization, grayscale etc), use the env transforms:

from torchrl.envs import EnvCreator, ParallelEnv, TransformedEnv, R3MTransform
env = ParallelEnv(3, EnvCreator(lambda: RoboHiveEnv(env_name="FrankaReachRandom_v2d-v0")))
env = TransformedEnv(
    base_env,
    R3MTransform(
        "resnet18",
        ["pixels"],
        ["pixels_embed"],
    ),
)

Make sure that the R3M or VIP transform is appended after the ParallelEnv, otherwise you will pass as many images as there are processes through the ResNet module (and quickly run into an OOM exception).

Finally, the script of a typical data collector (executed on 4 different GPUs in an asynchronous manner) reads as follows:

import tqdm
from torchrl.collectors.collectors import MultiaSyncDataCollector, RandomPolicy
from agenthive.rl_envs import RoboHiveEnv
from torchrl.envs import ParallelEnv, TransformedEnv, GrayScale, ToTensorImage, Resize, ObservationNorm, EnvCreator, Compose, CatFrames

if __name__ == '__main__':
    # create a parallel env with 4 envs running independendly.
    # I put the 'cuda:0' device to show how to create an env on cuda (ie: the output tensors will be on cuda)
    # but this will be overwritten in the collector below
    penv = ParallelEnv(4, EnvCreator(lambda: RoboHiveEnv('FrankaReachRandom_v2d-v0', device='cuda:0', from_pixels=True)))
    # we append a series of standard transforms, all running on cuda
    tenv = TransformedEnv(penv, Compose(ToTensorImage(), Resize(84, 84), GrayScale(), CatFrames(4, in_keys=['pixels']), ObservationNorm(in_keys=['pixels'])))
    # this is how you initialize your observation norm transform (the API will be improved shortly)
    tenv.transform[-1].init_stats(reduce_dim=(0, 1), cat_dim=1, num_iter=1000)
    # we cheat a bit by using a totally random policy. A CNN will obviously slow down collection a bit
    policy = RandomPolicy(tenv.action_spec)  # some random policy

    # we create an async collector on 4 different devices. The "passing_devices"  indicate where the env is placed, and the "device" where the policy is executed.
    # For a maximum efficiency they should match. Also, you can either pass a string for those args (ie all devices match) or a list of strings/devices.
    collector = MultiaSyncDataCollector([tenv, tenv, tenv, tenv], policy=policy, frames_per_batch=400, max_frames_per_traj=1000, total_frames=1_000_000,
                                        passing_devices=['cuda:0', 'cuda:1', 'cuda:2', 'cuda:3'],
                                        devices=['cuda:0', 'cuda:1', 'cuda:2', 'cuda:3'])
    # a simple collection loop to log the speed
    pbar = tqdm.tqdm(total=1_000_000)
    for data in collector:
        pbar.update(data.numel())
    del collector
    del tenv

Model training

The safest way of coding up a model and training it is to refer to the official torchrl examples:

Execution

AgentHive is optimized for the MUJOCO backend. Make sure to set the sim_backend environment variable to "MUJOCO" before running the code:

sim_backend=MUJOCO python script.py

Installation

AgentHive has two core dependencies: torchrl and RoboHive. RoboHive relies on mujoco and mujoco-py for physics simulation and rendering. As of now, RoboHive requires you to use the old mujoco bindings as well as the v0.13 of gym. TorchRL provides detailed instructions. on how to setup an environment with the old mujoco bindings.

See also the Getting Started markdown for more info on setting up your env.

For more complete instructions, check the installation pipeline in .circleci/unittest/linux/script/install.sh

agenthive's People

Contributors

facebook-github-bot avatar jdvakil avatar shahrutav avatar vikashplus avatar vmoens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

agenthive's Issues

Error after using the latest torchrl version

Command: HYDRA_FULL_ERROR=1 sim_backend=MUJOCO MUJOCO_GL=egl python train.py task=kitchen_knob1_off-v3 visual_transform= env_per_collector=1 lr=1e-3 hydra/launcher=local hydra/output=local

Traceback (most recent call last):
  File "train.py", line 20, in <module>
    main()
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/hydra/main.py", line 90, in decorated_main
    _run_hydra(
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/hydra/_internal/utils.py", line 394, in _run_hydra
    _run_app(
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/hydra/_internal/utils.py", line 457, in _run_app
    run_and_report(
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/hydra/_internal/utils.py", line 222, in run_and_report
    raise ex
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/hydra/_internal/utils.py", line 219, in run_and_report
    return func()
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/hydra/_internal/utils.py", line 458, in <lambda>
    lambda: hydra.run(
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/hydra/_internal/hydra.py", line 132, in run
    _ = ret.return_value
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/hydra/core/utils.py", line 260, in return_value
    raise self._return_value
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/hydra/core/utils.py", line 186, in run_job
    ret.return_value = task_function(task_cfg)
  File "train.py", line 12, in main
    train_sac(args)
  File "/home/rutavms/research/robohive/rlhive/examples/sac.py", line 516, in main
    td_record = recorder(None)
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/torchrl/trainers/trainers.py", line 1185, in __call__
    value = td_record.get(key).float()
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/tensordict/tensordict.py", line 3214, in get
    return self._default_get(key, default)
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/tensordict/tensordict.py", line 1003, in _default_get
    raise KeyError(
KeyError: 'key "solved" not found in TensorDict with keys [\'action\', \'done\', \'loc\', \'next\', \'observation_vector\', \'reward\', \'sample_log_prob\', \'scale\']'

Installation problems

I'm having problem with installation.

When I'm directly following Getting started instructions I'm receiving following error during rlhive import:

Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "/home/lklimkiewicz/reps/robots/agenthive_test1/agenthive/rlhive/__init__.py", line 6, in <module>
    from .envs import (
  File "/home/lklimkiewicz/reps/robots/agenthive_test1/agenthive/rlhive/envs.py", line 16, in <module>
    visual_obs_keys_wt = robohive.envs.multi_task.substeps1.visual_obs_keys_wt

To fix this particular error I downgraded robohive from 0.6 to 0.5, but I stumbled on another one:

Warning: Unused kwargs found: {'frameskip': 1, 'return_dict': True}
Configuring a new session for Franka_kitchen_sim(sim)
Reading robot-configurations from /home/lklimkiewicz/miniconda3/envs/agenthive_v4/lib/python3.8/site-packages/robohive/envs/multi_task/substeps1/../common/slidecabinet/franka_slidecabinet.config
Configuring component franka
Configuring component slidecabinet
Traceback (most recent call last):
  File "<string>", line 4, in <module>
  File "/home/lklimkiewicz/miniconda3/envs/agenthive_v4/lib/python3.8/site-packages/torchrl/envs/libs/gym.py", line 395, in __call__
    instance: GymWrapper = super().__call__(*args, **kwargs)
  File "/home/lklimkiewicz/miniconda3/envs/agenthive_v4/lib/python3.8/site-packages/torchrl/envs/common.py", line 134, in __call__
    instance: EnvBase = super().__call__(*args, **kwargs)
  File "/home/lklimkiewicz/miniconda3/envs/agenthive_v4/lib/python3.8/site-packages/torchrl/envs/libs/gym.py", line 953, in __init__
    super().__init__(**kwargs)
  File "/home/lklimkiewicz/miniconda3/envs/agenthive_v4/lib/python3.8/site-packages/torchrl/envs/libs/gym.py", line 504, in __init__
    super().__init__(**kwargs)
  File "/home/lklimkiewicz/miniconda3/envs/agenthive_v4/lib/python3.8/site-packages/torchrl/envs/common.py", line 2028, in __init__
    self._env = self._build_env(**kwargs)  # writes the self._env attribute
  File "/home/lklimkiewicz/miniconda3/envs/agenthive_v4/lib/python3.8/site-packages/rlhive/rl_envs.py", line 44, in _build_env
    env = self.lib.make(
  File "/home/lklimkiewicz/miniconda3/envs/agenthive_v4/lib/python3.8/site-packages/gym/envs/registration.py", line 156, in make
    return registry.make(id, **kwargs)
  File "/home/lklimkiewicz/miniconda3/envs/agenthive_v4/lib/python3.8/site-packages/gym/envs/registration.py", line 101, in make
    env = spec.make(**kwargs)
  File "/home/lklimkiewicz/miniconda3/envs/agenthive_v4/lib/python3.8/site-packages/gym/envs/registration.py", line 73, in make
    env = cls(**_kwargs)
  File "/home/lklimkiewicz/miniconda3/envs/agenthive_v4/lib/python3.8/site-packages/robohive/envs/multi_task/common/franka_appliance_v1.py", line 43, in __init__
    self._setup(**kwargs)
  File "/home/lklimkiewicz/miniconda3/envs/agenthive_v4/lib/python3.8/site-packages/robohive/envs/multi_task/common/franka_appliance_v1.py", line 52, in _setup
    super()._setup(
  File "/home/lklimkiewicz/miniconda3/envs/agenthive_v4/lib/python3.8/site-packages/robohive/envs/multi_task/multi_task_base_v1.py", line 112, in _setup
    super()._setup(obs_keys=obs_keys_wt,
  File "/home/lklimkiewicz/miniconda3/envs/agenthive_v4/lib/python3.8/site-packages/robohive/envs/env_base.py", line 130, in _setup
    self._setup_rgb_encoders(self.visual_keys, device=None)
  File "/home/lklimkiewicz/miniconda3/envs/agenthive_v4/lib/python3.8/site-packages/robohive/envs/env_base.py", line 162, in _setup_rgb_encoders
    if key.startswith('rgb'):
AttributeError: 'dict' object has no attribute 'startswith'
Closing Franka_kitchen_sim(sim)

Output from pip freeze:

absl-py==2.0.0
antlr4-python3-runtime==4.9.3
appdirs==1.4.4
certifi==2023.7.22
cffi==1.16.0
charset-normalizer==3.3.1
click==8.1.7
cloudpickle==1.2.2
contourpy==1.1.1
cycler==0.12.1
Cython==0.29.36
dm-control==1.0.11
dm-env==1.6
dm-tree==0.1.8
docker-pycreds==0.4.0
fasteners==0.15
ffmpeg==1.4
filelock==3.12.4
flatten-dict==0.4.2
fonttools==4.43.1
free-mujoco-py==2.1.6
fsspec==2023.10.0
gitdb==4.0.11
GitPython==3.1.40
glfw==1.12.0
gym==0.13.0
h5py==3.7.0
hydra-core==1.3.2
idna==3.4
imageio==2.31.6
importlib-resources==6.1.0
Jinja2==3.1.2
kiwisolver==1.4.5
labmaze==1.0.6
lxml==4.9.3
MarkupSafe==2.1.3
matplotlib==3.7.3
monotonic==1.6
mpmath==1.3.0
mujoco==2.3.3
networkx==3.1
numpy==1.24.4
nvidia-cublas-cu12==12.1.3.1
nvidia-cuda-cupti-cu12==12.1.105
nvidia-cuda-nvrtc-cu12==12.1.105
nvidia-cuda-runtime-cu12==12.1.105
nvidia-cudnn-cu12==8.9.2.26
nvidia-cufft-cu12==11.0.2.54
nvidia-curand-cu12==10.3.2.106
nvidia-cusolver-cu12==11.4.5.107
nvidia-cusparse-cu12==12.1.0.106
nvidia-nccl-cu12==2.18.1
nvidia-nvjitlink-cu12==12.3.52
nvidia-nvtx-cu12==12.1.105
omegaconf==2.3.0
packaging==23.2
pathtools==0.1.2
Pillow==10.0.1
protobuf==4.24.4
psutil==5.9.6
pycparser==2.21
pyglet==2.0.9
PyOpenGL==3.1.7
pyparsing==3.1.1
python-dateutil==2.8.2
PyYAML==6.0.1
requests==2.31.0
rlhive @ git+https://github.com/facebookresearch/agenthive.git@8941ac9f911453ab84ba3e47ba7700241608d1ce
robohive==0.5.0
scipy==1.10.1
sentry-sdk==1.32.0
setproctitle==1.3.3
six==1.16.0
sk-video==1.1.10
smmap==5.0.1
sympy==1.12
tensordict @ git+https://github.com/pytorch-labs/tensordict@6a9f8e354848455054a74f61e74187bb0368677a
termcolor==2.3.0
torch==2.1.0
torchaudio==2.1.0
torchrl @ git+https://github.com/pytorch/rl.git@c7d4764e787e4be903f7b5f03b6008f00e9b23a1
torchvision==0.16.0
tqdm==4.66.1
triton==2.1.0
typing_extensions==4.8.0
urllib3==2.0.7
wandb==0.15.12
zipp==3.17.0

Which package versions to install?

Hi!

I followed the Getting Started instructions but was unable to run the examples, as agenthive does not work with the most recent versions of the dependencies.

Could you detail which package versions you have installed on your environment?
In particular for torch, torchrl, robohive, tensordict, wandb and torchvision.

Otherwise, having a requirements.txt file would definitely be a huge help.

Thanks!

Clarification on evaluation metric

Hi,
Thanks for open-sourcing this framework! I'm trying to reproduce the results of the baselines reported in the Robohive paper, and wanted to ask what is the exact metric that is averaged over 3 seeds in the Franka-expert data runs (here: https://github.com/facebookresearch/agenthive/tree/dev/scripts)?
Is it the maximum success rate over a run averaged over 3 seeds or the maximum of the average success rate over 3 seeds or something else?
The paper doesn't seem to mention exactly how the success rate of a run is decided (over many checkpoints).
Thanks!

module 'robohive.envs.multi_task.substeps1' has no attribute 'visual_obs_keys_wt'

Hi,
I get the following error when importing rlhive:

from .envs import (
File "/home/reza/Lyon/Codes/agenthive/rlhive/envs.py", line 16, in
visual_obs_keys_wt = robohive.envs.multi_task.substeps1.visual_obs_keys_wt
AttributeError: module 'robohive.envs.multi_task.substeps1' has no attribute 'visual_obs_keys_wt'

Is this a version issue?
I installed robohive main branch.
Thank you in advance

Error in creating transformed env with R3M

After the recent pull, creating transformed env with R3M leads to this error:

Traceback (most recent call last):
  File "test.py", line 26, in <module>
    td = env.rand_step()
  File "/home/rutavms/research/robohive/latest/rl/torchrl/envs/common.py", line 540, in rand_step
    return self.step(tensordict)
  File "/home/rutavms/research/robohive/latest/rl/torchrl/envs/common.py", line 343, in step
    obs_keys = set(self.observation_spec.keys())
  File "/home/rutavms/research/robohive/latest/rl/torchrl/envs/transforms/transforms.py", line 407, in observation_spec
    observation_spec = self.transform.transform_observation_spec(
  File "/home/rutavms/research/robohive/latest/rl/torchrl/envs/transforms/transforms.py", line 662, in transform_observation_spec
    observation_spec = t.transform_observation_spec(observation_spec)
  File "/home/rutavms/research/robohive/latest/rl/torchrl/envs/transforms/transforms.py", line 662, in transform_observation_spec
    observation_spec = t.transform_observation_spec(observation_spec)
  File "/home/rutavms/research/robohive/latest/rl/torchrl/envs/transforms/r3m.py", line 95, in transform_observation_spec
    observation_spec = CompositeSpec(**observation_spec)
TypeError: __new__() keywords must be strings

Here's a simple script that reproduces the error.

torchRL opening too many files while sampling

Traceback (most recent call last):
  File "sac.py", line 418, in main
    sampled_tensordict = replay_buffer.sample(args.batch_size).clone()
  File "/home/rutavms/research/robohive/latest/rl/torchrl/data/replay_buffers/replay_buffers.py", line 427, in sample
    data, info = super().sample(batch_size, return_info=True)
  File "/home/rutavms/research/robohive/latest/rl/torchrl/data/replay_buffers/replay_buffers.py", line 243, in sample
    ret = self._prefetch_queue.popleft().result()
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/concurrent/futures/_base.py", line 437, in result
    return self.__get_result()
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/concurrent/futures/_base.py", line 389, in __get_result
    raise self._exception
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/rutavms/research/robohive/latest/rl/torchrl/data/replay_buffers/replay_buffers.py", line 63, in decorated_fun
    output = fun(self, *args, **kwargs)
  File "/home/rutavms/research/robohive/latest/rl/torchrl/data/replay_buffers/replay_buffers.py", line 218, in _sample
    data = self._collate_fn(data)
  File "/home/rutavms/research/robohive/latest/rl/torchrl/data/replay_buffers/storages.py", line 438, in _collate_contiguous
    return x.to_tensordict()
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/tensordict/tensordict.py", line 1190, in to_tensordict
    {
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/tensordict/tensordict.py", line 1193, in <dictcomp>
    else value.to_tensordict()
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/tensordict/tensordict.py", line 1190, in to_tensordict
    {
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/tensordict/tensordict.py", line 1193, in <dictcomp>
    else value.to_tensordict()
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/tensordict/tensordict.py", line 1190, in to_tensordict
    {
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/tensordict/tensordict.py", line 1191, in <dictcomp>
    key: value.clone()
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/tensordict/memmap.py", line 368, in clone
    return self._tensor.clone()
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/tensordict/memmap.py", line 348, in _tensor
    return self._load_item(self._index)
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/tensordict/memmap.py", line 302, in _load_item
    memmap_array = self.memmap_array
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/tensordict/memmap.py", line 240, in _get_memmap_array
    self._memmap_array = np.memmap(
  File "/home/rutavms/miniconda3/envs/rlhive/lib/python3.8/site-packages/numpy/core/memmap.py", line 267, in __new__
    mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=start)
OSError: [Errno 24] Too many open files

This can be avoided by restricting the env_info keys to be saved in the replay buffer.

Error in running set_info_dict_reader

While running the code, it leads to an error:

Traceback (most recent call last):
  File "test.py", line 24, in <module>
    env = env.set_info_dict_reader(info_dict_reader=reader)
  File "/home/rutavms/research/robohive/latest/rl/torchrl/envs/gym_like.py", line 284, in set_info_dict_reader
    self.observation_spec[info_key] = spec
  File "/home/rutavms/research/robohive/latest/rl/torchrl/data/tensor_specs.py", line 1257, in __setitem__
    raise RuntimeError(
RuntimeError: Setting a new attribute (solved) on another device (cpu against cuda:0). All devices of CompositeSpec must match.

I locally fixed in torchRL by simply adding spec.to(self.device) here

How can I use pre-trained model in robohive?

I am using the latest version of robohive. I want to use v0.6 pretrained agent(policy) in agenthive. The file is in pickle format, and it appears that mjrl is needed to load it in robohive. mjrl is bound to an old version of mujoco, so it seems to work differently from the latest version of mujoco. For example, recently mujoco does not provide mjkey.txt (I am using mac OS).

How can I use this model in robohive?

When I run `agenthive/examples/train.py ` , there happens a KeyError: 'full_done_spec'

When I run agenthive/examples/train.py , there happens a KeyError: 'full_done_spec'

/home/dellpc/anaconda3/envs/hive/bin/python /home/dellpc/Downloads/robot/code/hive/agenthive/examples/train.py 
/home/dellpc/Downloads/robot/code/hive/agenthive/examples/train.py:9: UserWarning: 
The version_base parameter is not specified.
Please specify a compatability version level, or None.
Will assume defaults for version 1.1
  @hydra.main(config_name="sac_mixed.yaml", config_path="config")
/home/dellpc/anaconda3/envs/hive/lib/python3.9/site-packages/hydra/_internal/hydra.py:119: UserWarning: Future Hydra versions will no longer change working directory at job runtime by default.
See https://hydra.cc/docs/1.2/upgrades/1.1_to_1.2/changes_to_job_working_dir/ for more information.
  ret = run_job(
RoboHive:> Registering Arms Envs
RoboHive:> Registering Myo Envs
RoboHive:> Registering Hand Envs
RoboHive:> Registering Appliances Envs
RoboHive:> Registering Kitchen Envs
RoboHive:> Registering Multi-Task (2 subtasks) Envs
RoboHive:> Registering Multi-Task (9 subtasks) Envs
RoboHive:> Registering TCDM Envs
RoboHive:> Registering Claw Envs
RLHive:> Registering Franka Envs
Registered a new env-variant: visual_franka_slide_random-v3
Registered a new env-variant: visual_franka_slide_close-v3
Registered a new env-variant: visual_franka_slide_open-v3
Registered a new env-variant: visual_franka_micro_random-v3
Registered a new env-variant: visual_franka_micro_close-v3
Registered a new env-variant: visual_franka_micro_open-v3
RLHive:> Registering Kitchen Envs
Registered a new env-variant: visual_kitchen_knob1_off-v3
Registered a new env-variant: visual_kitchen_knob1_on-v3
Registered a new env-variant: visual_kitchen_knob2_off-v3
Registered a new env-variant: visual_kitchen_knob2_on-v3
Registered a new env-variant: visual_kitchen_knob3_off-v3
Registered a new env-variant: visual_kitchen_knob3_on-v3
Registered a new env-variant: visual_kitchen_knob4_off-v3
Registered a new env-variant: visual_kitchen_knob4_on-v3
Registered a new env-variant: visual_kitchen_light_off-v3
Registered a new env-variant: visual_kitchen_light_on-v3
Registered a new env-variant: visual_kitchen_sdoor_close-v3
Registered a new env-variant: visual_kitchen_sdoor_open-v3
Registered a new env-variant: visual_kitchen_ldoor_close-v3
Registered a new env-variant: visual_kitchen_ldoor_open-v3
Registered a new env-variant: visual_kitchen_rdoor_close-v3
Registered a new env-variant: visual_kitchen_rdoor_open-v3
Registered a new env-variant: visual_kitchen_micro_close-v3
Registered a new env-variant: visual_kitchen_micro_open-v3
Registered a new env-variant: visual_FK1_RelaxFixed-v4
RLHive:> Registering Arm Envs
Registered a new env-variant: visual_door-v1
Registered a new env-variant: visual_hammer-v1
Registered a new env-variant: visual_pen-v1
Registered a new env-variant: visual_relocate-v1
RLHive:> Registering Myo Envs
Registered a new env-variant: visual_motorFingerReachFixed-v0
rendering device: 0, device is cuda:0
RoboHive:> For environment credits, please cite -
    RoboHive: A unified framework for robot learning | https://sites.google.com/view/robohive
        Code: https://github.com/vikashplus/robohive/stargazers (add a star to support the project)
    
[2023-12-09 15:05:21,505][OpenGL.acceleratesupport][INFO] - No OpenGL_accelerate module loaded: No module named 'OpenGL_accelerate'
[2023-12-09 15:05:21,523][absl][INFO] - MUJOCO_GL=egl, attempting to import specified OpenGL backend.
[2023-12-09 15:05:21,526][absl][INFO] - MuJoCo library version is: 2.3.3
Warning: Unused kwargs found: {'frameskip': 1, 'return_dict': True}
Configuring a new session for Franka_kitchen_sim(sim)
Reading robot-configurations from /home/dellpc/anaconda3/envs/hive/lib/python3.9/site-packages/robohive/envs/multi_task/substeps1/../common/slidecabinet/franka_slidecabinet.config
Configuring component franka
Configuring component slidecabinet
dict_keys(['rgb:right_cam:224x224:2d', 'rgb:left_cam:224x224:2d'])
rgb:right_cam:224x224:2d
dict_keys(['rgb:right_cam:224x224:2d', 'rgb:left_cam:224x224:2d'])
rgb:left_cam:224x224:2d
Using 224x224 visual inputs with 2d encoder
Resetting Franka_kitchen_sim(sim)
Error executing job with overrides: []
Traceback (most recent call last):
  File "/home/dellpc/Downloads/robot/code/hive/agenthive/examples/train.py", line 12, in main
    train_sac(args)
  File "/home/dellpc/Downloads/robot/code/hive/agenthive/examples/sac.py", line 284, in main
    train_env = make_env(num_envs=args.env_per_collector, task=args.task, **env_configs)
  File "/home/dellpc/Downloads/robot/code/hive/agenthive/examples/sac.py", line 104, in make_env
    base_env = RoboHiveEnv(task, device=device)
  File "/home/dellpc/anaconda3/envs/hive/lib/python3.9/site-packages/torchrl/envs/libs/gym.py", line 399, in __call__
    instance: GymWrapper = super().__call__(*args, **kwargs)
  File "/home/dellpc/anaconda3/envs/hive/lib/python3.9/site-packages/torchrl/envs/common.py", line 137, in __call__
    instance: EnvBase = super().__call__(*args, **kwargs)
  File "/home/dellpc/anaconda3/envs/hive/lib/python3.9/site-packages/torchrl/envs/libs/gym.py", line 957, in __init__
    super().__init__(**kwargs)
  File "/home/dellpc/anaconda3/envs/hive/lib/python3.9/site-packages/torchrl/envs/libs/gym.py", line 508, in __init__
    super().__init__(**kwargs)
  File "/home/dellpc/anaconda3/envs/hive/lib/python3.9/site-packages/torchrl/envs/common.py", line 2172, in __init__
    self._make_specs(self._env)  # writes the self._env attribute
  File "/home/dellpc/Downloads/robot/code/hive/agenthive/rlhive/rl_envs.py", line 114, in _make_specs
    rollout = self.rollout(2).get("next").exclude("done", "reward")[0]
  File "/home/dellpc/anaconda3/envs/hive/lib/python3.9/site-packages/torchrl/envs/common.py", line 1797, in rollout
    tensordict = self.reset()
  File "/home/dellpc/anaconda3/envs/hive/lib/python3.9/site-packages/torchrl/envs/common.py", line 1495, in reset
    return self._reset_proc_data(tensordict, tensordict_reset)
  File "/home/dellpc/anaconda3/envs/hive/lib/python3.9/site-packages/torchrl/envs/common.py", line 1498, in _reset_proc_data
    self._complete_done(self.full_done_spec, tensordict_reset)
  File "/home/dellpc/anaconda3/envs/hive/lib/python3.9/site-packages/torchrl/envs/common.py", line 937, in full_done_spec
    return self.output_spec["full_done_spec"]
  File "/home/dellpc/anaconda3/envs/hive/lib/python3.9/site-packages/torchrl/data/tensor_specs.py", line 3271, in __getitem__
    return self._specs[idx_unravel]
KeyError: 'full_done_spec'

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.

Process finished with exit code 1

Integration with torchRL

I modified the getting started example to run torchrl with robohive. Here's the modified example,

import torch
import robohive
from torchrl.envs import RoboHiveEnv
from torchrl.envs import ParallelEnv, TransformedEnv, R3MTransform

from rlhive.rl_envs import make_r3m_env
from torchrl.collectors.collectors import SyncDataCollector, MultiaSyncDataCollector, RandomPolicy
# make sure your ParallelEnv is inside the `if __name__ == "__main__":` condition, otherwise you'll
# be creating an infinite tree of subprocesses
if __name__ == "__main__":
    device = torch.device("cpu") # could be 'cuda:0'
    env_name = 'FrankaReachFixed-v0'
    env = make_r3m_env(env_name, model_name="resnet18", download=True)
    assert env.device == device
    # example of a rollout
    print(env.rollout(3))

Additionally, I changed this line to filter out the visual keys while concatenating R3M transform with other keys to

vec_keys = [k for k in base_env.observation_spec.keys() if ((k != "pixels") and ("visual" not in k))]

This leads to an error -

Traceback (most recent call last):
  File "test.py", line 16, in <module>
    print(env.rollout(3))
  File "/Users/rutavms/miniconda3/envs/agenthive/lib/python3.8/site-packages/torchrl/envs/common.py", line 1797, in rollout
    tensordict = self.reset()
  File "/Users/rutavms/miniconda3/envs/agenthive/lib/python3.8/site-packages/torchrl/envs/common.py", line 1480, in reset
    tensordict_reset = self._reset(tensordict, **kwargs)
  File "/Users/rutavms/miniconda3/envs/agenthive/lib/python3.8/site-packages/torchrl/envs/transforms/transforms.py", line 760, in _reset
    tensordict_reset = self.transform._reset(tensordict, tensordict_reset)
  File "/Users/rutavms/miniconda3/envs/agenthive/lib/python3.8/site-packages/torchrl/envs/transforms/transforms.py", line 1020, in _reset
    tensordict_reset = t._reset(tensordict, tensordict_reset)
  File "/Users/rutavms/miniconda3/envs/agenthive/lib/python3.8/site-packages/torchrl/envs/transforms/transforms.py", line 3694, in _reset
    tensordict_reset = self._call(tensordict_reset)
  File "/Users/rutavms/miniconda3/envs/agenthive/lib/python3.8/site-packages/torchrl/envs/transforms/transforms.py", line 3676, in _call
    out_tensor = torch.cat(values, dim=self.dim)
  File "/Users/rutavms/miniconda3/envs/agenthive/lib/python3.8/site-packages/tensordict/tensordict.py", line 2785, in __torch_function__
    return TD_HANDLED_FUNCTIONS[func](*args, **kwargs)
  File "/Users/rutavms/miniconda3/envs/agenthive/lib/python3.8/site-packages/tensordict/tensordict.py", line 5346, in _cat
    batch_size = list(list_of_tensordicts[0].batch_size)
AttributeError: 'Tensor' object has no attribute 'batch_size'

I am using the following versions of packages: robohive==0.6.0 tensordict==0.2.1 torchrl==0.2.1. Which version did you use? @vmoens

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.