Walker2D¶
This environment is part of the Mujoco environments which contains general information about the environment.
Action Space 

Observation Space 

import 

Description¶
This environment builds on the hopper environment by adding another set of legs that allow the robot to walk forward instead of hop. Like other MuJoCo environments, this environment aims to increase the number of independent state and control variables compared to classical control environments. The walker is a twodimensional bipedal robot consisting of seven main body parts  a single torso at the top (with the two legs splitting after the torso), two thighs in the middle below the torso, two legs below the thighs, and two feet attached to the legs on which the entire body rests. The goal is to walk in the forward (right) direction by applying torque to the six hinges connecting the seven body parts.
Action Space¶
The action space is a Box(1, 1, (6,), float32)
. An action represents the torques applied at the hinge joints.
Num 
Action 
Control Min 
Control Max 
Name (in corresponding XML file) 
Joint 
Type (Unit) 

0 
Torque applied on the thigh rotor 
1 
1 
thigh_joint 
hinge 
torque (N m) 
1 
Torque applied on the leg rotor 
1 
1 
leg_joint 
hinge 
torque (N m) 
2 
Torque applied on the foot rotor 
1 
1 
foot_joint 
hinge 
torque (N m) 
3 
Torque applied on the left thigh rotor 
1 
1 
thigh_left_joint 
hinge 
torque (N m) 
4 
Torque applied on the left leg rotor 
1 
1 
leg_left_joint 
hinge 
torque (N m) 
5 
Torque applied on the left foot rotor 
1 
1 
foot_left_joint 
hinge 
torque (N m) 
Observation Space¶
The observation space consists of the following parts (in order):
qpos (8 elements by default): Position values of the robot’s body parts.
qvel (9 elements): The velocities of these individual body parts (their derivatives).
By default, the observation does not include the robot’s xcoordinate (rootx
).
This can be included by passing exclude_current_positions_from_observation=False
during construction.
In this case, the observation space will be a Box(Inf, Inf, (18,), float64)
, where the first observation element is the xcoordinate of the robot.
Regardless of whether exclude_current_positions_from_observation
is set to True
or False
, the xcoordinate are returned in info
with the keys "x_position"
and "y_position"
, respectively.
By default, however, the observation space is a Box(Inf, Inf, (17,), float64)
where the elements are as follows:
Num 
Observation 
Min 
Max 
Name (in corresponding XML file) 
Joint 
Type (Unit) 

0 
zcoordinate of the torso (height of Walker2d) 
Inf 
Inf 
rootz 
slide 
position (m) 
1 
angle of the torso 
Inf 
Inf 
rooty 
hinge 
angle (rad) 
2 
angle of the thigh joint 
Inf 
Inf 
thigh_joint 
hinge 
angle (rad) 
3 
angle of the leg joint 
Inf 
Inf 
leg_joint 
hinge 
angle (rad) 
4 
angle of the foot joint 
Inf 
Inf 
foot_joint 
hinge 
angle (rad) 
5 
angle of the left thigh joint 
Inf 
Inf 
thigh_left_joint 
hinge 
angle (rad) 
6 
angle of the left leg joint 
Inf 
Inf 
leg_left_joint 
hinge 
angle (rad) 
7 
angle of the left foot joint 
Inf 
Inf 
foot_left_joint 
hinge 
angle (rad) 
8 
velocity of the xcoordinate of the torso 
Inf 
Inf 
rootx 
slide 
velocity (m/s) 
9 
velocity of the zcoordinate (height) of the torso 
Inf 
Inf 
rootz 
slide 
velocity (m/s) 
10 
angular velocity of the angle of the torso 
Inf 
Inf 
rooty 
hinge 
angular velocity (rad/s) 
11 
angular velocity of the thigh hinge 
Inf 
Inf 
thigh_joint 
hinge 
angular velocity (rad/s) 
12 
angular velocity of the leg hinge 
Inf 
Inf 
leg_joint 
hinge 
angular velocity (rad/s) 
13 
angular velocity of the foot hinge 
Inf 
Inf 
foot_joint 
hinge 
angular velocity (rad/s) 
14 
angular velocity of the thigh hinge 
Inf 
Inf 
thigh_left_joint 
hinge 
angular velocity (rad/s) 
15 
angular velocity of the leg hinge 
Inf 
Inf 
leg_left_joint 
hinge 
angular velocity (rad/s) 
16 
angular velocity of the foot hinge 
Inf 
Inf 
foot_left_joint 
hinge 
angular velocity (rad/s) 
excluded 
xcoordinate of the torso 
Inf 
Inf 
rootx 
slide 
position (m) 
Rewards¶
The total reward is: reward = healthy_reward bonus + forward_reward  ctrl_cost.
healthy_reward: Every timestep that the Walker2d is alive, it receives a fixed reward of value
healthy_reward
(default is \(1\)),forward_reward: A reward for moving forward, this reward would be positive if the Swimmer moves forward (in the positive \(x\) direction / in the right direction). \(w_{forward} \times \frac{dx}{dt}\), where \(dx\) is the displacement of the (front) “tip” (\(x_{afteraction}  x_{beforeaction}\)), \(dt\) is the time between actions, which depends on the
frame_skip
parameter (default is \(4\)), andframetime
which is \(0.002\)  so the default is \(dt = 4 \times 0.002 = 0.008\), \(w_{forward}\) is theforward_reward_weight
(default is \(1\)).ctrl_cost: A negative reward to penalize the Walker2d for taking actions that are too large. \(w_{control} \times \action\_2^2\), where \(w_{control}\) is
ctrl_cost_weight
(default is \(10^{3}\)).
info
contains the individual reward terms.
Starting State¶
The initial position state is \([0, 1.25, 0, 0, 0, 0, 0, 0, 0] + \mathcal{U}_{[reset\_noise\_scale \times I_{9}, reset\_noise\_scale \times I_{9}]}\). The initial velocity state is \(\mathcal{U}_{[reset\_noise\_scale \times I_{9}, reset\_noise\_scale \times I_{9}]}\).
where \(\mathcal{U}\) is the multivariate uniform continuous distribution.
Note that the zcoordinate is nonzero so that the Walker2d can stand up immediately.
Episode End¶
Termination¶
If terminate_when_unhealthy is True
(which is the default), the environment terminates when the Walker2d is unhealthy.
The Walker2d is unhealthy if any of the following happens:
Any of the state space values is no longer finite
The zcoordinate of the torso (the height) is not in the closed interval given by the
healthy_z_range
argument (default to \([0.8, 1.0]\)).The absolute value of the angle (
observation[1]
ifexclude_current_positions_from_observation=False
, elseobservation[2]
) is not in the closed interval specified by thehealthy_angle_range
argument (default is \([1, 1]\)).
Truncation¶
The default duration of an episode is 1000 timesteps.
Arguments¶
Walker2d provides a range of parameters to modify the observation space, reward function, initial state, and termination condition.
These parameters can be applied during gymnasium.make
in the following way:
import gymnasium as gym
env = gym.make('Walker2dv5', ctrl_cost_weight=1e3, ...)
Parameter 
Type 
Default 
Description 


