Skip to content

Pendulum-v1

Pendulum

Pendulum()

Bases: Environment[EnvState, EnvParams]

Swing a pendulum upright and keep it there by applying torque.

JAX port of the Gymnasium Pendulum-v1 environment. The angle starts at a uniformly random value in [-pi, pi] and the angular velocity in [-1, 1]. Supports differentiable transitions via with_transition_gradients().

  • Observation: Box of shape (3,) with the cosine and sine of the angle and the angular velocity.
  • Actions: Box of shape (1,) with the torque on the pendulum, bounded by params.max_torque (2 by default) in either direction. Actions outside the bounds are clipped.
  • Reward: -(theta**2 + 0.1 * theta_dot**2 + 0.001 * u**2), using the angle (normalized to [-pi, pi)) and angular velocity before the step and the clipped torque u.
  • Termination: never.
  • Truncation: after params.max_steps_in_episode steps (200 by default).
References

Parameters and state

EnvParams

Bases: EnvParams

Parameters of the Pendulum environment.

Attributes:

  • max_speed (float) –

    Maximum absolute angular velocity of the pendulum.

  • max_torque (float) –

    Maximum absolute torque; actions are clipped to it.

  • dt (float) –

    Duration of one step, used for Euler integration.

  • g (float) –

    Gravitational acceleration.

  • m (float) –

    Mass of the pendulum.

  • l (float) –

    Length of the pendulum.

  • max_steps_in_episode (int) –

    Number of steps after which the episode is truncated.

EnvState

Bases: EnvState

State of the Pendulum environment.

Attributes:

  • theta (Array) –

    Angle of the pendulum in radians, 0 being upright. Not wrapped.

  • theta_dot (Array) –

    Angular velocity of the pendulum, clipped to [-params.max_speed, params.max_speed].

  • last_u (Array) –

    Torque applied in the last step, after clipping. Only needed for rendering.

  • time (int) –

    Number of steps taken in the current episode.