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

[BugFix] Fix RoboHiveEnv tests #2062

Merged
merged 17 commits into from
Apr 15, 2024

Conversation

sriramsk1999
Copy link
Contributor

Description

  • Make RoboHiveEnv tests actually run correctly when executed
  • Fixed a bug in testing of envs without cameras
  • Refactor and simplify test case

Motivation and Context

Currently, the tests for RoboHiveEnv aren't actually executing correctly. When the env is instantiated, the from_pixels key isn't actually used, and none of the envs are tested with from_pixels=True.

After the test code is fixed, I get 9 failures for the RoboHive tests, all of which seem to be caused by an issue with DKitty environments.

Short Test log:

================================================= short test summary info =================================================
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyOrientFixed-v0-True] - gym.error.Error: A module (A) was specified for the environment but was not found, make sure the package is installed ...
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyOrientRandom-v0-True] - gym.error.Error: A module (A) was specified for the environment but was not found, make sure the package is installed ...
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyOrientRandom_v2d-v0-True] - gym.error.Error: A module (A) was specified for the environment but was not found, make sure the package is installed ...
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyStandFixed-v0-True] - gym.error.Error: A module (A) was specified for the environment but was not found, make sure the package is installed ...
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyStandRandom-v0-True] - gym.error.Error: A module (A) was specified for the environment but was not found, make sure the package is installed ...
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyStandRandom_v2d-v0-True] - gym.error.Error: A module (A) was specified for the environment but was not found, make sure the package is installed ...
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyWalkFixed-v0-True] - gym.error.Error: A module (A) was specified for the environment but was not found, make sure the package is installed ...
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyWalkRandom-v0-True] - gym.error.Error: A module (A) was specified for the environment but was not found, make sure the package is installed ...
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyWalkRandom_v2d-v0-True] - gym.error.Error: A module (A) was specified for the environment but was not found, make sure the package is installed ...

Full traceback:

-------------------------------------------------- Captured stdout call ---------------------------------------------------
Registered a new env-variant: A:head-A:left-A:right-A:tail-A:tracki-A:tracki-DKittyWalkRandom-v0
________________________________ TestRoboHive.test_robohive[DKittyWalkRandom_v2d-v0-True] _________________________________
Traceback (most recent call last):
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/gym/envs/registration.py", line 120, in spec
    importlib.import_module(mod_name)
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'A'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/_pytest/runner.py", line 342, in from_call
    result: Optional[TResult] = func()
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/_pytest/runner.py", line 263, in <lambda>
    lambda: ihook(item=item, **kwds), when=when, reraise=reraise
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/pluggy/_hooks.py", line 501, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/pluggy/_manager.py", line 119, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/pluggy/_callers.py", line 138, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/pluggy/_callers.py", line 121, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/_pytest/threadexception.py", line 87, in pytest_runtest_call
    yield from thread_exception_runtest_hook()
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/_pytest/threadexception.py", line 63, in thread_exception_runtest_hook
    yield
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/pluggy/_callers.py", line 121, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/_pytest/unraisableexception.py", line 90, in pytest_runtest_call
    yield from unraisable_exception_runtest_hook()
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/_pytest/unraisableexception.py", line 65, in unraisable_exception_runtest_hook
    yield
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/pluggy/_callers.py", line 121, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/_pytest/logging.py", line 839, in pytest_runtest_call
    yield from self._runtest_for(item, "call")
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/_pytest/logging.py", line 822, in _runtest_for
    yield
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/pluggy/_callers.py", line 121, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/_pytest/capture.py", line 882, in pytest_runtest_call
    return (yield)
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/pluggy/_callers.py", line 121, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/_pytest/skipping.py", line 256, in pytest_runtest_call
    return (yield)
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/pluggy/_callers.py", line 102, in _multicall
    res = hook_impl.function(*args)
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/_pytest/runner.py", line 178, in pytest_runtest_call
    raise e
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/_pytest/runner.py", line 170, in pytest_runtest_call
    item.runtest()
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/_pytest/python.py", line 1831, in runtest
    self.ihook.pytest_pyfunc_call(pyfuncitem=self)
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/pluggy/_hooks.py", line 501, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/pluggy/_manager.py", line 119, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/pluggy/_callers.py", line 138, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/pluggy/_callers.py", line 102, in _multicall
    res = hook_impl.function(*args)
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/_pytest/python.py", line 194, in pytest_pyfunc_call
    result = testfunction(**testargs)
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/home/sriramsk/desktop/torchrl/test/test_libs.py", line 3355, in test_robohive
    env = RoboHiveEnv(envname, from_pixels=from_pixels)
  File "/home/sriramsk/desktop/torchrl/torchrl/envs/libs/robohive.py", line 54, in __call__
    instance: RoboHiveEnv = super().__call__(*args, **kwargs)
  File "/home/sriramsk/desktop/torchrl/torchrl/envs/libs/gym.py", line 543, in __call__
    instance: GymWrapper = super().__call__(*args, **kwargs)
  File "/home/sriramsk/desktop/torchrl/torchrl/envs/common.py", line 166, in __call__
    instance: EnvBase = super().__call__(*args, **kwargs)
  File "/home/sriramsk/desktop/torchrl/torchrl/envs/libs/gym.py", line 1277, in __init__
    super().__init__(**kwargs)
  File "/home/sriramsk/desktop/torchrl/torchrl/envs/libs/gym.py", line 731, in __init__
    super().__init__(**kwargs)
  File "/home/sriramsk/desktop/torchrl/torchrl/envs/common.py", line 2993, in __init__
    self._env = self._build_env(**kwargs)  # writes the self._env attribute
  File "/home/sriramsk/desktop/torchrl/torchrl/envs/libs/robohive.py", line 201, in _build_env
    env = self.lib.make(
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/gym/envs/registration.py", line 156, in make
    return registry.make(id, **kwargs)
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/gym/envs/registration.py", line 100, in make
    spec = self.spec(path)
  File "/home/sriramsk/miniconda3/envs/torch_rl/lib/python3.9/site-packages/gym/envs/registration.py", line 123, in spec
    raise error.Error('A module ({}) was specified for the environment but was not found, make sure the package is installed with `pip install` before calling `gym.make()`'.format(mod_name))
gym.error.Error: A module (A) was specified for the environment but was not found, make sure the package is installed with `pip install` before calling `gym.make()`

Copy link

pytorch-bot bot commented Apr 7, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/2062

Note: Links to docs will display an error until the docs builds have been completed.

❌ 9 New Failures, 3 Unrelated Failures

As of commit 772e893 with merge base 0d00748 (image):

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 7, 2024
@vmoens vmoens changed the title [BUGFIX]: Fix RoboHiveEnv tests [BugFix]: Fix RoboHiveEnv tests Apr 7, 2024
@vmoens vmoens added the Environments Adds or modifies an environment wrapper label Apr 7, 2024
@vmoens
Copy link
Contributor

vmoens commented Apr 7, 2024

LGTM
Let's wait until I fix the CI with this
#2063

@vmoens vmoens changed the title [BugFix]: Fix RoboHiveEnv tests [BugFix] Fix RoboHiveEnv tests Apr 7, 2024
@vmoens vmoens added the Tests Incomplete or broken unit tests label Apr 7, 2024
@vmoens
Copy link
Contributor

vmoens commented Apr 7, 2024

The tests are still failing because of missing envs, e.g. DKittyOrientFixed-v0
@vikashplus here is the complete list

FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyOrientFixed-v0-True] - gym.error.UnregisteredEnv: No registered env with id: DKittyOrientFixed-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyOrientFixed-v0-False] - gym.error.UnregisteredEnv: No registered env with id: DKittyOrientFixed-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyOrientRandom-v0-True] - gym.error.UnregisteredEnv: No registered env with id: DKittyOrientRandom-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyOrientRandom-v0-False] - gym.error.UnregisteredEnv: No registered env with id: DKittyOrientRandom-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyOrientRandom_v2d-v0-True] - gym.error.UnregisteredEnv: No registered env with id: DKittyOrientRandom_v2d-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyOrientRandom_v2d-v0-False] - gym.error.UnregisteredEnv: No registered env with id: DKittyOrientRandom_v2d-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyStandFixed-v0-True] - gym.error.UnregisteredEnv: No registered env with id: DKittyStandFixed-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyStandFixed-v0-False] - gym.error.UnregisteredEnv: No registered env with id: DKittyStandFixed-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyStandRandom-v0-True] - gym.error.UnregisteredEnv: No registered env with id: DKittyStandRandom-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyStandRandom-v0-False] - gym.error.UnregisteredEnv: No registered env with id: DKittyStandRandom-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyStandRandom_v2d-v0-True] - gym.error.UnregisteredEnv: No registered env with id: DKittyStandRandom_v2d-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyStandRandom_v2d-v0-False] - gym.error.UnregisteredEnv: No registered env with id: DKittyStandRandom_v2d-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyWalkFixed-v0-True] - gym.error.UnregisteredEnv: No registered env with id: DKittyWalkFixed-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyWalkFixed-v0-False] - gym.error.UnregisteredEnv: No registered env with id: DKittyWalkFixed-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyWalkRandom-v0-True] - gym.error.UnregisteredEnv: No registered env with id: DKittyWalkRandom-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyWalkRandom-v0-False] - gym.error.UnregisteredEnv: No registered env with id: DKittyWalkRandom-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyWalkRandom_v2d-v0-True] - gym.error.UnregisteredEnv: No registered env with id: DKittyWalkRandom_v2d-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[DKittyWalkRandom_v2d-v0-False] - gym.error.UnregisteredEnv: No registered env with id: DKittyWalkRandom_v2d-v0
FAILED test/test_libs.py::TestRoboHive::test_robohive[FK1_CloseAllFixed-v4-True] - gym.error.UnregisteredEnv: No registered env with id: FK1_CloseAllFixed-v4
FAILED test/test_libs.py::TestRoboHive::test_robohive[FK1_CloseAllFixed-v4-False] - gym.error.UnregisteredEnv: No registered env with id: FK1_CloseAllFixed-v4

