Skip to content

Lesson 7 of 9 · 23m

Project Environments, Manifests, and Reproducible Scientific Work

Use Project.toml and Manifest.toml correctly so numerical results survive machine changes, package upgrades, collaborators, and cluster deployment.

A scientific result that only runs on your laptop is not a result; it is a rumor. Julia has a strong built-in answer to reproducibility: project environments. The mistake is treating them as optional package-manager plumbing instead of part of the experiment record. Pin the environment, instantiate it exactly, and record the Julia version like you would record compiler flags.

Start every real project as a project

mkdir reaction-diffusion && cd reaction-diffusion
julia --project=. -e 'using Pkg; Pkg.add(["DifferentialEquations", "Plots"])'

This creates Project.toml, the direct dependency list, and Manifest.toml, the exact resolved dependency graph. Commit both for applications, analyses, and reproducible papers. Library packages usually commit Project.toml but not Manifest.toml because they should remain compatible across dependency ranges.

Instantiate before you debug

On a new machine:

julia --project=. -e 'using Pkg; Pkg.instantiate()'
julia --project=. run_simulation.jl

Pkg.instantiate() downloads the exact package versions recorded in the manifest. If you skip this step, you are testing dependency resolution behavior, not your code.

Compat bounds are scientific communication

Project.toml can express compatible versions such as DifferentialEquations = "7" and julia = "1.10" under [compat]. The Julia entry matters because language behavior, standard library versions, and compiler performance evolve. Semver is not magic, but accurate bounds tell future you whether an upgrade was expected to be safe.

Do not mutate the shared global environment by habit

Pkg REPL commands such as ] status and ] add Example operate on the active project. If (@v1.10) pkg> appears, you are in the shared environment for that Julia version, where experimental dependencies create cross-project contamination and confusing version conflicts. For scripts, prefer launching with julia --project=. rather than depending on an interactive Pkg.activate(".") left in memory.

Record the execution context

Numerical results depend on more than package names:

using InteractiveUtils
versioninfo()

Capture CPU architecture, thread count, BLAS configuration, input data hashes, random seeds, and solver tolerances. Julia's random number generator is reproducible when seeded, but changing package or Julia versions can still change floating-point behavior through code paths and compiler optimizations.

Create randomness with an explicit object such as rng = Xoshiro(1234) and pass it through simulations instead of relying on hidden global state. It makes parallelism and tests much easier to reason about.

Julia artifacts are versioned binary or data dependencies managed by packages. Experimental input data is your responsibility: store immutable raw data separately, checksum it, and keep generated outputs out of source control unless they are tiny regression fixtures.

Field notes

  • A manifest lockfile cannot compensate for unpinned external data or undocumented environment variables.
  • If Pkg.instantiate() modifies the manifest unexpectedly, stop and inspect; reproducibility has already drifted.
  • Use a scratch environment for throwaway plotting rather than polluting the project that produces results.
  • Set thread counts in the job script, not in a shell nobody records.
  • For long-lived publications, archive the Julia version and platform details beside the repository tag.

Was this lesson helpful?

Sign in to rate