File size: 1,696 Bytes
3aeb818 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | ## Basic Usage
### Gym interface
We provide a gym-like interface to run rollouts:
<div class="admonition warning">
<p class="admonition-title">Attention Mac users!</p>
Mac users who wish to run this example need to prepend the “python” command with “mj”: mjpython
</div>
```py
from robocasa.environments import ALL_KITCHEN_ENVIRONMENTS
from robocasa.utils.env_utils import create_env, run_random_rollouts
import numpy as np
# choose random task
env_name = np.random.choice(list(ALL_KITCHEN_ENVIRONMENTS))
env = create_env(
env_name=env_name,
render_onscreen=True,
seed=0, # set seed=None to run unseeded
)
# reset the environment
env.reset()
# get task language
lang = env.get_ep_meta()["lang"]
print("Instruction:", lang)
for i in range(500):
action = np.random.randn(*env.action_spec[0].shape) * 0.1
obs, reward, done, info = env.step(action) # take action in the environment
env.render() # render on display
```
### Offscreen rollouts
You can also run rollouts and save videos:
```py
from robocasa.environments import ALL_KITCHEN_ENVIRONMENTS
from robocasa.utils.env_utils import create_env, run_random_rollouts
import numpy as np
# choose random task
env_name = np.random.choice(list(ALL_KITCHEN_ENVIRONMENTS))
env = create_env(
env_name=env_name,
render_onscreen=False,
seed=0, # set seed=None to run unseeded
)
# run rollouts with random actions and save video
info = run_random_rollouts(
env, num_rollouts=3, num_steps=100, video_path="/tmp/test.mp4"
)
print(info)
```
Separately we provide tools to run policy rollouts within robomimic. See the [policy learning page](../use_cases/policy_learning.html) for additional details. |