Skip to content

Don't report a fall as a time-out in inverted_pendulum - #681

Open
YannBerthelot wants to merge 1 commit into
google:mainfrom
YannBerthelot:fix/680-pendulum-time-out
Open

YannBerthelot wants to merge 1 commit into
google:mainfrom
YannBerthelot:fix/680-pendulum-time-out

Conversation

@YannBerthelot

Copy link
Copy Markdown

Fixes #680. This implements the fix proposed in the issue: inverted_pendulum now sets info['time_out'] to 0 instead of copying done. A fall ends the episode but is not a time-out, so PPO with bootstrap_on_timeout=True no longer adds gamma * V(s) to falls. The env still provides the time_out key, so the option keeps working with it.

The reproduction script from the issue, before:

fall: step 7, |angle|=0.231, done=1.0, time_out=1.0, truncation=0.0
time limit: step 3, |angle|=0.043, done=1.0, time_out=0.0, truncation=1.0

After:

fall: step 7, |angle|=0.231, done=1.0, time_out=0.0, truncation=0.0
time limit: step 3, |angle|=0.043, done=1.0, time_out=0.0, truncation=1.0

Tests run (CPU, Python 3.12, JAX 0.12.0.1):

  • New testInvertedPendulumFallIsNotTimeOut in brax/envs/env_test.py: after a fall, done is 1 and time_out is 0. It fails on main and passes with the fix.
  • In brax/training/agents/ppo/train_test.py, the tests that train on this env: testTrainWithNetworkParams (all 24 cases, 12 of them with bootstrap_on_timeout=True) and testTrainWithDistributionalCritic. All 25 pass.
  • pyink is clean on the changed lines. Both files already have other pyink diffs on main.

Not run: the rest of the suite (pytest --ignore=brax/v1). The SAC, APG, ARS and ES tests also train on this env, but they don't read time_out.

About testTrainWithNetworkParams: it only checks that training runs. With bootstrap_on_timeout=True it still runs the code path (PPO collects time_out and adds the bootstrap term), but for this env the term is now always 0, so the test no longer covers a non-zero bootstrap. It did not check the bootstrap value before either.

The issue mentions an alternative: a demo env with its own step limit, which would show the option with real time-outs. I'm happy to switch to that if you prefer.

Disclosure: AI-assisted (Claude); I reviewed and tested every change.

inverted_pendulum set info['time_out'] to done, so with
bootstrap_on_timeout=True PPO bootstrapped every fall as if the
episode had been cut short. The env has no time limit of its own, so
it now reports no time-outs.

Fixes google#680
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.

inverted_pendulum sets time_out on every fall, so bootstrap_on_timeout bootstraps terminations

1 participant