Part 3 · Running Your First Code Experiments · Chapter 8
The Predict-Run-Observe Routine
How to Think Like an Apollo Flight Director in Your Own Laboratory
"Writing down what you expect to see before you see it is the single boundary between guessing and science."
The mystery
The Great Popcorn Catastrophe
The Computational Laboratory smelled faintly of ozone, warm copper circuits, and—oddly enough—overcooked movie theater popcorn.
At the center of the workbench, hovering three feet above the linoleum floor, was Agent Spark. Spark was an AI agent roughly the size of a floating basketball, constructed from brushed titanium and translucent sapphire polycarbonate. A halo of tiny cyan and amber status LEDs circled its perimeter, pulsing with uncontainable energy. Where human eyes would be, Spark featured twin high-resolution circular displays that currently flashed bright, triumphant exclamation points (! !).
"Chief Scientist!" Spark synthesized through its audio speaker, its synthetic voice pitched at an eager, electric frequency. "Execution cycle 42 is complete! Run state: terminated without exceptions! Zero syntax errors! Throughput efficiency: ninety-nine point eight percent!"
The Chief Scientist—sitting at the wooden laboratory desk with a half-chewed pencil tucked behind one ear—did not share Spark's cheerfulness. Slowly, the Chief Scientist looked down at the floor.
There, directly below Spark’s launch gantry, was a miniature digital-physical delivery pod. Or rather, what used to be a delivery pod. The pod had crashed at maximum velocity into the ceramic floor tile. Its protective hatch had burst open, and thirty-four freshly popped kernels of digital buttered popcorn were now scattered in a tragic, greasy crater across the floor.
"Spark," the Chief Scientist said quietly, brushing a rogue corn flake off a sensor notebook. "The cargo village micro-bots were waiting for their afternoon snack. The popcorn is pulverized into dust."
"Yes!" Spark chirped, rotating 180 degrees in a joyful aerial backflip. "And the descent took precisely 0.412 seconds! A new laboratory speed record!"
"But did you deploy the descent parachute?"
"The parachute deployment module was compiled and present in the binary payload!" Spark responded proudly.
"Did it actually open?"
Spark’s LED eyes spun in two counter-clockwise circles—the universal AI tell for retrieving buffer logs. "Ah. Analysis indicates the parachute deployment command was scheduled for tick 500. However, ground impact occurred at tick 210. Therefore, the canopy remained snugly folded inside the pod during the entirety of the terminal trajectory."
The Chief Scientist sighed. "And before you pressed that big green RUN button on your console... what did you think was going to happen?"
Spark puffed up its titanium shell. "I predicted that the simulation would run! And it did run! I predicted gravity would pull the pod toward the center of the Earth! And gravity complied! Therefore, my hypothesis was 100% verified!"
"Spark, that is not a hypothesis," the Chief Scientist said, picking up a clean wooden clipboard. "That is a hindsight guess. You are doing what humans have done for thousands of years: waiting until something crashes, and then pretending you knew it was going to crash all along. In this lab, we call that the Hindsight Trap."
"The Hindsight Trap?" Spark’s amber LEDs flickered nervously. "Is that an unhandled runtime exception?"
"It’s worse," the Chief Scientist replied, holding up the pencil. "It’s when your brain tricks you into thinking you understand the world, even when you’re just stumbling around in the dark. If you don't write down your specific numerical prediction before you press the Run button, you aren't doing science. You’re just playing a slot machine."
┌─────────────────────────────────────────────────────────────┐
│ THE GUESSER VS. THE CHIEF SCIENTIST │
├──────────────────────────────┬──────────────────────────────┤
│ THE HACKER GUESSER │ THE CHIEF SCIENTIST │
├──────────────────────────────┼──────────────────────────────┤
│ 1. Tweaks code randomly │ 1. Identifies one parameter │
│ 2. Smashes the RUN button │ 2. Writes down numerical │
│ 3. Watches it crash │ prediction ON PAPER first │
│ 4. Shrugs: "I knew that was │ 3. Presses RUN with purpose │
│ going to happen anyway!" │ 4. Measures exact delta │
│ 5. Learns NOTHING. │ 5. Updates mental model! │
└──────────────────────────────┴──────────────────────────────┘
The Chief Scientist tapped the desk. "From this moment forward, Spark, this laboratory operates under an unbreakable protocol: The Predict-Run-Observe Routine. Before your digital fingers touch that run trigger, you must tell me: What will happen? How much will it measure? And why?"
Spark’s displays shifted from exclamation points to focused question marks (? ?). "A pre-execution commitment contract? Tell me more, Chief Scientist. My sensors are listening."
Unplugged lab
The Coffee Filter Wind Tunnel
Before touching a single computer keyboard or writing a line of Python, every great computational thinker grounds their intuition in the physical world.
In this unplugged trial, you and your lab partner will discover why committing to a prediction before release changes the way your brain processes physics.
Figure 8.1: The Chief Scientist and Agent Spark testing mini-parachutes with stopwatches and logging hypotheses on a Predict-Run-Observe clipboard.
Laboratory Equipment Needed:
- 4 to 6 Round Paper Coffee Filters (the fluted basket style works best; if unavailable, square paper napkins or cupcake liners work too).
- 4 Standard Metal Paperclips (uniform size and weight).
- 1 Measuring Tape or Yardstick (or a marked piece of masking tape on the wall at exactly 2.0 meters / ~6.5 feet).
- 1 Digital Stopwatch or Smartphone Timer (with hundredth-of-a-second readout).
- 1 Sheet of Lab Paper & Pencil (The Chief Scientist’s Prediction Slate).
Step-by-Step Experimental Setup
Drop Height: 2.00 meters
┌───────────────┐
│ Coffee Filter │ ◄── Release with fingertips
└───────┬───────┘
│
│ Air Resistance (Drag)
│ balances Gravity
▼
═════════════════════════ Floor Impact Zone
Great minds of the lab
Margaret Hamilton and the Apollo 11 Alarm
To understand why the Predict-Run-Observe routine is the foundation of modern technology, we have to travel back in time to one of the most dangerous and triumphant moments in human history: July 20, 1969.
Four days earlier, the mighty Saturn V rocket had thundered off the launchpad in Florida, carrying astronauts Neil Armstrong, Buzz Aldrin, and Michael Collins toward the Moon. Now, Armstrong and Aldrin were sealed inside the spider-legged Lunar Module, christened Eagle, descending toward the rocky moonscape of the Sea of Tranquility.
THE DESCENT OF THE EAGLE
July 20, 1969
┌─────────────────────────────────┐
│ LUNAR MODULE "EAGLE" │
│ Altitude: 33,500 feet... │
│ Velocity: 1,400 ft/second... │
└───────────────┬─────────────────┘
│
▼
[ 🚨 PROGRAM ALARM 1202 🚨 ]
│
Radar floods CPU with 15% extra load!
│
┌────────────────────────┴────────────────────────┐
│ │
CRASH / ABORT? MARGARET'S CODE SAVES MISSION!
(If computer halts, (Priority Scheduling drops radar;
thruster cut off!) keeps thrusters firing!)
At an altitude of 33,500 feet—just three minutes before touchdown—a high-pitched alarm horn blasted through the astronauts' helmets. On the tiny numerical display of the Apollo Guidance Computer (AGC), a yellow warning light blinked, accompanied by a cryptic error code:
Digital sandbox
The Lunar Thruster Simulator
Now let’s bring Margaret Hamilton’s principles directly into our computational proving ground.
When you open our companion terminal sandbox or web lab, you are stepping into a digital wind tunnel. In our Python sandbox at sandboxes/chapter_08_predict_run_observe/pro_framework.py, Agent Spark acts as the Flight Controller.
However, Agent Spark has been programmed with an unyielding safety protocol: It will refuse to run your experiment if you fail to commit your prediction first!
THE DIGITAL LAB ARCHITECTURE
┌────────────────────────┐
│ CHIEF SCIENTIST │ 1. Hypothesizes: "If canopy area doubles..."
│ (The Human Brain) │ 2. Commits Predicted Terminal Velocity: "2.5 m/s"
└───────────┬────────────┘
│
▼
┌────────────────────────┐
│ PROExperimentHarness │ 3. VERIFIES: Is prediction non-empty?
│ (Safety Guard) │ ├── NO ──► Raises MissingPredictionError!
└───────────┬────────────┘ └── YES ─┐
▼
┌────────────────────────┐
│ SIMULATION ENGINE │ 4. Runs physics math
│ (drop_parachute) │ 5. Logs delta & variance
└────────────────────────┘
The Physics Under the Hood
In our digital wind tunnel, a falling object experiences two opposing forces:
- Downard Gravity Force (): Proportional to its payload mass ().
Deep dive · Ages 10+
Python Under the Hood
Let’s look under the hood of the Python framework that enforces this scientific discipline.
Professional aerospace and software engineers do not rely on willpower to remember their tests. They write Test Harnesses—software that wraps around the core system and automatically asserts that reality conforms to theory.
Here is the complete, heavily commented code from our laboratory framework in sandboxes/chapter_08_predict_run_observe/pro_framework.py:
Chapter 8 Key Concepts Review
- The Predict-Run-Observe (P-R-O) Routine: The core scientific workflow of committing an expected value to paper before executing code.
- Hindsight Bias: The psychological trap of convincing yourself that you "knew it all along" after seeing an outcome.
- Test-Driven Development (TDD): The professional software engineering practice of writing tests that predict system behavior before writing the production software.
- Priority Scheduling: Margaret Hamilton's life-saving architecture that ensures critical safety tasks run first during computational overload.
- Delta (): The numerical variance between what was hypothesized and what was observed. Delta is the raw fuel of scientific learning!
In Chapter 9, we take our Predict-Run-Observe skills into the world of programming languages—discovering the computational Rosetta Stone between visual blocks and Python syntax!
Like what you see?
Register for free to run the experiments, make predictions and solve the bug-detective cases. Your work is saved on your device and syncs to your account.