@vikashplus
Copy link

I checked things at the RoboHive's end. All things line up well. Do you know where the problem is?

(robohive) vikashplus@vikashplus-m3:~/Repos/robohive$ ipython
In [1]: import robohive
RoboHive:> Registering Arms Envs
RoboHive:> Registering Myo Envs
RoboHive:> Registering Hand Envs
RoboHive:> Registering Claw Envs
RoboHive:> Registering Appliances Envs
RoboHive:> Registering Multi-Task (2 subtasks) Envs
RoboHive:> Registering FrankaKitchen (FK1) Envs
RoboHive:> Registering Multi-Task (9 subtasks) Envs
RoboHive:> Registering Quadruped Envs

In [3]: import gymnasium as gym

In [4]: ee = gym.make("DKittyWalkFixed-v0")

Here is another one

(robohive) vikashplus@vikashplus-m3:~/Repos/robohive/robohive$ python tests/test_quads.py 
RoboHive:> Registering Arms Envs
RoboHive:> Registering Myo Envs
RoboHive:> Registering Hand Envs
RoboHive:> Registering Claw Envs
RoboHive:> Registering Appliances Envs
RoboHive:> Registering Multi-Task (2 subtasks) Envs
RoboHive:> Registering FrankaKitchen (FK1) Envs
RoboHive:> Registering Multi-Task (9 subtasks) Envs
RoboHive:> Registering Quadruped Envs

=================================
Testing module::  Quadruped Suite
Testing env:  DKittyOrientFixed-v0
    ROBEL: RObotics BEnchmarks for Learning with low-cost robots
        Michael Ahn, Henry Zhu, Kristian Hartikainen, Hugo Ponte
        Abhishek Gupta, Sergey Levine, Vikash Kumar
        CoRL-2019 | https://sites.google.com/view/roboticsbenchmarks/
    
Testing env:  DKittyOrientRandom-v0
Testing env:  DKittyOrientRandom_v2d-v0
WARNING:absl:ARB_clip_control unavailable while mjDEPTH_ZEROFAR requested, depth accuracy will be limited
Testing env:  DKittyStandFixed-v0
Testing env:  DKittyStandRandom-v0
Testing env:  DKittyStandRandom_v2d-v0
Testing env:  DKittyWalkFixed-v0
Testing env:  DKittyWalkRandom-v0
Testing env:  DKittyWalkRandom_v2d-v0
.
----------------------------------------------------------------------
Ran 1 test in 8.394s

