robotenv 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- robotenv/__init__.py +21 -0
- robotenv/_canon.py +136 -0
- robotenv/config/__init__.py +93 -0
- robotenv/config/base_env.py +557 -0
- robotenv/config/control.py +161 -0
- robotenv/config/defaults.py +29 -0
- robotenv/config/env.py +107 -0
- robotenv/config/kinematics.py +121 -0
- robotenv/config/mount.py +172 -0
- robotenv/config/providers.py +171 -0
- robotenv/config/robot_providers.py +140 -0
- robotenv/config/sim.py +152 -0
- robotenv/config/specs.py +111 -0
- robotenv/config/sweep.py +100 -0
- robotenv/config/task.py +183 -0
- robotenv/envs/__init__.py +34 -0
- robotenv/envs/spaces.py +38 -0
- robotenv/errors.py +35 -0
- robotenv/robot/__init__.py +30 -0
- robotenv/robot/arm.py +319 -0
- robotenv/robot/external.py +234 -0
- robotenv/robot/generators.py +138 -0
- robotenv/robot/gripper.py +82 -0
- robotenv/robot/pose.py +49 -0
- robotenv/robot/providers/__init__.py +5 -0
- robotenv/robot/providers/menagerie/__init__.py +127 -0
- robotenv/robot/providers/menagerie/_describe.py +130 -0
- robotenv/robot/providers/menagerie/cards.json +37 -0
- robotenv/simulators/__init__.py +51 -0
- robotenv/simulators/base.py +70 -0
- robotenv/simulators/mujoco/__init__.py +38 -0
- robotenv/simulators/mujoco/arm_spec.py +137 -0
- robotenv/simulators/mujoco/compile.py +242 -0
- robotenv/simulators/mujoco/env.py +257 -0
- robotenv/simulators/mujoco/external.py +443 -0
- robotenv/simulators/mujoco/mount.py +65 -0
- robotenv/simulators/mujoco/render.py +158 -0
- robotenv/simulators/mujoco/scenes.py +35 -0
- robotenv/simulators/mujoco/sim.py +174 -0
- robotenv/simulators/warp/__init__.py +100 -0
- robotenv/simulators/warp/env.py +235 -0
- robotenv/simulators/warp/sim.py +332 -0
- robotenv/tasks/__init__.py +10 -0
- robotenv/tasks/base.py +147 -0
- robotenv/tasks/empty/__init__.py +42 -0
- robotenv/tasks/empty/params.py +33 -0
- robotenv/tasks/empty/task.py +27 -0
- robotenv/tasks/robosuite/__init__.py +133 -0
- robotenv/tasks/robosuite/_compat.py +165 -0
- robotenv/tasks/robosuite/_introspect.py +65 -0
- robotenv/tasks/robosuite/params.py +152 -0
- robotenv/tasks/robosuite/scene.py +140 -0
- robotenv/tasks/robosuite/task.py +145 -0
- robotenv/viz/__init__.py +22 -0
- robotenv/viz/_deps.py +16 -0
- robotenv/viz/camera.py +98 -0
- robotenv/viz/clip.py +180 -0
- robotenv/viz/frames.py +93 -0
- robotenv/viz/record.py +141 -0
- robotenv-0.2.1.dist-info/METADATA +136 -0
- robotenv-0.2.1.dist-info/RECORD +63 -0
- robotenv-0.2.1.dist-info/WHEEL +4 -0
- robotenv-0.2.1.dist-info/licenses/LICENSE +339 -0
robotenv/__init__.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Robot embodiments as validated, hashable data, instantiated in batched RL environments.
|
|
2
|
+
|
|
3
|
+
``env = robotenv.make_env(env_config)`` is the single way to get an environment from an ``EnvConfig``.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
__version__ = "0.2.1"
|
|
7
|
+
|
|
8
|
+
__all__ = ["__version__", "make_env"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def __getattr__(name):
|
|
12
|
+
# Lazy, so that ``import robotenv`` (and ``robotenv.config``) import no engine.
|
|
13
|
+
if name == "make_env":
|
|
14
|
+
from .envs import make_env
|
|
15
|
+
|
|
16
|
+
return make_env
|
|
17
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def __dir__():
|
|
21
|
+
return sorted(set(globals()) | {"make_env"})
|
robotenv/_canon.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"""Canonical JSON and hashing shared by every config object."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import math
|
|
8
|
+
from typing import Any, Callable, Mapping, TypeVar
|
|
9
|
+
|
|
10
|
+
from .errors import ConfigError
|
|
11
|
+
|
|
12
|
+
SIGNIFICANT_DIGITS = 12
|
|
13
|
+
HASH_DISPLAY_LENGTH = 12
|
|
14
|
+
|
|
15
|
+
T = TypeVar("T")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def round_float(x: float) -> float:
|
|
19
|
+
"""Round to 12 significant digits; ``-0.0`` becomes ``0.0``."""
|
|
20
|
+
if x == 0.0:
|
|
21
|
+
return 0.0
|
|
22
|
+
return float(f"{x:.{SIGNIFICANT_DIGITS - 1}e}")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def canonicalize(obj: Any) -> Any:
|
|
26
|
+
"""Plain JSON-able structure with rounded floats and tuples turned into lists."""
|
|
27
|
+
if isinstance(obj, bool) or obj is None or isinstance(obj, (str, int)):
|
|
28
|
+
return obj
|
|
29
|
+
if isinstance(obj, float):
|
|
30
|
+
return round_float(obj)
|
|
31
|
+
if isinstance(obj, Mapping):
|
|
32
|
+
return {str(k): canonicalize(v) for k, v in obj.items()}
|
|
33
|
+
if isinstance(obj, (list, tuple)):
|
|
34
|
+
return [canonicalize(v) for v in obj]
|
|
35
|
+
raise TypeError(f"cannot canonicalize {type(obj).__name__}")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def canonical_json(obj: Any) -> str:
|
|
39
|
+
return json.dumps(canonicalize(obj), sort_keys=True, separators=(",", ":"), allow_nan=False)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def sha256_hex(text: str) -> str:
|
|
43
|
+
return hashlib.sha256(text.encode("utf-8")).hexdigest()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# --- field coercion and validation -------------------------------------------------
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def as_float(x: Any, path: str) -> float:
|
|
50
|
+
if isinstance(x, (bool, str, bytes)) or not hasattr(x, "__float__"):
|
|
51
|
+
raise ConfigError(path, f"expected a number, got {type(x).__name__}")
|
|
52
|
+
try:
|
|
53
|
+
v = float(x)
|
|
54
|
+
except (TypeError, ValueError):
|
|
55
|
+
raise ConfigError(path, f"expected a number, got {x!r}") from None
|
|
56
|
+
if not math.isfinite(v):
|
|
57
|
+
raise ConfigError(path, "must be finite")
|
|
58
|
+
return v
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def as_vector(x: Any, size: int, path: str) -> tuple[float, ...]:
|
|
62
|
+
try:
|
|
63
|
+
items = tuple(x)
|
|
64
|
+
except TypeError:
|
|
65
|
+
raise ConfigError(path, f"expected a sequence of {size} numbers") from None
|
|
66
|
+
if len(items) != size:
|
|
67
|
+
raise ConfigError(path, f"expected {size} numbers, got {len(items)}")
|
|
68
|
+
return tuple(as_float(v, f"{path}[{i}]") for i, v in enumerate(items))
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def check_keys(d: Any, required: set[str], path: str, optional: set[str] = frozenset()) -> None:
|
|
72
|
+
"""Reject non-mappings, missing keys and unknown keys."""
|
|
73
|
+
if not isinstance(d, Mapping):
|
|
74
|
+
raise ConfigError(path, f"expected a mapping, got {type(d).__name__}")
|
|
75
|
+
missing = sorted(required - set(d))
|
|
76
|
+
if missing:
|
|
77
|
+
raise ConfigError(path, f"missing keys: {', '.join(missing)}")
|
|
78
|
+
unknown = sorted(set(d) - required - optional)
|
|
79
|
+
if unknown:
|
|
80
|
+
raise ConfigError(path, f"unknown keys: {', '.join(unknown)}")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def within(prefix: str, fn: Callable[..., T], *args: Any, **kwargs: Any) -> T:
|
|
84
|
+
"""Call ``fn`` and prefix the path of any ``ConfigError`` it raises."""
|
|
85
|
+
try:
|
|
86
|
+
return fn(*args, **kwargs)
|
|
87
|
+
except ConfigError as e:
|
|
88
|
+
raise e.prefixed(prefix) from None
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def as_int(x: Any, path: str) -> int:
|
|
92
|
+
if isinstance(x, bool) or not hasattr(x, "__index__"):
|
|
93
|
+
raise ConfigError(path, f"expected an integer, got {type(x).__name__}")
|
|
94
|
+
return int(x)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def as_bool(x: Any, path: str) -> bool:
|
|
98
|
+
if not isinstance(x, bool):
|
|
99
|
+
raise ConfigError(path, f"expected a bool, got {type(x).__name__}")
|
|
100
|
+
return x
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def as_str(x: Any, path: str) -> str:
|
|
104
|
+
if not isinstance(x, str) or not x:
|
|
105
|
+
raise ConfigError(path, "must be a non-empty string")
|
|
106
|
+
return x
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# --- JSON-like values as immutable structures ------------------------------------------
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def freeze(value: Any, path: str) -> Any:
|
|
113
|
+
"""JSON-like value as an immutable, hashable structure: lists become tuples, mappings become sorted item tuples
|
|
114
|
+
led by the marker ``"__map__"``. Used by providers whose parameters hold free-form mappings."""
|
|
115
|
+
if value is None or isinstance(value, (bool, str, int)):
|
|
116
|
+
return value
|
|
117
|
+
if isinstance(value, float):
|
|
118
|
+
return as_float(value, path)
|
|
119
|
+
if isinstance(value, Mapping):
|
|
120
|
+
items = sorted(value.items(), key=lambda kv: str(kv[0]))
|
|
121
|
+
return ("__map__",) + tuple((str(k), freeze(v, f"{path}.{k}")) for k, v in items)
|
|
122
|
+
if isinstance(value, (list, tuple)):
|
|
123
|
+
return tuple(freeze(v, f"{path}[{i}]") for i, v in enumerate(value))
|
|
124
|
+
raise ConfigError(
|
|
125
|
+
path,
|
|
126
|
+
f"unsupported value of type {type(value).__name__}; use bool, int, float, str, None, lists or mappings",
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def thaw(value: Any) -> Any:
|
|
131
|
+
"""Inverse of :func:`freeze`: mappings come back as dicts, sequences as tuples."""
|
|
132
|
+
if isinstance(value, tuple) and value and value[0] == "__map__":
|
|
133
|
+
return {k: thaw(v) for k, v in value[1:]}
|
|
134
|
+
if isinstance(value, tuple):
|
|
135
|
+
return tuple(thaw(v) for v in value)
|
|
136
|
+
return value
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Configuration layer: numpy only. Imports no simulation engine and no torch."""
|
|
2
|
+
|
|
3
|
+
from . import kinematics
|
|
4
|
+
from .base_env import BaseEnvConfig
|
|
5
|
+
from .control import CONTROL_MODES, ControlConfig, FixedGains, InertiaScaledGains, NativeGains
|
|
6
|
+
from .env import EnvConfig
|
|
7
|
+
from ..errors import ConfigError, Problem
|
|
8
|
+
from .providers import (
|
|
9
|
+
TaskProvider,
|
|
10
|
+
get_task_provider,
|
|
11
|
+
list_task_providers,
|
|
12
|
+
register_task_provider,
|
|
13
|
+
unregister_task_provider,
|
|
14
|
+
)
|
|
15
|
+
from .robot_providers import (
|
|
16
|
+
RobotProvider,
|
|
17
|
+
get_robot_provider,
|
|
18
|
+
list_robot_providers,
|
|
19
|
+
register_robot_provider,
|
|
20
|
+
unregister_robot_provider,
|
|
21
|
+
)
|
|
22
|
+
from .mount import MobileMount, Mount, scene_frame, snapped, world_mount
|
|
23
|
+
from .sweep import Family
|
|
24
|
+
from .specs import NOT_SET, Chain
|
|
25
|
+
from .sim import INTEGRATORS, MujocoOptions, SimConfig, WarpOptions, register_simulator_options
|
|
26
|
+
from .task import FixedBox, OwnReachable, TaskConfig
|
|
27
|
+
from ..robot import (
|
|
28
|
+
Capsule,
|
|
29
|
+
EndEffectorRef,
|
|
30
|
+
ExternalJoint,
|
|
31
|
+
ExternalRobot,
|
|
32
|
+
robot_from_dict,
|
|
33
|
+
TwoFingerGripper,
|
|
34
|
+
chain,
|
|
35
|
+
JointSpec,
|
|
36
|
+
LinkSpec,
|
|
37
|
+
ParametricArm,
|
|
38
|
+
Pose,
|
|
39
|
+
Segment,
|
|
40
|
+
ToolSpec,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
__all__ = [
|
|
44
|
+
"BaseEnvConfig",
|
|
45
|
+
"Chain",
|
|
46
|
+
"NOT_SET",
|
|
47
|
+
"CONTROL_MODES",
|
|
48
|
+
"ControlConfig",
|
|
49
|
+
"EnvConfig",
|
|
50
|
+
"Family",
|
|
51
|
+
"FixedBox",
|
|
52
|
+
"FixedGains",
|
|
53
|
+
"INTEGRATORS",
|
|
54
|
+
"InertiaScaledGains",
|
|
55
|
+
"MobileMount",
|
|
56
|
+
"Mount",
|
|
57
|
+
"MujocoOptions",
|
|
58
|
+
"NativeGains",
|
|
59
|
+
"OwnReachable",
|
|
60
|
+
"Problem",
|
|
61
|
+
"SimConfig",
|
|
62
|
+
"TaskConfig",
|
|
63
|
+
"TaskProvider",
|
|
64
|
+
"WarpOptions",
|
|
65
|
+
"get_task_provider",
|
|
66
|
+
"list_task_providers",
|
|
67
|
+
"register_simulator_options",
|
|
68
|
+
"register_task_provider",
|
|
69
|
+
"unregister_task_provider",
|
|
70
|
+
"RobotProvider",
|
|
71
|
+
"get_robot_provider",
|
|
72
|
+
"list_robot_providers",
|
|
73
|
+
"register_robot_provider",
|
|
74
|
+
"unregister_robot_provider",
|
|
75
|
+
"EndEffectorRef",
|
|
76
|
+
"ExternalJoint",
|
|
77
|
+
"ExternalRobot",
|
|
78
|
+
"robot_from_dict",
|
|
79
|
+
"Capsule",
|
|
80
|
+
"ConfigError",
|
|
81
|
+
"JointSpec",
|
|
82
|
+
"LinkSpec",
|
|
83
|
+
"ParametricArm",
|
|
84
|
+
"Pose",
|
|
85
|
+
"Segment",
|
|
86
|
+
"ToolSpec",
|
|
87
|
+
"TwoFingerGripper",
|
|
88
|
+
"chain",
|
|
89
|
+
"kinematics",
|
|
90
|
+
"scene_frame",
|
|
91
|
+
"snapped",
|
|
92
|
+
"world_mount",
|
|
93
|
+
]
|