Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Getting the same answer twice
You run a simulation and get 133.8 m of landing error. A colleague runs “the same thing” and gets 134.1. Who’s right? Maybe both: the random numbers differed, or a library updated, or the computer added numbers in a different order. Reproducibility means recording and controlling everything that affects the result (the random seed, the exact software versions, the input data and the settings) so anyone can get the same answer again, or explain why not.
Certification evidence, Monte Carlo dispersion analyses for landing ellipses, and ML results in papers must be re-creatable months later by someone else. Irreproducible pipelines waste weeks chasing “bugs” that are really changed seeds, library versions or summation order, and they undermine trust in results.
- 1. A random seed…
- 2. Pinning dependencies means…
- 3. Can the order of additions change a floating-point sum?
Level 1: Beginner
★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.Randomness done right
import numpy as np
rng = np.random.default_rng(42) # a local Generator: pass it around explicitly
x = rng.normal(0, 50, size=1000)
ss = np.random.SeedSequence(42) # parallel workers: independent child streams
rngs = [np.random.default_rng(s) for s in ss.spawn(8)]Avoid the legacy global state (np.random.seed, random.seed): any library call that draws from it silently shifts your stream. Don’t use seed + worker_id (streams can overlap or correlate). Seed every source: Python’s random, NumPy, PyTorch (torch.manual_seed, plus CUDA) and data-loader workers.
What to record for every run
Code version (git commit, clean working tree), environment (lock file, plus a fingerprint), full configuration (C2.5), random seeds, input-data version or hash, hardware/driver for GPU work, and the outputs with a run ID.
- 1. Best way to give 8 parallel workers independent random streams:
- 2. Why avoid np.random.seed?
- 3. Which is NOT needed to reproduce a run?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.Determinism vs reproducibility
- Bitwise determinism: identical bits every run on the same platform. It needs fixed seeds, single-threaded or deterministic reductions, and deterministic GPU kernels (
torch.use_deterministic_algorithms(True),CUBLAS_WORKSPACE_CONFIG), often at some cost in speed. - Statistical reproducibility: results agree within stated tolerances or confidence intervals across platforms. This is usually the realistic goal across machines, BLAS libraries and GPUs. Compare with tolerances, report variability over seeds.
Floating-point order effects
Each addition rounds to about 16 significant digits, so the order matters, especially with large dynamic range. Parallel reductions (OpenMP, MPI, GPU atomics) use whatever order the hardware produces. Remedies: pairwise summation (NumPy’s default, error growing like ), compensated summation (Kahan/Neumaier; Python’s built-in sum of floats is compensated since 3.12), exactly rounded math.fsum, or a fixed reduction tree.
- 1. Results agree to 1e-12 on one machine but differ at 1e-10 on another. Most likely cause:
- 2. math.fsum is…
- 3. For cross-platform checks, compare results…
Level 3: Advanced
★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.Error bounds for summation
Summing n numbers naively has worst-case error up to about (u = 2⁻⁵³), and the actual error depends on the order. Pairwise summation reduces this to , and compensated summation to . When greatly exceeds (cancellation, large dynamic range), these bounds are large relative to the result, which is exactly when order effects show.
Why SeedSequence beats seed + i
SeedSequence hashes the entropy (and the spawn key) through a mixing function to initialize each child’s state, so nearby integers don’t produce nearby or correlated states. PCG64 streams from different well-mixed states are practically independent.
The reproducibility stack
Data version (DVC or a hash) → code (git commit) → environment (lock file plus container) → configuration (C2.5) → seeds → outputs with a run ID derived from all of the above. If any input changes, the ID changes, which makes caching safe.
- 1. Order effects are largest when…
- 2. Pairwise summation's error grows like…
- 3. A run ID derived from config + environment + data hash lets you…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Reproducibility, measured
Exercise 1. experiment(42) returns the same (mean, 99th percentile) on every call, (50.36, 133.82) m with NumPy 2.x. Spawned worker streams are reproducible and distinct. With the global RNG, a single extra draw by “some library” shifts every subsequent number, while independent Generators don’t interfere. The environment fingerprint (Python version, platform, NumPy version) feeds a run ID that ignores dictionary key order but changes with any setting.
Exercise 2: summation order (20 000 values: 1% of size ~10⁶, the rest ~10⁻³; spread over 20 random orderings, in units in the last place of the exact sum):
| method | spread |
|---|---|
| naive left-to-right loop | 144 ulp |
| NumPy pairwise sum | 13 ulp |
| math.fsum | 0 |
| naive sum split into 1–64 “parallel” chunks | 73 ulp |
So merely changing the thread count changes the 8th significant digit of this sum. fsum is order-independent because it is exactly rounded. (Browser numbers: NumPy’s pairwise blocking differs between builds, so the pairwise spread differs slightly by platform, 11 ulp on desktop CPython.)
Reproducibility in AI, robotics and aerospace
- Monte Carlo dispersion analyses for entry, descent and landing must be reproducible for review.
- ML experiments: seeds for data order, initialization and augmentation; report mean ± spread over seeds.
- Simulation regression tests (C2.2) need tolerances that reflect order effects, not exact equality.
- Containers plus lock files plus DVC for long-lived mission analyses.
References
- N. J. Higham (1993). “The accuracy of floating point summation.” SIAM Journal on Scientific Computing, 14(4).
- D. Goldberg (1991). “What every computer scientist should know about floating-point arithmetic.” ACM Computing Surveys, 23(1).
- NumPy documentation: Random sampling: SeedSequence and parallel generation.
- PyTorch documentation: Reproducibility (torch.use_deterministic_algorithms).
- G. K. Sandve, A. Nekrutenko, J. Taylor, E. Hovig (2013). “Ten simple rules for reproducible computational research.” PLOS Computational Biology, 9(10).
- J. R. Shewchuk (1997). “Adaptive precision floating-point arithmetic and fast robust geometric predicates.” Discrete & Computational Geometry, 18 (the basis of math.fsum).