Reproducible Research › Module 4: Environments

"Works on my machine"

Lesson 1 of 3 · 2 min

Previous

You send your code to a friend. It crashes. Or worse, it runs and gives different numbers. Your code didn't change; the environment did.

What the environment includes

  • The language version (Python 3.9 vs 3.12).
  • Package versions (pandas 1.5 vs 2.2 changed some default behaviours).
  • The operating system and its system libraries.
  • Hardware: CPU vs GPU, and even different GPUs, can give slightly different floating-point results.

Why results change

Packages change defaults between versions: a function's default argument, the way ties are broken, a random-number generator. Each change can shift a result a little, or a lot. Results computed on GPUs can also vary slightly between runs unless deterministic settings are turned on.

The fix, in three levels

  1. Record the versions you used (this module's next lesson).
  2. Pin them, so others install exactly the same ones.
  3. Package the whole environment in a container, for full control.

Most student projects only need levels 1 and 2.

Test on a fresh machine

The only real proof is to run your project somewhere new: a friend's laptop, a fresh cloud notebook, or GitHub Actions.

RememberYour code is only half the recipe; the environment is the other half. Record it, pin it, and test it somewhere fresh.