1. Install and first example¶
The easiest way to use ReDySim RL is the GUI (chapter 2): install as below, with the gui
extra, and open it. The examples further down this chapter, and chapters 3 to 5, are for
using the environments in your own code: your own training algorithm, reward code, sweeps and
automation.
Install¶
ReDySim RL needs Python 3.10 or newer and ReDySim Fixed-base and Floating-base (the fixed-base and floating-base
simulators, one download), which must be installed first (they are not on PyPI, so installing
redysim_rl on its own fails with a missing redysim). The GUI offers the floating-base tasks too, so
it needs both; for scripts only, the floating-base simulator is needed just for space_reach,
quadruped_velocity and wheeled_nav.
Install ReDySim Fixed-base and Floating-base with its install.sh (Ubuntu) or install.ps1 (Windows), as its manual says.
That makes a virtual environment in the unpacked folder (redysim-1.0/.venv). Then, in the folder that holds
both redysim-1.0 and this download, activate that environment and install ReDySim RL:
source redysim-1.0/.venv/bin/activate
pip install torch --index-url https://download.pytorch.org/whl/cpu # Linux only: CPU build, about 1.0 GB instead of 5.4 GB
pip install "./redysim_rl-1.0[gui]" # the [gui] extra is for the GUI; leave it out for scripts only
Or run install.sh (Windows: install.ps1) in this folder: it does both steps above. The whole environment
with the GUI is then about 1.9 GB.
On Windows, in PowerShell, activate it with redysim-1.0\.venv\Scripts\Activate.ps1 instead (see the
script-policy hint in the Fixed-base manual).
NumPy and Gymnasium (1.1 or newer) are installed automatically. Check it:
python -c "import redysim_rl; print(redysim_rl.__version__)"
A vector environment¶
import numpy as np
import redysim_rl
env = redysim_rl.make_vec("joint_reach", num_envs=64) # 64 arms, one batch stepper
obs, info = env.reset(seed=0)
print(obs.shape, env.action_space.shape) # (64, 9) (64, 3)
rng = np.random.default_rng(0)
for _ in range(100):
actions = rng.uniform(-1.0, 1.0, env.action_space.shape).astype(np.float32)
obs, reward, terminated, truncated, info = env.step(actions)
print(reward.mean(), info["distance"].mean())
Every call takes and returns one row per robot. With the default settings an environment step is a 20 ms control step of a three-joint arm; the reward is the negative distance of the joints to a random goal. By default an environment that has ended (here after 200 steps) restarts at the next call, with a new goal and starting pose; see autoreset.
A single environment¶
import redysim_rl
env = redysim_rl.make("task_reach", action_mode="pd_target")
obs, info = env.reset(seed=1)
done = False
while not done:
obs, reward, terminated, truncated, info = env.step(env.action_space.sample())
done = terminated or truncated
print(info["distance"], info["is_success"])
The single environment is the vector environment with one robot and no autoreset, so it behaves
the same way; it is what you hand to a program that expects an ordinary Gymnasium environment
(gymnasium.make("Redysim/TaskReach-v0") works too). A vector environment is much faster for
training, because the physics of all robots is one call.
Next¶
Tasks and robots describes what the observations and rewards are, Action modes how an action becomes a force, and Training how to train a policy.