Advanced · Python lab

Python Laboratories for Modelers

Reproducible laboratories for simulation, numerical methods, optimization, and figure generation.

These laboratories teach Python as a way to test a mathematical argument. Code is never the starting point: each lab begins with a question, a small expected result, and a check that can fail clearly.

Standard laboratory structure

Every lab contains seven elements:

  1. Question — the mathematical or decision question in one paragraph.
  2. Model card — variables, units, equations, assumptions, and expected outputs.
  3. Starter experiment — a deterministic or fixed-seed run that all learners can reproduce.
  4. Checkpoint — a hand calculation, limiting case, conservation check, or known solution.
  5. Extension — one parameter, assumption, or algorithm is changed at a time.
  6. Evidence artefact — a labelled table or figure generated by the code.
  7. Reflection — what the computation supports, where it fails, and what data would be needed next.

Laboratory sequence

Numerical thinking

Interpolation and simple differential equations introduce discretisation, error, convergence, and the difference between a smooth-looking curve and an accurate approximation. The public interpolation guide provides a conceptual companion.

Dynamic systems

Recurrence relations and time-stepping models show how local rules generate trajectories. Learners compare time steps, inspect stability, and explain why a numerical result changes.

Simulation

Traffic or queueing cases introduce random seeds, repeated trials, distributions, and confidence intervals. One run is treated as an example; a claim requires a planned set of runs.

Spatial models

Grid-based environmental cases introduce boundary conditions, diffusion, parameter fields, and numerical refinement. Reading a Spatial Dengue Experiment Carefully demonstrates how model boundaries travel with the result.

Optimisation and trade-offs

Learners compare a baseline policy with candidate improvements, plot a trade-off surface, and test whether the preferred solution remains preferred under changed assumptions.

Scaffolding levels

  • Guided: complete missing expressions and reproduce a supplied check.
  • Structured: choose parameters and design one sensitivity test.
  • Independent: formulate the extension, justify the evaluation metric, and write the validation memo.

The same mathematical case can therefore support mixed experience without giving every learner a different intellectual task.

Reproducibility checklist

  • inputs and units are visible;
  • no local absolute path appears in code or output;
  • deterministic settings or random seeds are recorded;
  • results are saved before plotting;
  • axes, legends, and captions state what was measured;
  • one command or clearly ordered notebook regenerates the artefact;
  • a README explains expected output and known limitations.

Assessment

Code style is assessed in service of mathematical clarity. The strongest submission is not necessarily the longest program; it is the one in which a reader can connect assumptions to equations, equations to output, and output to a bounded conclusion.

Continue exploring