Log inStart free
LESSON 16.04 · 5 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Snapshots, cloning and replay

Save an environment's state, restore a clone, and replay the same actions.


Pro lesson. Stage 1 is free to watch. Pro opens all 5 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 16.04 · REPLAY BAYRUN A · GOAL AT STEP 9 · REWARD 1.6
01
Stage 1 of 5 · Run A
Run A moves right and reaches the goal at step 9. Each step draws an RNG number; below 0.25, it slips.
Explain it simply

The top grid is run A. Each column is one step, and the dot shows the agent's cell. Each step reads the state, draws one random number and writes a new state. The step depends only on the state and the action, so it can be replayed.

Run A: cells 0, 0, 1, 2, 3, 4, 5, 5, 6. It reaches the goal at step 9 with a total reward of 1.6. The table shows its state after step 2.

run A and its statesnapshotclone Bmismatches, hidden stateslip or blocked step
run Astart 01key 234door 5goal 6012345678910rewardgoal000.10.10.10.10.101.1fieldrun A, step 2t2pos0inv[]doorfalseunlocks0visited[0]rng3663131633outside the statenothing: every piece is in the staterun Astart 01key 234door 5goal 6012345678910rewardgoal000.10.10.10.10.101.1fieldrun A, step 2t2pos0inv[]doorfalseunlocks0visited[0]rng3663131633outside the statenothing: every piece is in the state
Toy: a 7-cell corridor, seed 7, 10-step budget
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
st+1, rt=f(st,at)\sy{s}{data}{s_{t+1}},\ \sy{r}{data}{r_t} = f(\sy{s}{data}{s_t}, \sy{a}{data}{a_t})
s9, r9=f(s8,right)=(cell 6, 1.1)s_{9},\ r_{9} = f(s_{8}, \text{right}) = (\text{cell } 6,\ 1.1)

The next state and the reward depend on the state and the action only.

Common mix-ups

MYTHSaving the agent's cell and items saves the environment.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01With the visit cache outside the state and a serialized snapshot, does clone B take another path?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 5
Unlock the full explainer
  • 4 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.