Use loop break instead of sys.exit() on early stop#123
Merged
Conversation
sys.exit() raises SystemExit which short-circuits env.close() and any outer cleanup, can't be unit-tested, and kills the kernel under Jupyter/IPython. Replace with a `solved` flag (DQN/A2C, nested loops) or a plain break (PPO, single loop) so the function returns normally and the final save runs through the same path as the EPISODES-exhausted case. Credit to @AlexisBogroff in #84 for flagging the pattern; applied to the current PyTorch tree.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sys.exit()in the three CartPole training scripts with a clean loop exit so the function returns normally instead of tearing down the process.solvedflag (nested while/for); PPO has a single outer loop so a plainbreakis enough.torch.savenow runs through one code path whether training ends from early stop or from exhaustingEPISODES.Why
sys.exit()raisesSystemExit, which:env.close()and any outer cleanupCredit to @AlexisBogroff in #84 for flagging the pattern on the original TF code; this PR applies the same idea to the current PyTorch tree.
Test plan
python 2-cartpole/1-dqn.py— confirm it stops cleanly when the 10-episode running mean crosses 490 and the saved model loads via--test2-cartpole/2-a2c.pyand2-cartpole/3-ppo.py