A reinforcement learning textbook that speaks both TensorFlow and PyTorch
Companion code for a book that implements every RL algorithm twice, so you don't have to translate frameworks in your head.

What it does This repository holds the complete source code for Reinforcement Learning: Theory and Python Implementation, a tutorial book by Zhiqing Xiao. Every chapter pairs mathematical derivations with runnable Python notebooks covering classic tabular methods (Bellman equations, SARSA, Q-learning) through modern deep RL (DQN variants, PPO, SAC, TD3, AlphaZero) and even newer topics like RLHF and GAIL. All code targets Gym 0.26 and runs on standard laptops across Windows, Linux, and macOS.
The interesting bit The standout feature is the deliberate dual implementation: each deep RL algorithm is written once in TensorFlow 2 and again in PyTorch 1 & 2. The author claims this is the first RL tutorial book to offer this one-to-one mapping, which saves readers from the usual mental gymnastics of translating between frameworks.
Key highlights
- Covers 16 chapters from first principles through advanced topics including IRL, PbRL, and MuZero
- Every algorithm has matching
.ipynband.htmlversions for browser viewing - Includes environments ranging from FrozenLake and CartPole to Pong, BipedalWalker, and HumanoidBullet
- Published English (2024) and Chinese (2023, 2019) editions with separate code branches
- Supplementary materials include exercise answers and errata
Caveats
- The README is sparse on actual repository structure; you’ll need to dig into language-specific branches for organization
- Some newer Gym/Gymnasium API changes may require minor adaptation since code targets Gym 0.26 specifically
Verdict Grab this if you’re learning RL and want to see clean, book-accompanying implementations side-by-side in both major frameworks. Skip it if you need a standalone library or cutting-edge research code; this is pedagogical material, not a production framework.