str 

Path to a MuJoCo model 

float 

Weight for forward_reward term (see 

float 

Weight for ctr_cost term (see 

float 

Weight for healthy_reward reward (see 

bool 

If True, issue a 

tuple 

The zcoordinate of the torso of the walker must be in this range to be considered healthy (see 

tuple 

The angle must be in this range to be considered healthy (see 

float 

Scale of random perturbations of initial position and velocity (see 

bool 

Whether or not to omit the xcoordinate from observations. Excluding the position can serve as an inductive bias to induce positionagnostic behavior in policies (see 
Version History¶
v5:
Minimum
mujoco
version is now 2.3.3.Added support for fully custom/third party
mujoco
models using thexml_file
argument (previously only a few changes could be made to the existing models).Added
default_camera_config
argument, a dictionary for setting themj_camera
properties, mainly useful for custom environments.Added
env.observation_structure
, a dictionary for specifying the observation space compose (e.g.qpos
,qvel
), useful for building tooling and wrappers for the MuJoCo environments.Return a nonempty
info
withreset()
, previously an empty dictionary was returned, the new keys are the same state information asstep()
.Added
frame_skip
argument, used to configure thedt
(duration ofstep()
), default varies by environment check environment documentation pages.In v2, v3 and v4 the models have different friction values for the two feet (left foot friction == 1.9 and right foot friction == 0.9). The
Walkerv5
model is updated to have the same friction for both feet (set to 1.9). This causes the Walker2d’s the right foot to slide less on the surface and therefore require more force to move (related GitHub issue).Fixed bug:
healthy_reward
was given on every step (even if the Walker2D is unhealthy), now it is only given if the Walker2d is healthy. Theinfo
“reward_survive” is updated with this change (related GitHub issue).Restored the
xml_file
argument (was removed inv4
).Added individual reward terms in
info
(info["reward_forward"]
, info["reward_ctrl"]
,info["reward_survive"]
).Added
info["z_distance_from_origin"]
which is equal to the vertical distance of the “torso” body from its initial position.
v4: All MuJoCo environments now use the MuJoCo bindings in mujoco >= 2.1.3
v3: Support for
gymnasium.make
kwargs such asxml_file
,ctrl_cost_weight
,reset_noise_scale
, etc. rgb rendering comes from tracking camera (so agent does not run away from screen)v2: All continuous control environments now use mujocopy >= 1.50
v1: max_time_steps raised to 1000 for robot based tasks. Added reward_threshold to environments.
v0: Initial versions release