OK

@sriramsk1999
Copy link
Contributor Author

Found a fix for the issue! The camera names for the DKitty env is causing a problem.

['A:trackingZ', 'A:trackingY', 'A:headCam', 'A:tailCam', 'A:leftCam', 'A:rightCam']

The colon in the camera name is causing some issue, I'm not sure what that is. But adding cams = [i.replace("A:", "A_") for i in cams] fixes the tests. All RoboHive tests are now passing on my machine.

@@ -233,6 +233,7 @@ def register_visual_env(cls, env_name, cams):

if not len(cams):
raise RuntimeError("Cannot create a visual envs without cameras.")
cams = [i.replace("A:", "A_") for i in cams]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if this is something you think should be changed at RoboHive's end.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see your comment above. I believe A:trackingZ is a valid string for MuJoCo as well as RoboHive.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would encourage using environment (and derived camera etc) names that are conventional and can be used for serialization. I can imagine someone using the camera name within the experiment name and use the experiment name to save things on disk

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have name a note of this for the next release.

@sriramsk1999
Copy link
Contributor Author

Should we merge this PR for now and remove the workaround after the camera names are updated in robohive in the next release? That seems like a reasonable approach.

@vikashplus
Copy link

I'd vote that we go ahead with the proposed workaround. I'll make sure that we land this change in the next RoboHive release.

@@ -3338,37 +3338,28 @@ class TestRoboHive:
# In the CI, robohive should not coexist with other libs so that's fine.
# Locally these imports can be annoying, especially given the amount of

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RoboHive's prints can be contorled using an env variable

ROBOHIVE_VERBOSITY=ALL/INFO/(WARN)/ERROR/ONCE/ALWAYS/SILENT

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure
The goal of this comment is for anyone running the tests and seeing loads of messages from imports. That could be a bit surprising and annoying. We can add that there's a strategy to silence them. I guess one could argue that importing a library should not print anything by default though...

@vmoens vmoens added the bc breaking backward compatibility breaking change label Apr 15, 2024
@vmoens
Copy link
Contributor

vmoens commented Apr 15, 2024

I isolated the "info" in the corresponding entry in the output tensordict

@vmoens vmoens merged commit bedd2b7 into pytorch:main Apr 15, 2024
54 of 66 checks passed
vmoens pushed a commit that referenced this pull request Apr 15, 2024
Co-authored-by: Vincent Moens <[email protected]>
(cherry picked from commit bedd2b7)
@sriramsk1999
Copy link
Contributor Author

I pulled the latest changes, upgraded robohive to 0.7, and replaced gym with gymnasium. The older failures are fixed, but a new set of tests are now failing.

================================================================================================================ short test summary info =================================================================================================================
FAILED test/test_libs.py::TestRoboHive::test_robohive[door-v1-False] - ValueError: too many values to unpack (expected 2)
FAILED test/test_libs.py::TestRoboHive::test_robohive[door-v1-True] - ValueError: too many values to unpack (expected 2)
FAILED test/test_libs.py::TestRoboHive::test_robohive[hammer-v1-False] - ValueError: too many values to unpack (expected 2)
FAILED test/test_libs.py::TestRoboHive::test_robohive[hammer-v1-True] - ValueError: too many values to unpack (expected 2)
FAILED test/test_libs.py::TestRoboHive::test_robohive[pen-v1-False] - ValueError: too many values to unpack (expected 2)
FAILED test/test_libs.py::TestRoboHive::test_robohive[pen-v1-True] - ValueError: too many values to unpack (expected 2)
FAILED test/test_libs.py::TestRoboHive::test_robohive[relocate-v1-False] - ValueError: too many values to unpack (expected 2)
FAILED test/test_libs.py::TestRoboHive::test_robohive[relocate-v1-True] - ValueError: too many values to unpack (expected 2)
=============================================================================================== 8 failed, 1034 passed, 11432 warnings in 921.68s (0:15:21) ===============================================================================================

