Walker2D#
This environment is part of the Mujoco environments.Please read that page first for general information.
Action Space 
Box(1.0, 1.0, (6,), float32) 
Observation Shape 
(17,) 
Observation High 
inf 
Observation Low 
inf 
Import 

Description#
This environment builds on the hopper environment based on the work done by Erez, Tassa, and Todorov in “Infinite Horizon Model Predictive Control for Nonlinear Periodic Tasks” by adding another set of legs making it possible for the robot to walker forward instead of hop. Like other Mujoco environments, this environment aims to increase the number of independent state and control variables as compared to the classic control environments. The walker is a twodimensional twolegged figure that consist of four 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 in the bottom below the thighs, and two feet attached to the legs on which the entire body rests. The goal is to make coordinate both sets of feet, legs, and thighs to move in the forward (right) direction by applying torques on the six hinges connecting the six 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 
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#
Observations consist of positional values of different body parts of the walker, followed by the velocities of those individual parts (their derivatives) with all the positions ordered before all the velocities.
By default, observations do not include the xcoordinate of the top. It may
be included by passing exclude_current_positions_from_observation=False
during construction.
In that case, the observation space will have 18 dimensions where the first dimension
represent the xcoordinates of the top of the walker.
Regardless of whether exclude_current_positions_from_observation
was set to true or false, the xcoordinate
of the top will be returned in info
with key "x_position"
.
By default, observation is a ndarray
with shape (17,)
where the elements correspond to the following:
Num 
Observation 
Min 
Max 
Name (in corresponding XML file) 
Joint 
Unit 

0 
zcoordinate of the top (height of hopper) 
Inf 
Inf 
rootz (torso) 
slide 
position (m) 
1 
angle of the top 
Inf 
Inf 
rooty (torso) 
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 top 
Inf 
Inf 
rootx 
slide 
velocity (m/s) 
9 
velocity of the zcoordinate (height) of the top 
Inf 
Inf 
rootz 
slide 
velocity (m/s) 
10 
angular velocity of the angle of the top 
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) 
Rewards#
The reward consists of three parts:
healthy_reward: Every timestep that the walker is alive, it receives a fixed reward of value
healthy_reward
,forward_reward: A reward of walking forward which is measured as
forward_reward_weight
* (xcoordinate before action  xcoordinate after action)/dt. dt is the time between actions and is dependeent on the frame_skip parameter (default is 4), where the frametime is 0.002  making the default dt = 4 * 0.002 = 0.008. This reward would be positive if the walker walks forward (right) desired.ctrl_cost: A cost for penalising the walker if it takes actions that are too large. It is measured as
ctrl_cost_weight
* sum(action^{2}) wherectrl_cost_weight
is a parameter set for the control and has a default value of 0.001
The total reward returned is reward = healthy_reward bonus + forward_reward  ctrl_cost and info
will also contain the individual reward terms
Starting State#
All observations start in state
(0.0, 1.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
with a uniform noise in the range of [reset_noise_scale
, reset_noise_scale
] added to the values for stochasticity.
Episode End#
The walker is said to be unhealthy if any of the following happens:
Any of the state space values is no longer finite
The height of the walker is not in the closed interval specified by
healthy_z_range
The absolute value of the angle (
observation[1]
ifexclude_current_positions_from_observation=False
, elseobservation[2]
) is not in the closed interval specified byhealthy_angle_range
If terminate_when_unhealthy=True
is passed during construction (which is the default),
the episode ends when any of the following happens:
Truncation: The episode duration reaches a 1000 timesteps
Termination: The walker is unhealthy
If terminate_when_unhealthy=False
is passed, the episode is ended only when 1000 timesteps are exceeded.
Arguments#
No additional arguments are currently supported in v2 and lower.
import gymnasium as gym
env = gym.make('Walker2dv4')
v3 and beyond take gymnasium.make
kwargs such as xml_file
, ctrl_cost_weight
, reset_noise_scale
, etc.
import gymnasium as gym
env = gym.make('Walker2dv4', ctrl_cost_weight=0.1, ....)
Parameter 
Type 
Default 
Description 


str 

Path to a MuJoCo model 

float 

Weight for forward_reward term (see section on reward) 

float 

Weight for ctr_cost term (see section on reward) 

float 

Constant reward given if the ant is “healthy” after timestep 

bool 

If true, issue a done signal if the zcoordinate of the walker is no longer healthy 

tuple 

The zcoordinate of the top of the walker must be in this range to be considered healthy 

tuple 

The angle must be in this range to be considered healthy 

float 

Scale of random perturbations of initial position and velocity (see section on Starting State) 

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 
Version History#
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 (1.0.0)