diff --git a/brax/envs/ant.py b/brax/envs/ant.py index 186dfd1c2..377570463 100644 --- a/brax/envs/ant.py +++ b/brax/envs/ant.py @@ -54,14 +54,14 @@ class Ant(PipelineEnv): | Num | Action | Control Min | Control Max | Name (in corresponding config) | Joint | Unit | |-----|--------------------------------------------------------------------|-------------|-------------|----------------------------------|-------|--------------| - | 0 | Torque applied on the rotor between the torso and front left hip | -1 | 1 | hip_1 (front_left_leg) | hinge | torque (N m) | - | 1 | Torque applied on the rotor between the front left two links | -1 | 1 | ankle_1 (front_left_leg) | hinge | torque (N m) | - | 2 | Torque applied on the rotor between the torso and front right hip | -1 | 1 | hip_2 (front_right_leg) | hinge | torque (N m) | - | 3 | Torque applied on the rotor between the front right two links | -1 | 1 | ankle_2 (front_right_leg) | hinge | torque (N m) | - | 4 | Torque applied on the rotor between the torso and back left hip | -1 | 1 | hip_3 (back_leg) | hinge | torque (N m) | - | 5 | Torque applied on the rotor between the back left two links | -1 | 1 | ankle_3 (back_leg) | hinge | torque (N m) | - | 6 | Torque applied on the rotor between the torso and back right hip | -1 | 1 | hip_4 (right_back_leg) | hinge | torque (N m) | - | 7 | Torque applied on the rotor between the back right two links | -1 | 1 | ankle_4 (right_back_leg) | hinge | torque (N m) | + | 0 | Torque applied on the rotor between the torso and back right hip | -1 | 1 | hip_4 (right_back_leg) | hinge | torque (N m) | + | 1 | Torque applied on the rotor between the back right two links | -1 | 1 | ankle_4 (right_back_leg) | hinge | torque (N m) | + | 2 | Torque applied on the rotor between the torso and front left hip | -1 | 1 | hip_1 (front_left_leg) | hinge | torque (N m) | + | 3 | Torque applied on the rotor between the front left two links | -1 | 1 | ankle_1 (front_left_leg) | hinge | torque (N m) | + | 4 | Torque applied on the rotor between the torso and front right hip | -1 | 1 | hip_2 (front_right_leg) | hinge | torque (N m) | + | 5 | Torque applied on the rotor between the front right two links | -1 | 1 | ankle_2 (front_right_leg) | hinge | torque (N m) | + | 6 | Torque applied on the rotor between the torso and back left hip | -1 | 1 | hip_3 (back_leg) | hinge | torque (N m) | + | 7 | Torque applied on the rotor between the back left two links | -1 | 1 | ankle_3 (back_leg) | hinge | torque (N m) | ### Observation Space @@ -138,7 +138,7 @@ class Ant(PipelineEnv): The episode terminates when any of the following happens: 1. The episode duration reaches a 1000 timesteps - 2. The y-orientation (index 2) in the state is **not** in the range + 2. The z-coordinate of the torso (index 0) in the state is **not** in the range `[0.2, 1.0]` """ # pyformat: enable diff --git a/brax/envs/humanoid.py b/brax/envs/humanoid.py index 0e8eaff84..54eeeeee4 100644 --- a/brax/envs/humanoid.py +++ b/brax/envs/humanoid.py @@ -50,22 +50,22 @@ class Humanoid(PipelineEnv): | Num | Action | Control Min | Control Max | Name (in corresponding config) | Joint | Unit | |-----|------------------------------------------------------------------------------------|-------------|-------------|----------------------------------|-------|--------------| - | 0 | Torque applied on the hinge in the y-coordinate of the abdomen | -1.0 | 1.0 | abdomen_yz | hinge | torque (N m) | - | 1 | Torque applied on the hinge in the z-coordinate of the abdomen | -1.0 | 1.0 | abdomen_yz | hinge | torque (N m) | + | 0 | Torque applied on the hinge in the y-coordinate of the abdomen | -1.0 | 1.0 | abdomen_y | hinge | torque (N m) | + | 1 | Torque applied on the hinge in the z-coordinate of the abdomen | -1.0 | 1.0 | abdomen_z | hinge | torque (N m) | | 2 | Torque applied on the hinge in the x-coordinate of the abdomen | -1.0 | 1.0 | abdomen_x | hinge | torque (N m) | - | 3 | Torque applied on the rotor between torso/abdomen and the right hip (x-coordinate) | -1.0 | 1.0 | right_hip_xyz (right_thigh) | hinge | torque (N m) | - | 4 | Torque applied on the rotor between torso/abdomen and the right hip (y-coordinate) | -1.0 | 1.0 | right_hip_xyz (right_thigh) | hinge | torque (N m) | - | 5 | Torque applied on the rotor between torso/abdomen and the right hip (z-coordinate) | -1.0 | 1.0 | right_hip_xyz (right_thigh) | hinge | torque (N m) | + | 3 | Torque applied on the rotor between torso/abdomen and the right hip (x-coordinate) | -1.0 | 1.0 | right_hip_x (right_thigh) | hinge | torque (N m) | + | 4 | Torque applied on the rotor between torso/abdomen and the right hip (z-coordinate) | -1.0 | 1.0 | right_hip_z (right_thigh) | hinge | torque (N m) | + | 5 | Torque applied on the rotor between torso/abdomen and the right hip (y-coordinate) | -1.0 | 1.0 | right_hip_y (right_thigh) | hinge | torque (N m) | | 6 | Torque applied on the rotor between the right hip/thigh and the right shin | -1.0 | 1.0 | right_knee | hinge | torque (N m) | - | 7 | Torque applied on the rotor between torso/abdomen and the left hip (x-coordinate) | -1.0 | 1.0 | left_hip_xyz (left_thigh) | hinge | torque (N m) | - | 8 | Torque applied on the rotor between torso/abdomen and the left hip (y-coordinate) | -1.0 | 1.0 | left_hip_xyz (left_thigh) | hinge | torque (N m) | - | 9 | Torque applied on the rotor between torso/abdomen and the left hip (z-coordinate) | -1.0 | 1.0 | left_hip_xyz (left_thigh) | hinge | torque (N m) | + | 7 | Torque applied on the rotor between torso/abdomen and the left hip (x-coordinate) | -1.0 | 1.0 | left_hip_x (left_thigh) | hinge | torque (N m) | + | 8 | Torque applied on the rotor between torso/abdomen and the left hip (z-coordinate) | -1.0 | 1.0 | left_hip_z (left_thigh) | hinge | torque (N m) | + | 9 | Torque applied on the rotor between torso/abdomen and the left hip (y-coordinate) | -1.0 | 1.0 | left_hip_y (left_thigh) | hinge | torque (N m) | | 10 | Torque applied on the rotor between the left hip/thigh and the left shin | -1.0 | 1.0 | left_knee | hinge | torque (N m) | - | 11 | Torque applied on the rotor between the torso and right upper arm (coordinate -1) | -1.0 | 1.0 | right_shoulder12 | hinge | torque (N m) | - | 12 | Torque applied on the rotor between the torso and right upper arm (coordinate -2) | -1.0 | 1.0 | right_shoulder12 | hinge | torque (N m) | + | 11 | Torque applied on the rotor between the torso and right upper arm (coordinate -1) | -1.0 | 1.0 | right_shoulder1 | hinge | torque (N m) | + | 12 | Torque applied on the rotor between the torso and right upper arm (coordinate -2) | -1.0 | 1.0 | right_shoulder2 | hinge | torque (N m) | | 13 | Torque applied on the rotor between the right upper arm and right lower arm | -1.0 | 1.0 | right_elbow | hinge | torque (N m) | - | 14 | Torque applied on the rotor between the torso and left upper arm (coordinate -1) | -1.0 | 1.0 | left_shoulder12 | hinge | torque (N m) | - | 15 | Torque applied on the rotor between the torso and left upper arm (coordinate -2) | -1.0 | 1.0 | left_shoulder12 | hinge | torque (N m) | + | 14 | Torque applied on the rotor between the torso and left upper arm (coordinate -1) | -1.0 | 1.0 | left_shoulder1 | hinge | torque (N m) | + | 15 | Torque applied on the rotor between the torso and left upper arm (coordinate -2) | -1.0 | 1.0 | left_shoulder2 | hinge | torque (N m) | | 16 | Torque applied on the rotor between the left upper arm and left lower arm | -1.0 | 1.0 | left_elbow | hinge | torque (N m) | ### Observation Space @@ -74,7 +74,7 @@ class Humanoid(PipelineEnv): Humanoid, followed by the velocities of those individual parts (their derivatives) with all the positions ordered before all the velocities. - The observation is a `ndarray` with shape `(376,)` where the elements correspond to the following: + The observation is a `ndarray` with shape `(244,)` where the elements correspond to the following: | Num | Observation | Min | Max | Name (in corresponding config) | Joint | Unit | |-----|-----------------------------------------------------------------------------------------------------------------|------|-----|----------------------------------|-------|--------------------------| @@ -83,22 +83,22 @@ class Humanoid(PipelineEnv): | 2 | x-orientation of the torso (centre) | -Inf | Inf | root | free | angle (rad) | | 3 | y-orientation of the torso (centre) | -Inf | Inf | root | free | angle (rad) | | 4 | z-orientation of the torso (centre) | -Inf | Inf | root | free | angle (rad) | - | 5 | z-angle of the abdomen (in lower_waist) | -Inf | Inf | abdomen_yz | hinge | angle (rad) | - | 6 | y-angle of the abdomen (in lower_waist) | -Inf | Inf | abdomen_yy | hinge | angle (rad) | + | 5 | z-angle of the abdomen (in lower_waist) | -Inf | Inf | abdomen_z | hinge | angle (rad) | + | 6 | y-angle of the abdomen (in lower_waist) | -Inf | Inf | abdomen_y | hinge | angle (rad) | | 7 | x-angle of the abdomen (in pelvis) | -Inf | Inf | abdomen_x | hinge | angle (rad) | - | 8 | x-coordinate of angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_xyz | hinge | angle (rad) | - | 9 | y-coordinate of angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_xyz | hinge | angle (rad) | - | 10 | z-coordinate of angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_xyz | hinge | angle (rad) | + | 8 | x-coordinate of angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_x | hinge | angle (rad) | + | 9 | z-coordinate of angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_z | hinge | angle (rad) | + | 10 | y-coordinate of angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_y | hinge | angle (rad) | | 11 | angle between right hip and the right shin (in right_knee) | -Inf | Inf | right_knee | hinge | angle (rad) | - | 12 | x-coordinate of angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_xyz | hinge | angle (rad) | - | 13 | y-coordinate of angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_xyz | hinge | angle (rad) | - | 14 | z-coordinate of angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_xyz | hinge | angle (rad) | + | 12 | x-coordinate of angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_x | hinge | angle (rad) | + | 13 | z-coordinate of angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_z | hinge | angle (rad) | + | 14 | y-coordinate of angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_y | hinge | angle (rad) | | 15 | angle between left hip and the left shin (in left_knee) | -Inf | Inf | left_knee | hinge | angle (rad) | - | 16 | coordinate-1 (multi-axis) angle between torso and right arm (in right_upper_arm) | -Inf | Inf | right_shoulder12 | hinge | angle (rad) | - | 17 | coordinate-2 (multi-axis) angle between torso and right arm (in right_upper_arm) | -Inf | Inf | right_shoulder12 | hinge | angle (rad) | + | 16 | coordinate-1 (multi-axis) angle between torso and right arm (in right_upper_arm) | -Inf | Inf | right_shoulder1 | hinge | angle (rad) | + | 17 | coordinate-2 (multi-axis) angle between torso and right arm (in right_upper_arm) | -Inf | Inf | right_shoulder2 | hinge | angle (rad) | | 18 | angle between right upper arm and right_lower_arm | -Inf | Inf | right_elbow | hinge | angle (rad) | - | 19 | coordinate-1 (multi-axis) angle between torso and left arm (in left_upper_arm) | -Inf | Inf | left_shoulder12 | hinge | angle (rad) | - | 20 | coordinate-2 (multi-axis) angle between torso and left arm (in left_upper_arm) | -Inf | Inf | left_shoulder12 | hinge | angle (rad) | + | 19 | coordinate-1 (multi-axis) angle between torso and left arm (in left_upper_arm) | -Inf | Inf | left_shoulder1 | hinge | angle (rad) | + | 20 | coordinate-2 (multi-axis) angle between torso and left arm (in left_upper_arm) | -Inf | Inf | left_shoulder2 | hinge | angle (rad) | | 21 | angle between left upper arm and left_lower_arm | -Inf | Inf | left_elbow | hinge | angle (rad) | | 22 | x-coordinate velocity of the torso (centre) | -Inf | Inf | root | free | velocity (m/s) | | 23 | y-coordinate velocity of the torso (centre) | -Inf | Inf | root | free | velocity (m/s) | @@ -109,29 +109,29 @@ class Humanoid(PipelineEnv): | 28 | z-coordinate of angular velocity of the abdomen (in lower_waist) | -Inf | Inf | abdomen_z | hinge | angular velocity (rad/s) | | 29 | y-coordinate of angular velocity of the abdomen (in lower_waist) | -Inf | Inf | abdomen_y | hinge | angular velocity (rad/s) | | 30 | x-coordinate of angular velocity of the abdomen (in pelvis) | -Inf | Inf | abdomen_x | hinge | angular velocity (rad/s) | - | 31 | x-coordinate of the angular velocity of the angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_xyz | hinge | angular velocity (rad/s) | - | 32 | y-coordinate of the angular velocity of the angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_z | hinge | angular velocity (rad/s) | - | 33 | z-coordinate of the angular velocity of the angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_y | hinge | angular velocity (rad/s) | + | 31 | x-coordinate of the angular velocity of the angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_x | hinge | angular velocity (rad/s) | + | 32 | z-coordinate of the angular velocity of the angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_z | hinge | angular velocity (rad/s) | + | 33 | y-coordinate of the angular velocity of the angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_y | hinge | angular velocity (rad/s) | | 34 | angular velocity of the angle between right hip and the right shin (in right_knee) | -Inf | Inf | right_knee | hinge | angular velocity (rad/s) | - | 35 | x-coordinate of the angular velocity of the angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_xyz | hinge | angular velocity (rad/s) | - | 36 | y-coordinate of the angular velocity of the angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_z | hinge | angular velocity (rad/s) | - | 37 | z-coordinate of the angular velocity of the angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_y | hinge | angular velocity (rad/s) | + | 35 | x-coordinate of the angular velocity of the angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_x | hinge | angular velocity (rad/s) | + | 36 | z-coordinate of the angular velocity of the angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_z | hinge | angular velocity (rad/s) | + | 37 | y-coordinate of the angular velocity of the angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_y | hinge | angular velocity (rad/s) | | 38 | angular velocity of the angle between left hip and the left shin (in left_knee) | -Inf | Inf | left_knee | hinge | angular velocity (rad/s) | - | 39 | coordinate-1 (multi-axis) of the angular velocity of the angle between torso and right arm (in right_upper_arm) | -Inf | Inf | right_shoulder12 | hinge | angular velocity (rad/s) | - | 40 | coordinate-2 (multi-axis) of the angular velocity of the angle between torso and right arm (in right_upper_arm) | -Inf | Inf | right_shoulder12 | hinge | angular velocity (rad/s) | + | 39 | coordinate-1 (multi-axis) of the angular velocity of the angle between torso and right arm (in right_upper_arm) | -Inf | Inf | right_shoulder1 | hinge | angular velocity (rad/s) | + | 40 | coordinate-2 (multi-axis) of the angular velocity of the angle between torso and right arm (in right_upper_arm) | -Inf | Inf | right_shoulder2 | hinge | angular velocity (rad/s) | | 41 | angular velocity of the angle between right upper arm and right_lower_arm | -Inf | Inf | right_elbow | hinge | angular velocity (rad/s) | - | 42 | coordinate-1 (multi-axis) of the angular velocity of the angle between torso and left arm (in left_upper_arm) | -Inf | Inf | left_shoulder12 | hinge | angular velocity (rad/s) | - | 43 | coordinate-2 (multi-axis) of the angular velocity of the angle between torso and left arm (in left_upper_arm) | -Inf | Inf | left_shoulder12 | hinge | angular velocity (rad/s) | + | 42 | coordinate-1 (multi-axis) of the angular velocity of the angle between torso and left arm (in left_upper_arm) | -Inf | Inf | left_shoulder1 | hinge | angular velocity (rad/s) | + | 43 | coordinate-2 (multi-axis) of the angular velocity of the angle between torso and left arm (in left_upper_arm) | -Inf | Inf | left_shoulder2 | hinge | angular velocity (rad/s) | | 44 | angular velocity of the angle between left upper arm and left_lower_arm | -Inf | Inf | left_elbow | hinge | angular velocity (rad/s) | Additionally, after all the positional and velocity based values in the table, the state_space consists of (in order): - *cinert:* Mass and inertia of a single rigid body relative to the center of - mass (this is an intermediate result of transition). It has shape 14*10 - (*nbody * 10*) and hence adds to another 140 elements in the state space. - - *cvel:* Center of mass based velocity. It has shape 14 * 6 (*nbody * 6*) and - hence adds another 84 elements in the state space + mass (this is an intermediate result of transition). It has shape 11*10 + (*nlinks * 10*) and hence adds to another 110 elements in the state space. + - *cvel:* Center of mass based velocity. It has shape 11 * 6 (*nlinks * 6*) and + hence adds another 66 elements in the state space - *qfrc_actuator:* Constraint force generated as the actuator force. This has shape `(23,)` *(nv * 1)* and hence adds another 23 elements to the state space. diff --git a/brax/envs/humanoidstandup.py b/brax/envs/humanoidstandup.py index 5ffdd532a..4b150a28c 100644 --- a/brax/envs/humanoidstandup.py +++ b/brax/envs/humanoidstandup.py @@ -52,22 +52,22 @@ class HumanoidStandup(PipelineEnv): | Num | Action | Control Min | Control Max | Name (in corresponding config) | Joint | Unit | |-----|------------------------------------------------------------------------------------|-------------|-------------|----------------------------------|-------|--------------| - | 0 | Torque applied on the hinge in the y-coordinate of the abdomen | -1.0 | 1.0 | abdomen_yz | hinge | torque (N m) | - | 1 | Torque applied on the hinge in the z-coordinate of the abdomen | -1.0 | 1.0 | abdomen_yz | hinge | torque (N m) | + | 0 | Torque applied on the hinge in the y-coordinate of the abdomen | -1.0 | 1.0 | abdomen_y | hinge | torque (N m) | + | 1 | Torque applied on the hinge in the z-coordinate of the abdomen | -1.0 | 1.0 | abdomen_z | hinge | torque (N m) | | 2 | Torque applied on the hinge in the x-coordinate of the abdomen | -1.0 | 1.0 | abdomen_x | hinge | torque (N m) | - | 3 | Torque applied on the rotor between torso/abdomen and the right hip (x-coordinate) | -1.0 | 1.0 | right_hip_xyz (right_thigh) | hinge | torque (N m) | - | 4 | Torque applied on the rotor between torso/abdomen and the right hip (y-coordinate) | -1.0 | 1.0 | right_hip_xyz (right_thigh) | hinge | torque (N m) | - | 5 | Torque applied on the rotor between torso/abdomen and the right hip (z-coordinate) | -1.0 | 1.0 | right_hip_xyz (right_thigh) | hinge | torque (N m) | + | 3 | Torque applied on the rotor between torso/abdomen and the right hip (x-coordinate) | -1.0 | 1.0 | right_hip_x (right_thigh) | hinge | torque (N m) | + | 4 | Torque applied on the rotor between torso/abdomen and the right hip (z-coordinate) | -1.0 | 1.0 | right_hip_z (right_thigh) | hinge | torque (N m) | + | 5 | Torque applied on the rotor between torso/abdomen and the right hip (y-coordinate) | -1.0 | 1.0 | right_hip_y (right_thigh) | hinge | torque (N m) | | 6 | Torque applied on the rotor between the right hip/thigh and the right shin | -1.0 | 1.0 | right_knee | hinge | torque (N m) | - | 7 | Torque applied on the rotor between torso/abdomen and the left hip (x-coordinate) | -1.0 | 1.0 | left_hip_xyz (left_thigh) | hinge | torque (N m) | - | 8 | Torque applied on the rotor between torso/abdomen and the left hip (y-coordinate) | -1.0 | 1.0 | left_hip_xyz (left_thigh) | hinge | torque (N m) | - | 9 | Torque applied on the rotor between torso/abdomen and the left hip (z-coordinate) | -1.0 | 1.0 | left_hip_xyz (left_thigh) | hinge | torque (N m) | + | 7 | Torque applied on the rotor between torso/abdomen and the left hip (x-coordinate) | -1.0 | 1.0 | left_hip_x (left_thigh) | hinge | torque (N m) | + | 8 | Torque applied on the rotor between torso/abdomen and the left hip (z-coordinate) | -1.0 | 1.0 | left_hip_z (left_thigh) | hinge | torque (N m) | + | 9 | Torque applied on the rotor between torso/abdomen and the left hip (y-coordinate) | -1.0 | 1.0 | left_hip_y (left_thigh) | hinge | torque (N m) | | 10 | Torque applied on the rotor between the left hip/thigh and the left shin | -1.0 | 1.0 | left_knee | hinge | torque (N m) | - | 11 | Torque applied on the rotor between the torso and right upper arm (coordinate -1) | -1.0 | 1.0 | right_shoulder12 | hinge | torque (N m) | - | 12 | Torque applied on the rotor between the torso and right upper arm (coordinate -2) | -1.0 | 1.0 | right_shoulder12 | hinge | torque (N m) | + | 11 | Torque applied on the rotor between the torso and right upper arm (coordinate -1) | -1.0 | 1.0 | right_shoulder1 | hinge | torque (N m) | + | 12 | Torque applied on the rotor between the torso and right upper arm (coordinate -2) | -1.0 | 1.0 | right_shoulder2 | hinge | torque (N m) | | 13 | Torque applied on the rotor between the right upper arm and right lower arm | -1.0 | 1.0 | right_elbow | hinge | torque (N m) | - | 14 | Torque applied on the rotor between the torso and left upper arm (coordinate -1) | -1.0 | 1.0 | left_shoulder12 | hinge | torque (N m) | - | 15 | Torque applied on the rotor between the torso and left upper arm (coordinate -2) | -1.0 | 1.0 | left_shoulder12 | hinge | torque (N m) | + | 14 | Torque applied on the rotor between the torso and left upper arm (coordinate -1) | -1.0 | 1.0 | left_shoulder1 | hinge | torque (N m) | + | 15 | Torque applied on the rotor between the torso and left upper arm (coordinate -2) | -1.0 | 1.0 | left_shoulder2 | hinge | torque (N m) | | 16 | Torque applied on the rotor between the left upper arm and left lower arm | -1.0 | 1.0 | left_elbow | hinge | torque (N m) | ### Observation Space @@ -76,7 +76,7 @@ class HumanoidStandup(PipelineEnv): Humanoid, followed by the velocities of those individual parts (their derivatives) with all the positions ordered before all the velocities. - The observation is a `ndarray` with shape `(376,)` where the elements + The observation is a `ndarray` with shape `(244,)` where the elements correspond to the following: | Num | Observation | Min | Max | Name (in corresponding config) | Joint | Unit | @@ -86,22 +86,22 @@ class HumanoidStandup(PipelineEnv): | 2 | x-orientation of the torso (centre) | -Inf | Inf | root | free | angle (rad) | | 3 | y-orientation of the torso (centre) | -Inf | Inf | root | free | angle (rad) | | 4 | z-orientation of the torso (centre) | -Inf | Inf | root | free | angle (rad) | - | 5 | z-angle of the abdomen (in lower_waist) | -Inf | Inf | abdomen_yz | hinge | angle (rad) | - | 6 | y-angle of the abdomen (in lower_waist) | -Inf | Inf | abdomen_yy | hinge | angle (rad) | + | 5 | z-angle of the abdomen (in lower_waist) | -Inf | Inf | abdomen_z | hinge | angle (rad) | + | 6 | y-angle of the abdomen (in lower_waist) | -Inf | Inf | abdomen_y | hinge | angle (rad) | | 7 | x-angle of the abdomen (in pelvis) | -Inf | Inf | abdomen_x | hinge | angle (rad) | - | 8 | x-coordinate of angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_xyz | hinge | angle (rad) | - | 9 | y-coordinate of angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_xyz | hinge | angle (rad) | - | 10 | z-coordinate of angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_xyz | hinge | angle (rad) | + | 8 | x-coordinate of angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_x | hinge | angle (rad) | + | 9 | z-coordinate of angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_z | hinge | angle (rad) | + | 10 | y-coordinate of angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_y | hinge | angle (rad) | | 11 | angle between right hip and the right shin (in right_knee) | -Inf | Inf | right_knee | hinge | angle (rad) | - | 12 | x-coordinate of angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_xyz | hinge | angle (rad) | - | 13 | y-coordinate of angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_xyz | hinge | angle (rad) | - | 14 | z-coordinate of angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_xyz | hinge | angle (rad) | + | 12 | x-coordinate of angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_x | hinge | angle (rad) | + | 13 | z-coordinate of angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_z | hinge | angle (rad) | + | 14 | y-coordinate of angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_y | hinge | angle (rad) | | 15 | angle between left hip and the left shin (in left_knee) | -Inf | Inf | left_knee | hinge | angle (rad) | - | 16 | coordinate-1 (multi-axis) angle between torso and right arm (in right_upper_arm) | -Inf | Inf | right_shoulder12 | hinge | angle (rad) | - | 17 | coordinate-2 (multi-axis) angle between torso and right arm (in right_upper_arm) | -Inf | Inf | right_shoulder12 | hinge | angle (rad) | + | 16 | coordinate-1 (multi-axis) angle between torso and right arm (in right_upper_arm) | -Inf | Inf | right_shoulder1 | hinge | angle (rad) | + | 17 | coordinate-2 (multi-axis) angle between torso and right arm (in right_upper_arm) | -Inf | Inf | right_shoulder2 | hinge | angle (rad) | | 18 | angle between right upper arm and right_lower_arm | -Inf | Inf | right_elbow | hinge | angle (rad) | - | 19 | coordinate-1 (multi-axis) angle between torso and left arm (in left_upper_arm) | -Inf | Inf | left_shoulder12 | hinge | angle (rad) | - | 20 | coordinate-2 (multi-axis) angle between torso and left arm (in left_upper_arm) | -Inf | Inf | left_shoulder12 | hinge | angle (rad) | + | 19 | coordinate-1 (multi-axis) angle between torso and left arm (in left_upper_arm) | -Inf | Inf | left_shoulder1 | hinge | angle (rad) | + | 20 | coordinate-2 (multi-axis) angle between torso and left arm (in left_upper_arm) | -Inf | Inf | left_shoulder2 | hinge | angle (rad) | | 21 | angle between left upper arm and left_lower_arm | -Inf | Inf | left_elbow | hinge | angle (rad) | | 22 | x-coordinate velocity of the torso (centre) | -Inf | Inf | root | free | velocity (m/s) | | 23 | y-coordinate velocity of the torso (centre) | -Inf | Inf | root | free | velocity (m/s) | @@ -112,29 +112,29 @@ class HumanoidStandup(PipelineEnv): | 28 | z-coordinate of angular velocity of the abdomen (in lower_waist) | -Inf | Inf | abdomen_z | hinge | angular velocity (rad/s) | | 29 | y-coordinate of angular velocity of the abdomen (in lower_waist) | -Inf | Inf | abdomen_y | hinge | angular velocity (rad/s) | | 30 | x-coordinate of angular velocity of the abdomen (in pelvis) | -Inf | Inf | abdomen_x | hinge | angular velocity (rad/s) | - | 31 | x-coordinate of the angular velocity of the angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_xyz | hinge | angular velocity (rad/s) | - | 32 | y-coordinate of the angular velocity of the angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_z | hinge | angular velocity (rad/s) | - | 33 | z-coordinate of the angular velocity of the angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_y | hinge | angular velocity (rad/s) | + | 31 | x-coordinate of the angular velocity of the angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_x | hinge | angular velocity (rad/s) | + | 32 | z-coordinate of the angular velocity of the angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_z | hinge | angular velocity (rad/s) | + | 33 | y-coordinate of the angular velocity of the angle between pelvis and right hip (in right_thigh) | -Inf | Inf | right_hip_y | hinge | angular velocity (rad/s) | | 34 | angular velocity of the angle between right hip and the right shin (in right_knee) | -Inf | Inf | right_knee | hinge | angular velocity (rad/s) | - | 35 | x-coordinate of the angular velocity of the angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_xyz | hinge | angular velocity (rad/s) | - | 36 | y-coordinate of the angular velocity of the angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_z | hinge | angular velocity (rad/s) | - | 37 | z-coordinate of the angular velocity of the angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_y | hinge | angular velocity (rad/s) | + | 35 | x-coordinate of the angular velocity of the angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_x | hinge | angular velocity (rad/s) | + | 36 | z-coordinate of the angular velocity of the angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_z | hinge | angular velocity (rad/s) | + | 37 | y-coordinate of the angular velocity of the angle between pelvis and left hip (in left_thigh) | -Inf | Inf | left_hip_y | hinge | angular velocity (rad/s) | | 38 | angular velocity of the angle between left hip and the left shin (in left_knee) | -Inf | Inf | left_knee | hinge | angular velocity (rad/s) | - | 39 | coordinate-1 (multi-axis) of the angular velocity of the angle between torso and right arm (in right_upper_arm) | -Inf | Inf | right_shoulder12 | hinge | angular velocity (rad/s) | - | 40 | coordinate-2 (multi-axis) of the angular velocity of the angle between torso and right arm (in right_upper_arm) | -Inf | Inf | right_shoulder12 | hinge | angular velocity (rad/s) | + | 39 | coordinate-1 (multi-axis) of the angular velocity of the angle between torso and right arm (in right_upper_arm) | -Inf | Inf | right_shoulder1 | hinge | angular velocity (rad/s) | + | 40 | coordinate-2 (multi-axis) of the angular velocity of the angle between torso and right arm (in right_upper_arm) | -Inf | Inf | right_shoulder2 | hinge | angular velocity (rad/s) | | 41 | angular velocity of the angle between right upper arm and right_lower_arm | -Inf | Inf | right_elbow | hinge | angular velocity (rad/s) | - | 42 | coordinate-1 (multi-axis) of the angular velocity of the angle between torso and left arm (in left_upper_arm) | -Inf | Inf | left_shoulder12 | hinge | angular velocity (rad/s) | - | 43 | coordinate-2 (multi-axis) of the angular velocity of the angle between torso and left arm (in left_upper_arm) | -Inf | Inf | left_shoulder12 | hinge | angular velocity (rad/s) | + | 42 | coordinate-1 (multi-axis) of the angular velocity of the angle between torso and left arm (in left_upper_arm) | -Inf | Inf | left_shoulder1 | hinge | angular velocity (rad/s) | + | 43 | coordinate-2 (multi-axis) of the angular velocity of the angle between torso and left arm (in left_upper_arm) | -Inf | Inf | left_shoulder2 | hinge | angular velocity (rad/s) | | 44 | angular velocity of the angle between left upper arm and left_lower_arm | -Inf | Inf | left_elbow | hinge | angular velocity (rad/s) | Additionally, after all the positional and velocity based values in the table, the state_space consists of (in order): - *cinert:* Mass and inertia of a single rigid body relative to the center of - mass (this is an intermediate result of transition). It has shape 14*10 - (*nbody * 10*) and hence adds to another 140 elements in the state space. - - *cvel:* Center of mass based velocity. It has shape 14 * 6 (*nbody * 6*) and - hence adds another 84 elements in the state space + mass (this is an intermediate result of transition). It has shape 11*10 + (*nlinks * 10*) and hence adds to another 110 elements in the state space. + - *cvel:* Center of mass based velocity. It has shape 11 * 6 (*nlinks * 6*) and + hence adds another 66 elements in the state space - *qfrc_actuator:* Constraint force generated as the actuator force. This has shape `(23,)` *(nv * 1)* and hence adds another 23 elements to the state space. diff --git a/tests/envs_doc_test.py b/tests/envs_doc_test.py new file mode 100644 index 000000000..648f7defc --- /dev/null +++ b/tests/envs_doc_test.py @@ -0,0 +1,178 @@ +# Copyright 2026 The Brax Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests that environment docstrings match their MJCF XML definitions.""" + +import ast +import pathlib +import re +from xml.etree import ElementTree + +from absl.testing import absltest + +_ENVS_DIR = pathlib.Path(__file__).resolve().parent.parent / 'brax' / 'envs' +_ASSETS_DIR = _ENVS_DIR / 'assets' + + +def _get_class_docstring(env_file: str, class_name: str) -> str: + tree = ast.parse((_ENVS_DIR / env_file).read_text(encoding='utf-8')) + for node in tree.body: + if isinstance(node, ast.ClassDef) and node.name == class_name: + doc = ast.get_docstring(node, clean=False) + assert doc is not None + return doc + raise AssertionError(f'Class {class_name} not found in {env_file}') + + +def _parse_markdown_table(section: str) -> list[list[str]]: + rows = [] + for line in section.splitlines(): + stripped = line.strip() + if not stripped.startswith('|'): + continue + cells = [cell.strip() for cell in stripped.strip('|').split('|')] + if not cells or cells[0] == 'Num' or set(cells[0]) == {'-'}: + continue + rows.append(cells) + return rows + + +def _section(doc: str, header: str) -> str: + pattern = rf'### {re.escape(header)}\s*(.*?)(?=\n\s*### |\Z)' + match = re.search(pattern, doc, flags=re.DOTALL) + assert match is not None, f'Section {header} not found' + return match.group(1) + + +def _xml_actuators(xml_file: str) -> list[str]: + root = ElementTree.fromstring( + (_ASSETS_DIR / xml_file).read_text(encoding='utf-8') + ) + return [elem.attrib['joint'] for elem in root.findall('./actuator/motor')] + + +def _xml_joints(xml_file: str) -> list[str]: + root = ElementTree.fromstring( + (_ASSETS_DIR / xml_file).read_text(encoding='utf-8') + ) + joints = [] + + def walk(elem: ElementTree.Element) -> None: + for child in elem: + if child.tag == 'joint': + joints.append(child.attrib['name']) + else: + walk(child) + + worldbody = root.find('worldbody') + assert worldbody is not None + walk(worldbody) + return joints + + +def _xml_fused_link_count(xml_file: str) -> int: + root = ElementTree.fromstring( + (_ASSETS_DIR / xml_file).read_text(encoding='utf-8') + ) + worldbody = root.find('worldbody') + assert worldbody is not None + return sum( + 1 + for body in worldbody.iter('body') + if body.find('joint') is not None or body.find('freejoint') is not None + ) + + +class EnvsDocTest(absltest.TestCase): + + def test_ant_action_and_observation_ordering(self): + doc = _get_class_docstring('ant.py', 'Ant') + + action_rows = _parse_markdown_table(_section(doc, 'Action Space')) + expected_actuators = _xml_actuators('ant.xml') + self.assertLen(action_rows, len(expected_actuators)) + for idx, (row, joint) in enumerate(zip(action_rows, expected_actuators)): + self.assertEqual(row[0], str(idx)) + self.assertTrue( + row[4].startswith(f'{joint} '), + f'Action row {idx} expected {joint}, got {row[4]}', + ) + + obs_rows = _parse_markdown_table(_section(doc, 'Observation Space')) + hinge_joints = _xml_joints('ant.xml')[1:] # skip root free joint + self.assertLen(obs_rows, 5 + len(hinge_joints) + 6 + len(hinge_joints)) + for offset, joint in enumerate(hinge_joints): + self.assertTrue( + obs_rows[5 + offset][4].startswith(f'{joint} '), + f'Obs qpos row {5 + offset} expected {joint}, got ' + f'{obs_rows[5 + offset][4]}', + ) + vel_idx = 5 + len(hinge_joints) + 6 + offset + self.assertTrue( + obs_rows[vel_idx][4].startswith(f'{joint} '), + f'Obs qvel row {vel_idx} expected {joint}, got ' + f'{obs_rows[vel_idx][4]}', + ) + + term_section = _section(doc, 'Episode Termination') + self.assertIn('z-coordinate of the torso (index 0)', term_section) + + def test_humanoid_and_standup_spaces_match_xml(self): + for env_file, class_name, xml_file in [ + ('humanoid.py', 'Humanoid', 'humanoid.xml'), + ('humanoidstandup.py', 'HumanoidStandup', 'humanoidstandup.xml'), + ]: + with self.subTest(env_file=env_file): + doc = _get_class_docstring(env_file, class_name) + + action_rows = _parse_markdown_table(_section(doc, 'Action Space')) + expected_actuators = _xml_actuators(xml_file) + self.assertLen(action_rows, len(expected_actuators)) + for idx, (row, joint) in enumerate( + zip(action_rows, expected_actuators) + ): + self.assertEqual(row[0], str(idx)) + self.assertTrue( + row[4] == joint or row[4].startswith(f'{joint} '), + f'{env_file} action row {idx} expected {joint}, got {row[4]}', + ) + if joint.endswith(('_x', '_y', '_z')): + self.assertIn(f'{joint[-1]}-coordinate', row[1]) + + obs_section = _section(doc, 'Observation Space') + nlinks = _xml_fused_link_count(xml_file) + hinge_joints = _xml_joints(xml_file)[1:] # skip root free joint + nq = 5 + len(hinge_joints) + nv = 6 + len(hinge_joints) + expected_obs_dim = nq + nv + nlinks * 10 + nlinks * 6 + nv + self.assertIn(f'shape `({expected_obs_dim},)`', obs_section) + + obs_rows = _parse_markdown_table(obs_section) + self.assertLen(obs_rows, nq + nv) + for offset, joint in enumerate(hinge_joints): + qpos_row = obs_rows[5 + offset] + qvel_row = obs_rows[nq + 6 + offset] + self.assertEqual(qpos_row[4], joint) + self.assertEqual(qvel_row[4], joint) + if joint.endswith(('_x', '_y', '_z')): + axis = joint[-1] + self.assertTrue( + f'{axis}-angle' in qpos_row[1] + or f'{axis}-coordinate' in qpos_row[1] + ) + self.assertIn(f'{axis}-coordinate', qvel_row[1]) + + +if __name__ == '__main__': + absltest.main()