Full traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sriramsk/desktop/torchrl/torchrl/envs/libs/robohive.py", line 62, in __call__
    instance._refine_specs()
  File "/home/sriramsk/desktop/torchrl/torchrl/envs/libs/robohive.py", line 303, in _refine_specs
    rollout = self.rollout(2, return_contiguous=False).get("next")
  File "/home/sriramsk/desktop/torchrl/torchrl/envs/common.py", line 2528, in rollout
    tensordict = self.reset()
  File "/home/sriramsk/desktop/torchrl/torchrl/envs/common.py", line 2105, in reset
    tensordict_reset = self._reset(tensordict, **kwargs)
  File "/home/sriramsk/desktop/torchrl/torchrl/envs/libs/gym.py", line 1165, in _reset
    return super()._reset(tensordict, **kwargs)
  File "/home/sriramsk/desktop/torchrl/torchrl/envs/gym_like.py", line 357, in _reset
    obs, info = self._reset_output_transform(self._env.reset(**kwargs))
ValueError: too many values to unpack (expected 2)

@vikashplus
Copy link

vikashplus commented Apr 15, 2024

RoboHive is returning 2 values. See here -
https://github.com/vikashplus/robohive/blob/main/robohive/envs/env_base.py#L513
So maybe something to do with the self._reset_output_transform ?

@vmoens
Copy link
Contributor

vmoens commented Apr 15, 2024

Nope it seems that in this case robohive is returning only one (at least torchrl cannot see two things coming out of reset)
The envs are hammer, door, relocate and pen.
This commit solves it, and as you can see it does so by providing an empty dict if there is only one output

@vikashplus
Copy link

vikashplus commented Apr 15, 2024

this line kinda does the same thing directly in the base class that uses @implement_for("gymnasium") to ensure compatibility

  • for the hammer, door, relocate and pen envs (v1s), I'm overwriting the reset function. Does the @implement_for("gymnasium") functionality get inherited when someone overwrites a function, or are we expecting users to explicitly apply it again on the new function declaration?
  • Let's say it doesn't, do you know why it's not affecting other envs (e.g. 1) where we use the same trick for gym compatibility?

@vmoens
Copy link
Contributor

vmoens commented Apr 29, 2024

Here's my understanding of what is happening: the reset you pointed in env_base does indeed return 2 values but as you were asking just above the new method doesn't and @implement_for doesn't catch that
The way we deal with this in RL is to have one _process_reset_data method or similar that we tune to the gym version and never touch. Example

class EnvBase:
    @implement_for("gymnasium")
    def _process_reset_data(self, reset_data):
        if not isinstance(reset_data, tuple) or not (len(reset_data) == 2 and isinstance(reset_data[1], dict)):
            return reset_data, {}
        return reset_data
    @implement_for("gym", None, 0.25) # or whatever other version
    def _process_reset_data(self, reset_data):
        if isinstance(reset_data, tuple) and len(reset_data) == 2 and isinstance(reset_data[1], dict):
            # throw the dict away
            return reset_data[0]
        return reset_data
	def reset(self):
        # your code here
        return self._process_reset_data(reset_data)
class OtherEnv(EnvBase):
	def reset(self):
        # your other code here
        return self._process_reset_data(reset_data)

Does that help?

@sriramsk1999 sriramsk1999 deleted the bugfix/fix-robohive-tests branch April 29, 2024 12:47
@vikashplus
Copy link

Thanks @vmoens for digging in. This indeed confirms the theory.

I was also surprised by why it's not affecting other envs (e.g. 1. And there is a clever answer hidden there. Instead of returning the values, these other envs rely on the super().reset() for return for which implement_for works perfectly.
In essence, using super().reset() does the same thing as you suggested. I feel it's a bit more elegant, I'll document it and also add a test for it. I'll change that 4 envs that didn't follow this convention and then RoboHive will hopefully take another step toward torchRL compatibility.

@vmoens
Copy link
Contributor

vmoens commented Apr 30, 2024

super() can defo do the job!
We don't use it in RL because that would make the entire Env API dependent on some (nasty) gym stuff + that would make the whole API more complex (people that don't use gym or different versions of gym should not care about that).
But in Robohive's case I guess super() is the most sensible option

@vikashplus
Copy link

Perfect. Thanks for pairing with me to better understand this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bc breaking backward compatibility breaking change CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Environments Adds or modifies an environment wrapper Tests Incomplete or broken unit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants