diff --git a/carl/envs/dmc/README.md b/carl/envs/dmc/README.md new file mode 100644 index 00000000..1ab21757 --- /dev/null +++ b/carl/envs/dmc/README.md @@ -0,0 +1,10 @@ +# Headless Rendering +If you have problems with OpenGL, this helped: +Set this in your script +```python +os.environ['DISABLE_MUJOCO_RENDERING'] = '1' +os.environ['MUJOCO_GL'] = 'osmesa' +os.environ['PYOPENGL_PLATFORM'] = 'osmesa' +``` + +And set ErrorChecker to None in `OpenGL/raw/GL/_errors.py`. \ No newline at end of file diff --git a/carl/envs/dmc/carl_dm_finger.py b/carl/envs/dmc/carl_dm_finger.py index ed8469a5..a30ae3a4 100644 --- a/carl/envs/dmc/carl_dm_finger.py +++ b/carl/envs/dmc/carl_dm_finger.py @@ -9,7 +9,7 @@ from carl.utils.types import Context, Contexts DEFAULT_CONTEXT = { - "gravity": -9.81, # Gravity is disabled via flag + "gravity": 9.81, # Gravity is disabled via flag "friction_tangential": 1, # Scaling factor for tangential friction of all geoms (objects) "friction_torsional": 1, # Scaling factor for torsional friction of all geoms (objects) "friction_rolling": 1, # Scaling factor for rolling friction of all geoms (objects) @@ -30,7 +30,7 @@ } CONTEXT_BOUNDS = { - "gravity": (-np.inf, -0.1, float), + "gravity": (0.1, np.inf, float), "friction_tangential": (0, np.inf, float), "friction_torsional": (0, np.inf, float), "friction_rolling": (0, np.inf, float), diff --git a/carl/envs/dmc/carl_dm_fish.py b/carl/envs/dmc/carl_dm_fish.py index b7886baa..973fab16 100644 --- a/carl/envs/dmc/carl_dm_fish.py +++ b/carl/envs/dmc/carl_dm_fish.py @@ -9,7 +9,7 @@ from carl.utils.types import Context, Contexts DEFAULT_CONTEXT = { - "gravity": -9.81, # Gravity is disabled via flag + "gravity": 9.81, # Gravity is disabled via flag "friction_tangential": 1, # Scaling factor for tangential friction of all geoms (objects) "friction_torsional": 1, # Scaling factor for torsional friction of all geoms (objects) "friction_rolling": 1, # Scaling factor for rolling friction of all geoms (objects) @@ -26,7 +26,7 @@ } CONTEXT_BOUNDS = { - "gravity": (-np.inf, -0.1, float), + "gravity": (0.1, np.inf, float), "friction_tangential": (0, np.inf, float), "friction_torsional": (0, np.inf, float), "friction_rolling": (0, np.inf, float), diff --git a/carl/envs/dmc/carl_dm_quadruped.py b/carl/envs/dmc/carl_dm_quadruped.py index 29554d98..7949b356 100644 --- a/carl/envs/dmc/carl_dm_quadruped.py +++ b/carl/envs/dmc/carl_dm_quadruped.py @@ -9,7 +9,7 @@ from carl.utils.types import Context, Contexts DEFAULT_CONTEXT = { - "gravity": -9.81, + "gravity": 9.81, "friction_tangential": 1.0, # Scaling factor for tangential friction of all geoms (objects) "friction_torsional": 1.0, # Scaling factor for torsional friction of all geoms (objects) "friction_rolling": 1.0, # Scaling factor for rolling friction of all geoms (objects) @@ -26,7 +26,7 @@ } CONTEXT_BOUNDS = { - "gravity": (-np.inf, -0.1, float), + "gravity": (0.1, np.inf, float), "friction_tangential": (0, np.inf, float), "friction_torsional": (0, np.inf, float), "friction_rolling": (0, np.inf, float), diff --git a/carl/envs/dmc/carl_dm_walker.py b/carl/envs/dmc/carl_dm_walker.py index 524aa2a3..6b9d0662 100644 --- a/carl/envs/dmc/carl_dm_walker.py +++ b/carl/envs/dmc/carl_dm_walker.py @@ -9,7 +9,7 @@ from carl.utils.types import Context, Contexts DEFAULT_CONTEXT = { - "gravity": -9.81, + "gravity": 9.81, "friction_tangential": 1.0, # Scaling factor for tangential friction of all geoms (objects) "friction_torsional": 1.0, # Scaling factor for torsional friction of all geoms (objects) "friction_rolling": 1.0, # Scaling factor for rolling friction of all geoms (objects) @@ -26,7 +26,7 @@ } CONTEXT_BOUNDS = { - "gravity": (-np.inf, -0.1, float), + "gravity": (0.1, np.inf, float), "friction_tangential": (0, np.inf, float), "friction_torsional": (0, np.inf, float), "friction_rolling": (0, np.inf, float), diff --git a/carl/envs/dmc/dmc_tasks/__init__.py b/carl/envs/dmc/dmc_tasks/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/carl/envs/dmc/dmc_tasks/finger.py b/carl/envs/dmc/dmc_tasks/finger.py index 9bad7621..2c02cbb5 100644 --- a/carl/envs/dmc/dmc_tasks/finger.py +++ b/carl/envs/dmc/dmc_tasks/finger.py @@ -45,25 +45,34 @@ def check_constraints( limb_length_1: float, x_spinner: float = 0.2, x_finger: float = -0.2, -) -> None: + raise_error: bool = False, + **kwargs: Any +) -> bool: + is_okay = True spinner_half_length = spinner_length / 2 # Check if spinner collides with finger hinge distance_spinner_to_fingerhinge = (x_spinner - x_finger) - spinner_half_length if distance_spinner_to_fingerhinge < 0: - raise ValueError( - f"Distance finger to spinner ({distance_spinner_to_fingerhinge}) not big enough, " - f"spinner can't spin. Decrease spinner_length ({spinner_length})." - ) + is_okay = False + if raise_error: + raise ValueError( + f"Distance finger to spinner ({distance_spinner_to_fingerhinge}) not big enough, " + f"spinner can't spin. Decrease spinner_length ({spinner_length})." + ) # Check if finger can reach spinner (distance should be negative) distance_fingertip_to_spinner = (x_spinner - spinner_half_length) - ( x_finger + limb_length_0 + limb_length_1 ) if distance_fingertip_to_spinner > 0: - raise ValueError( - f"Finger cannot reach spinner ({distance_fingertip_to_spinner}). Increase either " - f"limb_length_0, limb_length_1 or spinner_length." - ) + is_okay = False + if raise_error: + raise ValueError( + f"Finger cannot reach spinner ({distance_fingertip_to_spinner}). Increase either " + f"limb_length_0, limb_length_1 or spinner_length." + ) + + return is_okay def get_finger_xml_string( @@ -98,6 +107,7 @@ def get_finger_xml_string( x_spinner=x_spinner, x_finger=x_finger, spinner_length=spinner_length, + raise_error=True ) proximal_to = -limb_length_0 diff --git a/carl/envs/dmc/dmc_tasks/utils.py b/carl/envs/dmc/dmc_tasks/utils.py index ab449618..f5199955 100644 --- a/carl/envs/dmc/dmc_tasks/utils.py +++ b/carl/envs/dmc/dmc_tasks/utils.py @@ -162,9 +162,9 @@ def check_okay_to_set(context_feature: str | list[str]) -> bool: gravity = option.get("gravity") if gravity is not None: g = gravity.split(" ") - gravity = " ".join([g[0], g[1], str(context["gravity"])]) + gravity = " ".join([g[0], g[1], str(-context["gravity"])]) else: - gravity = " ".join(["0", "0", str(context["gravity"])]) + gravity = " ".join(["0", "0", str(-context["gravity"])]) option.set("gravity", gravity) if check_okay_to_set("wind"): diff --git a/carl/envs/dmc/loader.py b/carl/envs/dmc/loader.py index 7161a2cc..30c41738 100644 --- a/carl/envs/dmc/loader.py +++ b/carl/envs/dmc/loader.py @@ -29,6 +29,7 @@ def load_dmc_env( environment_kwargs: Dict[str, bool] = None, visualize_reward: bool = False, ) -> dm_env: + if domain_name in _DOMAINS: domain = _DOMAINS[domain_name] elif domain_name in suite._DOMAINS: diff --git a/carl/envs/dmc/wrappers.py b/carl/envs/dmc/wrappers.py index e905c0f8..1a9b203f 100644 --- a/carl/envs/dmc/wrappers.py +++ b/carl/envs/dmc/wrappers.py @@ -1,10 +1,10 @@ from typing import Any, Optional, Tuple, TypeVar, Union import dm_env # type: ignore -import gymnasium as gym +import gym import numpy as np from dm_env import StepType -from gymnasium import spaces +from gym import spaces ObsType = TypeVar("ObsType") ActType = TypeVar("ActType")