<liclass="toctree-l1 current has-children"><aclass="reference internal"href="../">MuJoCo</a><inputchecked=""class="toctree-checkbox"id="toctree-checkbox-6"name="toctree-checkbox-6"role="switch"type="checkbox"/><labelfor="toctree-checkbox-6"><divclass="visually-hidden">Toggle child pages in navigation</div><iclass="icon"><svg><usehref="#svg-arrow-right"></use></svg></i></label><ulclass="current">
<liclass="toctree-l2 current current-page"><aclass="current reference internal"href="#">Ant</a></li>
<liclass="toctree-l1"><aclass="reference external"href="https://github.com/Farama-Foundation/Gymnasium/blob/main/docs/README.md">Contribute to the Docs</a></li>
<h2>Description<aclass="headerlink"href="#description"title="Permalink to this heading">#</a></h2>
<p>This environment is based on the environment introduced by Schulman,
Moritz, Levine, Jordan and Abbeel in <aclass="reference external"href="https://arxiv.org/abs/1506.02438">“High-Dimensional Continuous Control
Using Generalized Advantage Estimation”</a>.
The ant is a 3D robot consisting of one torso (free rotational body) with
four legs attached to it with each leg having two links. The goal is to
coordinate the four legs to move in the forward (right) direction by applying
torques on the eight hinges connecting the two links of each leg and the torso
(nine parts and eight hinges).</p>
</section>
<sectionid="action-space">
<h2>Action Space<aclass="headerlink"href="#action-space"title="Permalink to this heading">#</a></h2>
<p>The action space is a <codeclass="docutils literal notranslate"><spanclass="pre">Box(-1,</span><spanclass="pre">1,</span><spanclass="pre">(8,),</span><spanclass="pre">float32)</span></code>. An action represents the torques applied at the hinge joints.</p>
<thclass="head"><p>Name (in corresponding XML file)</p></th>
<thclass="head"><p>Joint</p></th>
<thclass="head"><p>Unit</p></th>
</tr>
</thead>
<tbody>
<trclass="row-even"><td><p>0</p></td>
<td><p>Torque applied on the rotor between the torso and front left hip</p></td>
<td><p>-1</p></td>
<td><p>1</p></td>
<td><p>hip_1 (front_left_leg)</p></td>
<td><p>hinge</p></td>
<td><p>torque (N m)</p></td>
</tr>
<trclass="row-odd"><td><p>1</p></td>
<td><p>Torque applied on the rotor between the front left two links</p></td>
<td><p>-1</p></td>
<td><p>1</p></td>
<td><p>angle_1 (front_left_leg)</p></td>
<td><p>hinge</p></td>
<td><p>torque (N m)</p></td>
</tr>
<trclass="row-even"><td><p>2</p></td>
<td><p>Torque applied on the rotor between the torso and front right hip</p></td>
<td><p>-1</p></td>
<td><p>1</p></td>
<td><p>hip_2 (front_right_leg)</p></td>
<td><p>hinge</p></td>
<td><p>torque (N m)</p></td>
</tr>
<trclass="row-odd"><td><p>3</p></td>
<td><p>Torque applied on the rotor between the front right two links</p></td>
<td><p>-1</p></td>
<td><p>1</p></td>
<td><p>angle_2 (front_right_leg)</p></td>
<td><p>hinge</p></td>
<td><p>torque (N m)</p></td>
</tr>
<trclass="row-even"><td><p>4</p></td>
<td><p>Torque applied on the rotor between the torso and back left hip</p></td>
<td><p>-1</p></td>
<td><p>1</p></td>
<td><p>hip_3 (back_leg)</p></td>
<td><p>hinge</p></td>
<td><p>torque (N m)</p></td>
</tr>
<trclass="row-odd"><td><p>5</p></td>
<td><p>Torque applied on the rotor between the back left two links</p></td>
<td><p>-1</p></td>
<td><p>1</p></td>
<td><p>angle_3 (back_leg)</p></td>
<td><p>hinge</p></td>
<td><p>torque (N m)</p></td>
</tr>
<trclass="row-even"><td><p>6</p></td>
<td><p>Torque applied on the rotor between the torso and back right hip</p></td>
<td><p>-1</p></td>
<td><p>1</p></td>
<td><p>hip_4 (right_back_leg)</p></td>
<td><p>hinge</p></td>
<td><p>torque (N m)</p></td>
</tr>
<trclass="row-odd"><td><p>7</p></td>
<td><p>Torque applied on the rotor between the back right two links</p></td>
<td><p>-1</p></td>
<td><p>1</p></td>
<td><p>angle_4 (right_back_leg)</p></td>
<td><p>hinge</p></td>
<td><p>torque (N m)</p></td>
</tr>
</tbody>
</table>
</div>
</section>
<sectionid="observation-space">
<h2>Observation Space<aclass="headerlink"href="#observation-space"title="Permalink to this heading">#</a></h2>
<p>Observations consist of positional values of different body parts of the ant,
followed by the velocities of those individual parts (their derivatives) with all
the positions ordered before all the velocities.</p>
<p>By default, observations do not include the x- and y-coordinates of the ant’s torso. These may
be included by passing <codeclass="docutils literal notranslate"><spanclass="pre">exclude_current_positions_from_observation=False</span></code> during construction.
In that case, the observation space will have 113 dimensions where the first two dimensions
represent the x- and y- coordinates of the ant’s torso.
Regardless of whether <codeclass="docutils literal notranslate"><spanclass="pre">exclude_current_positions_from_observation</span></code> was set to true or false, the x- and y-coordinates
of the torso will be returned in <codeclass="docutils literal notranslate"><spanclass="pre">info</span></code> with keys <codeclass="docutils literal notranslate"><spanclass="pre">"x_position"</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">"y_position"</span></code>, respectively.</p>
<p>However, by default, an observation is a <codeclass="docutils literal notranslate"><spanclass="pre">ndarray</span></code> with shape <codeclass="docutils literal notranslate"><spanclass="pre">(111,)</span></code>
where the elements correspond to the following:</p>
<thclass="head"><p>Name (in corresponding XML file)</p></th>
<thclass="head"><p>Joint</p></th>
<thclass="head"><p>Unit</p></th>
</tr>
</thead>
<tbody>
<trclass="row-even"><td><p>0</p></td>
<td><p>z-coordinate of the torso (centre)</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>torso</p></td>
<td><p>free</p></td>
<td><p>position (m)</p></td>
</tr>
<trclass="row-odd"><td><p>1</p></td>
<td><p>x-orientation of the torso (centre)</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>torso</p></td>
<td><p>free</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-even"><td><p>2</p></td>
<td><p>y-orientation of the torso (centre)</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>torso</p></td>
<td><p>free</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-odd"><td><p>3</p></td>
<td><p>z-orientation of the torso (centre)</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>torso</p></td>
<td><p>free</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-even"><td><p>4</p></td>
<td><p>w-orientation of the torso (centre)</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>torso</p></td>
<td><p>free</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-odd"><td><p>5</p></td>
<td><p>angle between torso and first link on front left</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>hip_1 (front_left_leg)</p></td>
<td><p>hinge</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-even"><td><p>6</p></td>
<td><p>angle between the two links on the front left</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>ankle_1 (front_left_leg)</p></td>
<td><p>hinge</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-odd"><td><p>7</p></td>
<td><p>angle between torso and first link on front right</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>hip_2 (front_right_leg)</p></td>
<td><p>hinge</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-even"><td><p>8</p></td>
<td><p>angle between the two links on the front right</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>ankle_2 (front_right_leg)</p></td>
<td><p>hinge</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-odd"><td><p>9</p></td>
<td><p>angle between torso and first link on back left</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>hip_3 (back_leg)</p></td>
<td><p>hinge</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-even"><td><p>10</p></td>
<td><p>angle between the two links on the back left</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>ankle_3 (back_leg)</p></td>
<td><p>hinge</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-odd"><td><p>11</p></td>
<td><p>angle between torso and first link on back right</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>hip_4 (right_back_leg)</p></td>
<td><p>hinge</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-even"><td><p>12</p></td>
<td><p>angle between the two links on the back right</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>ankle_4 (right_back_leg)</p></td>
<td><p>hinge</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-odd"><td><p>13</p></td>
<td><p>x-coordinate velocity of the torso</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>torso</p></td>
<td><p>free</p></td>
<td><p>velocity (m/s)</p></td>
</tr>
<trclass="row-even"><td><p>14</p></td>
<td><p>y-coordinate velocity of the torso</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>torso</p></td>
<td><p>free</p></td>
<td><p>velocity (m/s)</p></td>
</tr>
<trclass="row-odd"><td><p>15</p></td>
<td><p>z-coordinate velocity of the torso</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>torso</p></td>
<td><p>free</p></td>
<td><p>velocity (m/s)</p></td>
</tr>
<trclass="row-even"><td><p>16</p></td>
<td><p>x-coordinate angular velocity of the torso</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>torso</p></td>
<td><p>free</p></td>
<td><p>angular velocity (rad/s)</p></td>
</tr>
<trclass="row-odd"><td><p>17</p></td>
<td><p>y-coordinate angular velocity of the torso</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>torso</p></td>
<td><p>free</p></td>
<td><p>angular velocity (rad/s)</p></td>
</tr>
<trclass="row-even"><td><p>18</p></td>
<td><p>z-coordinate angular velocity of the torso</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>torso</p></td>
<td><p>free</p></td>
<td><p>angular velocity (rad/s)</p></td>
</tr>
<trclass="row-odd"><td><p>19</p></td>
<td><p>angular velocity of angle between torso and front left link</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>hip_1 (front_left_leg)</p></td>
<td><p>hinge</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-even"><td><p>20</p></td>
<td><p>angular velocity of the angle between front left links</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>ankle_1 (front_left_leg)</p></td>
<td><p>hinge</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-odd"><td><p>21</p></td>
<td><p>angular velocity of angle between torso and front right link</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>hip_2 (front_right_leg)</p></td>
<td><p>hinge</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-even"><td><p>22</p></td>
<td><p>angular velocity of the angle between front right links</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>ankle_2 (front_right_leg)</p></td>
<td><p>hinge</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-odd"><td><p>23</p></td>
<td><p>angular velocity of angle between torso and back left link</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>hip_3 (back_leg)</p></td>
<td><p>hinge</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-even"><td><p>24</p></td>
<td><p>angular velocity of the angle between back left links</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>ankle_3 (back_leg)</p></td>
<td><p>hinge</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-odd"><td><p>25</p></td>
<td><p>angular velocity of angle between torso and back right link</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>hip_4 (right_back_leg)</p></td>
<td><p>hinge</p></td>
<td><p>angle (rad)</p></td>
</tr>
<trclass="row-even"><td><p>26</p></td>
<td><p>angular velocity of the angle between back right links</p></td>
<td><p>-Inf</p></td>
<td><p>Inf</p></td>
<td><p>ankle_4 (right_back_leg)</p></td>
<td><p>hinge</p></td>
<td><p>angle (rad)</p></td>
</tr>
</tbody>
</table>
</div>
<p>The remaining 14*6 = 84 elements of the observation are contact forces
(external forces - force x, y, z and torque x, y, z) applied to the
center of mass of each of the links. The 14 links are: the ground link,
the torso link, and 3 links for each leg (1 + 1 + 12) with the 6 external forces.</p>
<p>The (x,y,z) coordinates are translational DOFs while the orientations are rotational
DOFs expressed as quaternions. One can read more about free joints on the <aclass="reference external"href="https://mujoco.readthedocs.io/en/latest/XMLreference.html">Mujoco Documentation</a>.</p>
<p><strong>Note:</strong> Ant-v4 environment no longer has the following contact forces issue.
If using previous Humanoid versions from v4, there have been reported issues that using a Mujoco-Py version > 2.0 results
in the contact forces always being 0. As such we recommend to use a Mujoco-Py version < 2.0
when using the Ant environment if you would like to report results with contact forces (if
contact forces are not used in your experiments, you can use version > 2.0).</p>
</section>
<sectionid="rewards">
<h2>Rewards<aclass="headerlink"href="#rewards"title="Permalink to this heading">#</a></h2>
<p>The reward consists of three parts:</p>
<ulclass="simple">
<li><p><em>healthy_reward</em>: Every timestep that the ant is healthy (see definition in section “Episode Termination”), it gets a reward of fixed value <codeclass="docutils literal notranslate"><spanclass="pre">healthy_reward</span></code></p></li>
<li><p><em>forward_reward</em>: A reward of moving forward which is measured as
<em>(x-coordinate before action - x-coordinate after action)/dt</em>. <em>dt</em> is the time
between actions and is dependent on the <codeclass="docutils literal notranslate"><spanclass="pre">frame_skip</span></code> parameter (default is 5),
where the frametime is 0.01 - making the default <em>dt = 5 * 0.01 = 0.05</em>.
This reward would be positive if the ant moves forward (in positive x direction).</p></li>
<li><p><em>ctrl_cost</em>: A negative reward for penalising the ant if it takes actions
that are too large. It is measured as <em><codeclass="docutils literal notranslate"><spanclass="pre">ctrl_cost_weight</span></code> * sum(action<sup>2</sup>)</em>
where <em><codeclass="docutils literal notranslate"><spanclass="pre">ctr_cost_weight</span></code></em> is a parameter set for the control and has a default value of 0.5.</p></li>
<li><p><em>contact_cost</em>: A negative reward for penalising the ant if the external contact
force is too large. It is calculated <em><codeclass="docutils literal notranslate"><spanclass="pre">contact_cost_weight</span></code> * sum(clip(external contact
force to <codeclass="docutils literal notranslate"><spanclass="pre">contact_force_range</span></code>)<sup>2</sup>)</em>.</p></li>
</ul>
<p>The total reward returned is <em><strong>reward</strong></em><em>=</em><em>healthy_reward + forward_reward - ctrl_cost - contact_cost</em> and <codeclass="docutils literal notranslate"><spanclass="pre">info</span></code> will also contain the individual reward terms.</p>
</section>
<sectionid="starting-state">
<h2>Starting State<aclass="headerlink"href="#starting-state"title="Permalink to this heading">#</a></h2>
<p>All observations start in state
(0.0, 0.0, 0.75, 1.0, 0.0 … 0.0) with a uniform noise in the range
of [-<codeclass="docutils literal notranslate"><spanclass="pre">reset_noise_scale</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">reset_noise_scale</span></code>] added to the positional values and standard normal noise
with mean 0 and standard deviation <codeclass="docutils literal notranslate"><spanclass="pre">reset_noise_scale</span></code> added to the velocity values for
stochasticity. Note that the initial z coordinate is intentionally selected
to be slightly high, thereby indicating a standing up ant. The initial orientation
is designed to make it face forward as well.</p>
</section>
<sectionid="episode-end">
<h2>Episode End<aclass="headerlink"href="#episode-end"title="Permalink to this heading">#</a></h2>
<p>The ant is said to be unhealthy if any of the following happens:</p>
<olclass="arabic simple">
<li><p>Any of the state space values is no longer finite</p></li>
<li><p>The z-coordinate of the torso is <strong>not</strong> in the closed interval given by <codeclass="docutils literal notranslate"><spanclass="pre">healthy_z_range</span></code> (defaults to [0.2, 1.0])</p></li>
</ol>
<p>If <codeclass="docutils literal notranslate"><spanclass="pre">terminate_when_unhealthy=True</span></code> is passed during construction (which is the default),
the episode ends when any of the following happens:</p>
<olclass="arabic simple">
<li><p>Truncation: The episode duration reaches a 1000 timesteps</p></li>
<li><p>Termination: The ant is unhealthy</p></li>
</ol>
<p>If <codeclass="docutils literal notranslate"><spanclass="pre">terminate_when_unhealthy=False</span></code> is passed, the episode is ended only when 1000 timesteps are exceeded.</p>
</section>
<sectionid="arguments">
<h2>Arguments<aclass="headerlink"href="#arguments"title="Permalink to this heading">#</a></h2>
<p>No additional arguments are currently supported in v2 and lower.</p>
<p>v3 and v4 take <codeclass="docutils literal notranslate"><spanclass="pre">gymnasium.make</span></code> kwargs such as <codeclass="docutils literal notranslate"><spanclass="pre">xml_file</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">ctrl_cost_weight</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">reset_noise_scale</span></code>, etc.</p>
<td><p>If true, issue a done signal if the z-coordinate of the torso is no longer in the <codeclass="docutils literal notranslate"><spanclass="pre">healthy_z_range</span></code></p></td>
<td><p>Whether or not to omit the x- and y-coordinates from observations. Excluding the position can serve as an inductive bias to induce position-agnostic behavior in policies</p></td>
</tr>
</tbody>
</table>
</div>
</section>
<sectionid="version-history">
<h2>Version History<aclass="headerlink"href="#version-history"title="Permalink to this heading">#</a></h2>
<ulclass="simple">
<li><p>v4: all mujoco environments now use the mujoco bindings in mujoco>=2.1.3</p></li>
<li><p>v3: support for <codeclass="docutils literal notranslate"><spanclass="pre">gymnasium.make</span></code> kwargs such as <codeclass="docutils literal notranslate"><spanclass="pre">xml_file</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">ctrl_cost_weight</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">reset_noise_scale</span></code>, etc. rgb rendering comes from tracking camera (so agent does not run away from screen)</p></li>
<li><p>v2: All continuous control environments now use mujoco_py >= 1.50</p></li>
<li><p>v1: max_time_steps raised to 1000 for robot based tasks. Added reward_threshold to environments.</p></li>