Skip to content
VLASIFY™
TutorialResearch & computing support

Scientific code reproducibility: make every figure rerunnable

Updated · Scientifically reviewed by Priyank Srivastava, PhD on

Short answer

A result is computationally reproducible when someone else can regenerate it from your code and data. Put code under version control and tag the version used for each paper; pin the software environment (lock files or a container); record parameters, seeds and input data with each run; write one script per figure that goes from data to the final plot; archive code and data with persistent identifiers; and add automated tests that confirm key numbers do not change. Then test the package on a clean machine.

Who this is for

Researchers preparing papers, theses or reports whose results depend on simulation or analysis code, and groups meeting journal or funder code-sharing requirements.

Software

Git ≥ 2.30conda/mamba or pip currentApptainer or Docker current

Prerequisites

  • Your code in a directory you control, and a Git installation.
  • A list of the figures and tables in the paper and the runs behind each.
  • Somewhere to archive data (institutional repository, Zenodo or a facility archive).

Step 1: version control and a clear layout

git init
mkdir -p src scripts data/raw data/processed figures
git add src scripts README.md
git commit -m "Code used for the paper"
git tag -a paper-v1 -m "Version used for submitted manuscript"

Keep raw data read-only and never edit it by hand; scripts produce everything in data/processed and figures.

Step 2: pin the environment

# conda / mamba
mamba env export --from-history > environment.yml
mamba env export > environment.lock.yml
# pip
python -m pip freeze > requirements.lock.txt

For compiled codes and HPC libraries, a container definition makes the environment rebuildable:

Bootstrap: docker
From: python:3.12-slim

%files
    requirements.lock.txt /opt/requirements.lock.txt

%post
    pip install --no-cache-dir -r /opt/requirements.lock.txt

Build it with apptainer build paper.sif paper.def. See installing scientific software on Linux.

Step 3: record every run

Each run writes its parameters, code version and seed next to its output:

import json, subprocess, sys, platform

def run_metadata(params, seed):
    commit = subprocess.run(["git", "rev-parse", "HEAD"], capture_output=True, text=True).stdout.strip()
    return {"params": params, "seed": seed, "git_commit": commit,
            "python": sys.version.split()[0], "platform": platform.platform()}

meta = run_metadata({"nx": 512, "ppc": 64, "a0": 2.0}, seed=1234)
print(json.dumps(meta, indent=2))

Step 4: one command per figure

python scripts/fig3_spectrum.py data/processed/run_a0_2.h5 figures/fig3.pdf

A Makefile or snakemake workflow that rebuilds every figure from data with one command (make figures) is ideal.

Step 5: archive and cite

Add a LICENSE, a README explaining how to reproduce each figure, and a CITATION.cff file. Archive the tagged release on Zenodo (which issues a DOI) or an institutional repository, and cite the DOI in the paper’s code availability statement.

Verify

  • Clone the repository on a different machine, build the environment from the lock file or container, and regenerate the figures.
  • Compare key numbers with the paper within a stated tolerance.
  • Run the regression tests (pytest) that pin those numbers, so future changes cannot silently alter results.

Troubleshooting

  • Environment will not solve years later: keep the container image itself in the archive, not only its definition.
  • Results differ slightly between machines: document the tolerance; check thread counts and random seeds; differences far above rounding suggest a bug or uninitialised data.
  • Simulation too expensive to rerun: archive the reduced data and provide a small, cheap test case that exercises the same code path.

Assumptions and limitations

  • Reproducibility (same data, same code) is not correctness; verification and validation are separate steps, see how to validate simulation results.
  • Commands are examples for common tools; adapt to your group’s stack.
  • Journal and funder requirements differ and change; check the current policy.

Frequently asked questions

Is bitwise reproducibility necessary?+

Usually not. Parallel reductions, different compilers and GPUs change floating-point rounding. Aim for results reproducible within a stated tolerance, and check that the tolerance is far smaller than the effects you report.

How do I share very large simulation outputs?+

Archive the inputs, code, environment and the reduced data behind each figure. Keep full outputs in institutional or facility storage and describe how to obtain or regenerate them.

What licence should research code use?+

An OSI-approved open-source licence (for example MIT, BSD-3-Clause, Apache-2.0 or GPL) chosen with your institution's policies. Without a licence, others legally cannot reuse the code even if it is public.

Do journals require this?+

Many journals and funders now require code and data availability statements, and some request reproducibility packages for review. Check the specific policy of your target journal and funder.

References

  1. Wilson et al., Good enough practices in scientific computing, PLoS Comput. Biol. 13, e1005510 (2017) · Peer-reviewed article
  2. Sandve et al., Ten simple rules for reproducible computational research, PLoS Comput. Biol. 9, e1003285 (2013) · Peer-reviewed article
  3. The Turing Way: guide for reproducible research · The Turing Way community
  4. Zenodo: GitHub integration for software DOIs · Zenodo
  5. Citation File Format · CFF project

Want this set up and verified for you?

We install, configure and validate scientific software on your workstation, cluster or cloud, and train your team to run it.

Services listed on this page are available today. Products marked “early access” or “in development” on our platform page are not yet generally available.

Spotted an error or an outdated command? Tell us. We correct verified issues promptly.

Related guides

How Vlasify can help

Get a Quote