Expand description
Pendulum swing-up continuous-control environment.
PendulumSwingUp is the canonical SAC/TD3/DDPG smoke benchmark
(issue #139, part of the SAC decomposition #136). It reimplements
the classic Gym Pendulum-v1 task in-tree with no external
dependencies and closed-form physics.
A rigid pendulum hangs from a fixed pivot. The agent applies a continuous torque at the pivot and is rewarded for swinging the pendulum upright and holding it there with minimal velocity and control effort.
- Action:
Vec<f32>of length 1 (torqueu), clamped to[-2.0, 2.0]. - Observation (3-dim):
[cos θ, sin θ, θ̇]. The angle is encoded as(cos, sin)so the observation is continuous across the±πwrap. - Dynamics: standard
Pendulum-v1physics withg = 10,m = 1,l = 1,dt = 0.05; angular velocityθ̇clamped to[-8.0, 8.0]. - Reward:
-(θ_norm² + 0.1·θ̇² + 0.001·u²)whereθ_normis the angle wrapped to[-π, π]. Reward is always≤ 0and is0only at the upright rest state (θ = 0,θ̇ = 0,u = 0). - Episode length: 200 steps, then
truncated = true. The env never setsterminated.
§Determinism contract
The only source of randomness is the initial angle/velocity drawn at
Environment::reset, which is seeded (see
PendulumSwingUp::with_seed). Reset is reproducible: two envs with
the same seed produce identical episodes. The dynamics themselves are
fully deterministic (no RNG), so Environment::restore_state
followed by Environment::step reproduces every subsequent
StepResult bit-for-bit. The PendulumState snapshot captures
the simulation state (theta, theta_dot, steps) but not the
reset RNG.
Structs§
- Pendulum
State - Snapshot of
PendulumSwingUp’s simulation state. - Pendulum
Swing Up - Pendulum swing-up task with a continuous torque action.