Skip to content

Fix double pendulum env - #643

Merged
jsuarez5341 merged 2 commits into
PufferAI:4.0from
zdu863:agent/fix-double-pendulum-env
Aug 20, 2026
Merged

Fix double pendulum env#643
jsuarez5341 merged 2 commits into
PufferAI:4.0from
zdu863:agent/fix-double-pendulum-env

Conversation

@zdu863

@zdu863 zdu863 commented Aug 15, 2026

Copy link
Copy Markdown
Contributor
  • c_step() wrote the terminal transition and then c_reset() cleared it before vecenv could read it.
  • Replaces the single Euler step with RK4 plus substeps, dynamics unchanged. Energy drift over a 10s episode falls from 123% to 0.0006%.
  • Updated to DeepMind-style reward. The old 0.5*height + hold-streak reward was leaning on Euler's drift as unintended dissipation.
  • Training with the default config reaches hold_time 406/600 control steps from a dead hang in ~90 seconds.
  • The old reward is removed rather than gated, so prior results aren't reproducible.

@zdu863
zdu863 marked this pull request as ready for review August 15, 2026 19:29
Physics: replace the single semi-implicit Euler step with RK4 plus configurable
substeps. Acceleration is factored out of integrate_physics into dp_accel so it
can be evaluated at RK4 trial states; the dynamics themselves are unchanged.
Measured energy drift over a 10s episode with zero force falls from 123% to
0.6355% at substeps=1 and 0.0006% at substeps=4. That matters here because a
swing-up is entirely energy bookkeeping -- an integrator that leaks energy makes
the catch easy for the wrong reason.

Reward: replace 0.5*height + hold-streak bonus with a DeepMind Control
Suite-style dense blend. The streak bookkeeping is kept because hold_time is
derived from it, which keeps that metric reward-independent.

On accurate physics the reward choice is decisive. Building on the terminal-signal
fix in this branch's parent, at 500M steps from a dead hang, hold_time out of 600:

  Euler  + streak    358   (previous behaviour)
  RK4    + streak      0   -- never catches
  RK4    + DeepMind  407

The streak reward pays 0.5100 for the first held step against 0.5000 for flying
through the top, a 2% signal that Euler's energy drift was masking by acting as
unintended dissipation. The DeepMind blend pays 4.2x at the same decision point.

Note this removes the old reward rather than keeping it behind a flag, so
existing double_pendulum results are not reproducible from here on.

The standalone demo sets substeps and balance_bonus_weight explicitly. Its
designated initializer would otherwise zero them, leaving the interactive binary
on RK4x1 with w=0 while training runs RK4x4 with w=0.5.

Also fix min_lr_ratio = 0 -> 0.0. The CLI infers each flag's type from its
config default, so the int made --train.min-lr-ratio reject float values.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@jsuarez5341
jsuarez5341 merged commit 42f70d6 into PufferAI:4.0 Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants