Log inStart free
LESSON 16.22 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Wrappers and wrapper ordering

Four wrappers change what an agent sees, does and earns, and their order matters.


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

Go Pro · $8.25/mo
EXPLAINER · 16.22 · RL BAY4 WRAPPERS · REPEAT 2 · LIMIT 8
01
Stage 1 of 6 · The stack
Four wrappers sit around the track. Each one changes one channel: observation, reward, action or episode end.
Explain it simply

On the left is the agent. On the right is the track, the base environment. Each box between them is a wrapper, an environment that holds another one and changes one part of it.

The stack, outermost first: ScaleObs, ClipReward, ActionRepeat, TimeLimit, Track. The agent talks only to ScaleObs.

wrappersaction, agent reward, passed testraw rewards, observationnegative reward, failed test
Agentalways rightScaleObsobservationClipRewardrewardActionRepeatactionTimeLimitepisode endTrackbase env0start01+12+33+24−2506+17+48−39+110011+212+113−214+315016+117+218−119+1020goalthe wrapper stackprint(env) → ScaleObs(ClipReward(ActionRepeat(TimeLimit(Track))))Track: raw reward per cellAgentalways rightScaleObsobservationClipRewardrewardActionRepeatactionTimeLimitepisode endTrackbase env0start01+12+33+24−2506+17+48−39+110011+212+113−214+315016+117+218−119+1020goalthe wrapper stackprint(env) → ScaleObs(ClipReward(ActionRepeat(TimeLimit(Track))))Track: raw reward per cell
Toy: a 20-cell coin track under 4 wrappers; the policy always moves right
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
env=ScaleObs(ClipReward(ActionRepeat(TimeLimit(Track))))\text{env} = \sy{scale}{param}{\text{ScaleObs}}(\sy{clip}{param}{\text{ClipReward}}(\sy{repeat}{param}{\text{ActionRepeat}}(\sy{limit}{param}{\text{TimeLimit}}(\sy{x}{data}{\text{Track}}))))
print(env)→ScaleObs(ClipReward(ActionRepeat(TimeLimit(Track))))\text{print(env)} \to \text{ScaleObs(ClipReward(ActionRepeat(TimeLimit(Track))))}

Each wrapper calls the one inside it and changes one channel.

Common mix-ups

MYTHThe order of wrappers does not change the rewards.

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

Predict, then reveal
3 CHECKS · PRO
Q01At repeat 1, does moving ClipReward inside ActionRepeat change any reward?

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

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 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.