Unit 10 of 11 · about 3 hours · implement
Synchronous and asynchronous sweeps, ties, unreachable states and terminal conventions
Two correct implementations can differ for sweeps before they agree. Unstable ties and terminal leaks explain most planning mismatches.
You'll be able to
- Implement synchronous two-array and asynchronous in-place sweeps and state order dependence.
- Break ties with a stable rule and keep all maximum actions where the task needs the full optimal set.
- Enforce terminal conventions with and reward on entry, and keep unreachable states out of stopping.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Asynchronous DP, ties and unreachable statesReinforcement Learning: An Introduction (2nd ed.) - Chapters 3 and 4
Chapter 4, Section 4.5 Asynchronous Dynamic Programming, printed pp. 85 to 86; Figure 4.1 bottom-right with multiple arrows for ties, printed p. 77; Exercise 4.2 on added state 15, printed p. 76, and Exercise 4.4 on tie switching, printed p. 82. The authors post the full text free at incompleteideas.net.
- Synchronous code and terminal entryHands-on Modern RL - MDPs, Values and Bellman Equations
How Far One Sweep Can Propagate Information with
valuesversusupdatedcode, and Terminal Rewards Are Computed Upon Entry withtransitionreturning 0 after terminal (page read 2026-10-14) - Terminal bootstrap ruleGymnasium - Time Limits and Episode Semantics
Solution with
vf_target = rew + gamma * (1 - terminated) * vf_next_state; terminal cuts the bootstrap (page read 2026-10-14)Use only the terminal line here. Truncation was covered in the horizons unit.
Focus on
- Synchronous reads for all successors. In-place reads the latest values, so order changes the path but not the fixed point when every state keeps getting updated.
- Ties admit any split among maximum actions. Switching among equally good policies each sweep looks like non-convergence. Fix the rule and log the full set where needed.
- Terminals have no successor value. Unreachable states keep their initialization until swept. Exclude them from stopping or prove they are swept.
Common mistakes · 3
- Comparing one synchronous sweep to many in-place updates. Compare fixed points and residuals, not sweep counts.
- Storing a terminal bootstrap. The transition into the goal already carries the reward. The terminal state contributes 0 after.
- Letting an unreachable state set the maximum difference. Mask to reachable states or sweep all states.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.What is the difference between synchronous and in-place updates in (4.5)?Answer
Synchronous computes the whole new table from the old table. In-place reuses new values for states already updated in this sweep.
2.What does Figure 4.1 show with multiple arrows?Answer
Several actions tie for maximum in (4.9). Any split among them is greedy. The implementation must pick a stable rule.
3.What is Exercise 4.2 testing with state 15?Answer
Whether added states are reachable and how their values follow from outgoing transitions. Unreachable states do not affect others until the dynamics link them.
4.What value follows a terminal transition?Answer
Reward on entry plus 0 after. Never add as if the terminal had future return.
Practice
- Sutton and Barto Exercises 4.2 and 4.4: unreachable states and tie stability
Exercise 4.2 on state 15, printed p. 76, and Exercise 4.4 on fixing tie switching, printed p. 82. The authors post the full text free at incompleteideas.net.
Code both sweep orders. Show first-max stabilizes while naive switching can oscillate. The section mini-project covers seeded tie and terminal defects.
You're done when
Your synchronous sweeps match Figure 4.1 through , your in-place run reaches the same fixed point, ties are stable, and terminals contribute 0 after entry.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 4 more in the section
- Reinforcement Learning: An Introduction (2nd ed.) - Chapters 3 and 4Richard Sutton and Andrew Barto · required
The authors post the full second edition free at incompleteideas.net; cite the printed page numbers. Study Chapter 3 (Sections 3.1 to 3.7, finite MDPs, returns, Bellman equations and optimality) and Chapter 4 (Sections 4.1 to 4.7, policy evaluation, improvement, policy and value iteration, asynchronous DP and GPI). Reproduce Example 4.1 and Figure 4.1 exactly, then Example 4.3 (the gambler), and write exact tests for stochastic transitions, terminals, ties and stopping error.
- Gymnasium - Time Limits and Episode SemanticsFarama Foundation · required
Read the termination, truncation and "importance in learning code" sections, then the vector autoreset note at https://farama.org/Vector-Autoreset-Mode (next-step autoreset is the default in Gymnasium 1.x). Build a wrapper test that distinguishes termination from truncation and proves which cases bootstrap before using any third-party environment.
- Hands-on Modern RL - MDPs, Values and Bellman EquationsWalking Labs · support
Use the value and Bellman page and the value experiment page (
code/chapter03_mdp/bellman_equation_verify.pyandgridworld_q_learning.pyrun on CPU in seconds) as a code companion. Check every equation against Sutton and Barto before adopting it. Pin commit 9231bab of walkinglabs/hands-on-modern-rl; itscode/chapterNNfolders do not follow the site chapter numbers.
Also in this section
- Stanford CS234 Winter 2026 - Foundations and PlanningStanford University · primary
Study Lecture 1 (
lecture1pre.pdfandlecture1post.pdf) and Lecture 2 on tabular MDP planning (lecture2pre.pdfandlecture2post.pdfunder https://web.stanford.edu/class/cs234/slides/). Work Assignment 1 independently: the written MDP, horizon and Bellman-operator questions and thevi_and_pi.pyplanning code on RiverSwim (NumPy only). Do not copy or publish course solutions. - Deep-ML - Planning ProblemsDeep-ML · support
Use named problems as closed-book checks after your own implementation passes: 157 (Bellman equation for value iteration), 164 (the gambler's problem by value iteration) and 467 (policy iteration). Read each problem's tests before trusting its statement.
- Reinforcement Learning Control Laboratory - Planning CoreRoadmap-Final · required
Complete Milestone A planning requirements: an explicit finite MDP, exact policy evaluation, value iteration, policy iteration, simulator agreement and seeded reward, transition, terminal and tie defects.
- Reinforcement Learning: An Introduction (2nd ed.) - Chapter 2 banditsRichard Sutton and Andrew Barto · reference
Read Section 2.9, Associative Search (Contextual Bandits), printed p. 41, with Exercise 2.10 as the context versus no-context check. Use only this section from Chapter 2.