Evaluate and replay a policy as a complete system
Check observations, normalization, timing, and action limits alongside the checkpoint.
Run a trained policy in your browser
A PPO neural network chooses left or right from the cart position, velocity, pole angle and angular velocity. Each step runs the model weights in your browser. Compare it with random actions from the same initial state. The policy was trained beforehand; it does not learn during this replay.
Ready. The model downloads when you run the exercise.
Trained PPO policy
Return: 0 / 500
Last action: waiting
Random actions
Return: 0 / 500
Last action: waiting
Try several seeds. Every simulated step earns 1 reward, including the failure step. An episode ends when the cart crosses ±2.4 m, the pole tilts past ±12°, or it reaches the 500-step time limit. One successful episode does not establish reliability across starting conditions.
Model and training evidence
The 20 KB actor was trained with Stable Baselines3 PPO for 51,200 CartPole-v1 steps using seed 7. It scored a mean return of 500 on 20 held-out Gymnasium seeds; random actions averaged 21.4. Browser resets use a different seeded generator, so compare policies within the same browser run. The first run also downloads the WASM runtime.
Opening the Python editor…
Requirements and learning goals
Before you start
- A saved policy
- A simulator or recorded observations
You will be able to
- Version a policy contract
- Build deterministic replay checks
- Report failure distributions
The browser exercise above works without extra setup. The project brief below assumes the listed prerequisites and gives you a task and checks to perform. Need a guided first project?
A is a function that chooses an action from an observation. Its checkpoint stores learned parameters, but does not explain what each input number means. Replay feeds saved observations through that policy again. It helps you catch changed units, missing sensors, or broken action ranges before connecting a trained model to movement.
Store the checkpoint identity and observed outcome with a recorded episode, so a claimed improvement can be traced to a particular run.
Version the whole policy contract
Use the browser exercise above to replay a trained CartPole PPO policy through the backend in our yzma fork. Press Run policy comparison and record both returns. Each policy receives the same starting state. Try several seeds and count failures, then inspect the model report. The displayed inference time excludes model downloads and animation delays. Stop ends the worker; running again resets the .
In Write Python, edit the seed list and evaluation loop. await predict(observation) runs the same pretrained PPO model; reset(seed) and step(observation, action) use the same CartPole physics. Both policies start from the same observation for each seed. Python's random-action generator differs from the guided view's, so their random returns can differ even with the same seed. Add your own action rule to compare it with PPO, keeping the reset seeds and 500-step limit fixed.
A checkpoint depends on observation ordering, units, normalization, action scaling, control interval, and reset behavior. Save those alongside hashes for the model and supporting files.
Create a short observation sequence with reference outputs. Replay it in a fresh process with actuation disabled. Start with shape and value checks:
import math
def validate_step(observation, action):
if len(observation) != 4:
raise ValueError("observation shape changed")
if not all(math.isfinite(x) for x in observation):
raise ValueError("invalid observation")
if action not in (0, 1):
raise ValueError("invalid CartPole action")
validate_step([0.1, 0.0, 0.02, -0.1], 1)Adapt this to the actual action space. For continuous control, also check ranges and rate limits. Log rejected outputs rather than hiding a contract mismatch through clipping.
Replay failures
Inject duplicate samples, missing measurements, stale timestamps, and episode resets. Define whether each case requests stop, waits, or resets the policy. Recurrent models must clear hidden state between episodes.
Evaluate a fixed set of starts with success rate, completion time, interventions, and constraint violations. Keep final evaluation separate from policy selection.
The G1 training example documents a specific reference contract; its deployable observation app does not run grasp inference. Loading an app and executing a policy are separate milestones.
Common snag: filling a missing measurement with zero when zero is a valid physical value. Preserve missingness explicitly.
Optional extension: replay physical sensor timing through the simulator before changing the policy or enabling a new hardware target.
Before you move on
Can you do each of these?
- Version a policy contract
- Build deterministic replay checks
- Report failure distributions
0 of 2 checkpoints solved. Try checkpoint 1