-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Upgrade from gym to gymnasium * Support vector env * Update dependencies * Split state into multiple components * Remove comment * Add reset_to_demo option for gym env * Revert task env step change and clean up dependencies * Install gym deps for ci * Fix typo * Fix tests * Remove imports * Add import * Add test for example scripts * Comment out test * Update pyrep dependency with cffi fix branch * Typo * Point to commit hash * Comment out flaky test * Move gym envs to rlbench/__init__.py * Include package data * Move dataset_generator.py into package; add rlbench-generate-dataset entry point * Clean up old code and sort imports * Update setup.py --------- Co-authored-by: Stephen James <[email protected]>
- Loading branch information
1 parent
f2c625f
commit 299dddc
Showing
17 changed files
with
348 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
import gym | ||
import rlbench.gym | ||
import gymnasium as gym | ||
from gymnasium.utils.performance import benchmark_step | ||
import rlbench | ||
|
||
env = gym.make('rlbench/reach_target-vision-v0', render_mode="rgb_array") | ||
|
||
env = gym.make('reach_target-state-v0', render_mode='human') | ||
|
||
training_steps = 120 | ||
episode_length = 40 | ||
for i in range(training_steps): | ||
if i % episode_length == 0: | ||
print('Reset Episode') | ||
obs = env.reset() | ||
obs, reward, terminate, _ = env.step(env.action_space.sample()) | ||
obs, reward, terminate, _, _ = env.step(env.action_space.sample()) | ||
env.render() # Note: rendering increases step time. | ||
|
||
print('Done') | ||
|
||
fps = benchmark_step(env, target_duration=10) | ||
print(f"FPS: {fps:.2f}") | ||
env.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import time | ||
import gymnasium as gym | ||
import rlbench | ||
|
||
|
||
def benchmark_vector_step(env, target_duration: int = 5, seed=None) -> float: | ||
steps = 0 | ||
end = 0.0 | ||
env.reset(seed=seed) | ||
env.action_space.sample() | ||
start = time.monotonic() | ||
|
||
while True: | ||
action = env.action_space.sample() | ||
_, _, terminal, truncated, _ = env.step(action) | ||
steps += terminal.shape[0] | ||
|
||
# if terminal or truncated: | ||
# env.reset() | ||
|
||
if time.monotonic() - start > target_duration: | ||
end = time.monotonic() | ||
break | ||
|
||
length = end - start | ||
|
||
steps_per_time = steps / length | ||
return steps_per_time | ||
|
||
if __name__ == "__main__": | ||
# Only works with spawn (multiprocessing) context | ||
env = gym.make_vec('rlbench/reach_target-vision-v0', num_envs=2, vectorization_mode="async", vector_kwargs={"context": "spawn"}) | ||
|
||
training_steps = 120 | ||
episode_length = 40 | ||
for i in range(training_steps): | ||
if i % episode_length == 0: | ||
print('Reset Episode') | ||
obs = env.reset() | ||
obs, reward, terminate, _, _ = env.step(env.action_space.sample()) | ||
env.render() # Note: rendering increases step time. | ||
|
||
print('Done') | ||
|
||
fps = benchmark_vector_step(env, target_duration=10) | ||
print(f"FPS: {fps:.2f}") | ||
|
||
env.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,48 @@ | ||
__version__ = '1.2.0' | ||
__version__ = "1.2.0" | ||
|
||
import numpy as np | ||
import pyrep | ||
|
||
pr_v = np.array(pyrep.__version__.split('.'), dtype=int) | ||
if pr_v.size < 4 or np.any(pr_v < np.array([4, 1, 0, 2])): | ||
raise ImportError( | ||
'PyRep version must be greater than 4.1.0.2. Please update PyRep.') | ||
import os | ||
|
||
from gymnasium import register | ||
|
||
import rlbench.backend.task as task | ||
from rlbench.action_modes.action_mode import ( | ||
ActionMode, | ||
ArmActionMode, | ||
GripperActionMode, | ||
) | ||
from rlbench.environment import Environment | ||
from rlbench.action_modes.action_mode import ActionMode, ArmActionMode, GripperActionMode | ||
from rlbench.observation_config import ObservationConfig | ||
from rlbench.observation_config import CameraConfig | ||
from rlbench.sim2real.domain_randomization import RandomizeEvery | ||
from rlbench.sim2real.domain_randomization import VisualRandomizationConfig | ||
from rlbench.observation_config import CameraConfig, ObservationConfig | ||
from rlbench.sim2real.domain_randomization import ( | ||
RandomizeEvery, | ||
VisualRandomizationConfig, | ||
) | ||
from rlbench.utils import name_to_task_class | ||
|
||
__all__ = [ | ||
"ActionMode", | ||
"ArmActionMode", | ||
"GripperActionMode", | ||
"CameraConfig", | ||
"Environment", | ||
"ObservationConfig", | ||
"RandomizeEvery", | ||
"VisualRandomizationConfig", | ||
] | ||
|
||
TASKS = [ | ||
t for t in os.listdir(task.TASKS_PATH) if t != "__init__.py" and t.endswith(".py") | ||
] | ||
|
||
for task_file in TASKS: | ||
task_name = task_file.split(".py")[0] | ||
task_class = name_to_task_class(task_name) | ||
for obs_mode in ["state", "vision"]: | ||
register( | ||
id=f"rlbench/{task_name}-{obs_mode}-v0", | ||
entry_point="rlbench.gym:RLBenchEnv", | ||
kwargs={ | ||
"task_class": task_class, | ||
"observation_mode": obs_mode, | ||
}, | ||
nondeterministic=True, | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.