yxyang / locomotion_simulation

MIT License
84 stars 24 forks source link

Few issues due to use of deprecated api #8

Open pulak-gautam opened 5 months ago

pulak-gautam commented 5 months ago

Whilst trying to get up the simulation running, I encountered few trivial issues:

  1. locomotion/__init__.py", line 6, in register if env_id in registry.env_specs: AttributeError: 'dict' object has no attribute 'env_specs'

Patch to fix:

diff --git a/locomotion/__init__.py b/locomotion/__init__.py
index f1a0f8d..4994b53 100644
--- a/locomotion/__init__.py
+++ b/locomotion/__init__.py
@@ -3,7 +3,7 @@ import gym
 from gym.envs.registration import registry, make, spec

 def register(env_id, *args, **kvargs):
-  if env_id in registry.env_specs:
+  if env_id not in gym.envs.registry:
     return
   else:
     return gym.envs.registration.register(env_id, *args, **kvargs)
  1. locomotion/robots/minitaur.py", line 168, in __init__ self._observation_history = collections.deque(maxlen=100) AttributeError: module 'collections.abc' has no attribute 'deque'

Patch to fix:

diff --git a/locomotion/robots/minitaur.py b/locomotion/robots/minitaur.py
index 866a999..ff18169 100644
--- a/locomotion/robots/minitaur.py
+++ b/locomotion/robots/minitaur.py
@@ -189,17 +189,17 @@ class Minitaur(object):
       raise ValueError("on_rack and reset_at_current_position "
                        "cannot be enabled together")

-    if isinstance(motor_kp, (collections.Sequence, np.ndarray)):
+    if isinstance(motor_kp, (collections.abc.Sequence, np.ndarray)):
       self._motor_kps = np.asarray(motor_kp)
     else:
       self._motor_kps = np.full(num_motors, motor_kp)

-    if isinstance(motor_kd, (collections.Sequence, np.ndarray)):
+    if isinstance(motor_kd, (collections.abc.Sequence, np.ndarray)):
       self._motor_kds = np.asarray(motor_kd)
     else:
       self._motor_kds = np.full(num_motors, motor_kd)

-    if isinstance(motor_torque_limits, (collections.Sequence, np.ndarray)):
+    if isinstance(motor_torque_limits, (collections.abc.Sequence, np.ndarray)):
       self._motor_torque_limits = np.asarray(motor_torque_limits)
     elif motor_torque_limits is None:
yxyang commented 5 months ago

Thank you for your efforts! Can you submit a pull request?

pulak-gautam commented 5 months ago

These are breaking changes in gym (first one) and in python 3.10 (second one). If one follows requirements.txt and/or downgrades to python <= 3.9, it should work I think. I will try to make a PR with these changes implemented in a modular way to have the code running even if someone's running with the older api/versions (for which it was written). Would that be fine?