A simulation answers “what if” questions that are slow, costly or impossible to answer by experiment: how long a drug stays effective, how an infection spreads through a school, how hot a plate gets. An agent can now write a working simulation in minutes. The hard part is knowing whether its answer is right, because a wrong simulation produces a plot that looks just as good as a right one.
You do not need the equations. You need a picture of the model: boxes and arrows, a shape cut into pieces, or many individuals.
Write down every number with its unit, and say what happens at the start and at the edges.
Check against answers you already know before you trust anything new.
Refine until the answer stops changing: smaller time steps, a finer mesh, more runs.
Never trust a pretty plot. A smooth curve says nothing about whether it is correct.
This is a track: a hands-on unit on one kind of data, using the skills from Parts 1 to 4. It builds on Reproducible figures (scripts, pinned versions) and Delegating well (describing the result). Parallel agents and reusable skills come in Part 5.
Three questions where an experiment is slow, costly or not allowed
A simulation is rules, numbers and a start, stepped forward many times
Most models are one of three pictures
Boxes and arrows: a drug drains from the blood like water from a tank
Boxes and arrows: an epidemic is three boxes and two rates
A shape cut into pieces: each piece moves towards its neighbours
The finite element method does the same on any shape, with triangles
Many individuals: random walkers spread out like heat
Pick the picture that matches your question
Your question is about…
Picture
Ask the agent for
A known answer to check
amounts in a few places over time
boxes and arrows
an ODE model (Python scipy, R deSolve)
half-life, conservation, R0 below 1
how something varies across a shape
shape in pieces
finite differences (1D) or FEM (scikit-fem)
straight line, textbook formula
individuals who differ, meet or choose
many individuals
an agent-based model with a fixed seed
the smooth model in the simple case
When in doubt, start with the simplest picture that could answer your question. Add detail only when the simple model is checked and found too crude.
An agent writes the code in minutes; the risk is a plausible wrong answer
Skill 1: write every number with its unit and where it came from
Keep the numbers in a parameter file, not buried in the code. The script reads the file.
Ask the agent to print the units next to every result.
A unit read wrongly gives a smooth curve and a wrong answer
“Half-life 6” without a unit is an invitation to guess. Write “half-life 6 hours” and “report time in hours”.
Skill 2: check against answers you already know, before anything new
The drug model passes when it halves every half-life
Known answer: 10 → 5 → 2.5 → 1.25 → 0.625 mg/L at 0, 6, 12, 18, 24 h.
Ask for the check as numbers in a table, not only as a plot. Lines on top of each other can hide a small difference.
The epidemic model passes three checks that need no maths
The total stays 10 000. Nobody appears or disappears.
The peak comes when a third are still susceptible (S = N/R0). A known property of this model.
With R0 below 1 there is no outbreak. The number infected only falls.
Skill 3: refine until the answer stops changing
Cell size along the rod
Largest error (°C)
Error shrinks by
10 cm
0.152
5 cm
0.038
4.0 ×
2.5 cm
0.0095
4.0 ×
1.25 cm
0.0024
4.0 ×
A simulation chops time and space into steps. Smaller steps should change the answer less and less.
Ask the agent for this table for your key number: halve the step, rerun, report the change.
If the answer is still moving, the result is not yet a result.
Never trust a pretty plot (1): too big a time step
Never trust a pretty plot (2): a beam that looks right and is 63 % wrong
Both meshes give a picture of a nicely bent beam. Only the formula and the refinement table show that one is far too stiff.
Agent-based models are noisy: compare many runs, not one
With 20 000 walkers the crowd matches the diffusion prediction. With 50, a single run can be off by a third.
Ask for a fixed random seed (so a run can be repeated) and several seeds (so you see the spread).
The prompt states the model, the numbers, the checks and the output
Build a one-compartment pharmacokinetic model in Python (scipy).
The drug is given as an IV bolus; it is removed at a rate proportional
to the amount present.
Parameters, with units, are in parameters.csv. Read them from there.
Report time in hours and concentration in mg/L.
Before anything else, add checks and print them as a table
(check, expected, got, OK):
- concentration after one half-life is half the starting value
- at 24 h it is 1/16 of the starting value
- twice the dose gives twice the concentration
- halving the solver tolerance changes the 24 h value by < 0.1 %
Then plot concentration against time and report how long the level
stays above the effective level. Ask me if anything is unclear.
Ask for a check table you can read in ten seconds
For FEM, let the agent install scikit-fem in a project environment
scikit-fem is a small Python library (needs only numpy and scipy). Ask for it in a project environment*, never system-wide.
Record the versions (requirements.txt), as in Reproducible figures.
Heavier alternatives exist: FEniCSx (more powerful, harder to install, usually via conda or Docker) or a commercial package your department licenses.
* With Rust, no project environment, conda or Docker is needed: a Rust program compiles to one self-contained file. See Translating code to Rust.
Change one thing at a time, and keep every run
What if the half-life is 4 h? 8 h? Change one parameter per run.
Ask for a small runs table: run id, what changed, key result, all checks passed?
Keep the parameter file and the script under git; commit when a run is worth keeping.
A fixed seed and recorded versions mean anyone can repeat any run.
Run the model for half-lives of 4, 6 and 8 hours, everything else as in
parameters.csv. Add one row per run to runs.csv: date, half_life_h,
hours_above_effective_level, all_checks_passed. Do not overwrite earlier rows.
A verified model can still be the wrong model
Where this goes wrong
Missing units. The agent guesses hours or minutes, metres or millimetres. Write them every time.
Wrong edges. Insulated vs fixed temperature; clamped vs free. Draw a sketch and describe each edge.
No known-answer check. “The plot looks reasonable” is not a check.
No refinement. A result that still changes when you halve the step is not a result.
One run of a random model. Report several seeds, not the luckiest one.
Parameters from nowhere. The agent may fill in a “typical” value. Ask it to list every number it did not get from you.
Checks written after the results. It is too easy to adjust the check to the answer. Write the expected values first.
Verified, but not validated. The code is right; the model is too simple for the question.
What the agent does and does not do here
The agent does well
You do
write the model code in Python or R
describe the model in words, with a sketch
set up solvers, meshes, environments
supply every number, with its unit and source
add checks, tables, plots, a runs log
supply the expected answers for the checks
explain what the code does, line by line
judge whether the model fits the question
suggest standard models and known results
look up the known results in a trusted source
Summary
Concept
Key fact
Three pictures
boxes and arrows (ODE), shape in pieces (finite differences, FEM), many individuals (agent-based)
Parameter file
every number with its unit and source, read by the script
Boundary conditions
what happens at the edges: fixed, insulated, clamped, free
totals conserved, no value beyond its limits, no negative amounts
Refinement
halve the step or the cell size; the key number must settle
Seeds
fixed seed to repeat a run; several seeds to see the spread
Pretty plot
a smooth curve says nothing about correctness
Verification vs validation
solving the model right vs choosing the right model
Next (Parallel workers: Claude and Codex): two agents at once, the same task given to both, and one agent checking the other’s work. Or continue with another track.