Restart, resume, and the output-dir lifecycle¶
A jaxrens run writes a fixed set of artifacts into one
output.working_dir: *.energies, *.traj.*, *.adaptation.h5,
*.checkpoint.h5, and friends. Two distinct concerns live on top of
that directory:
Avoiding accidental clobber — re-running the same config against the same output dir should never silently destroy or corrupt the prior run’s data.
Resuming a prior run — from a crash, from a clean completion, or to retune the MCMC, sometimes a new invocation legitimately needs to continue an earlier output dir.
These are opposite ends of the same lifecycle, so jaxrens treats them with a single decision: is this a restart, or is it fresh?
restart_intent = (init.restart_file is set in YAML)
OR (--resume passed on the CLI)
The predicate is computed once in _cmd_run before any I/O, and it
drives the rest of the lifecycle: whether the output-dir gate fires,
which mode the writers open in, and whether the compatibility validator
runs.
Three start modes¶
Mode |
Trigger |
Gate |
Writer mode |
Walker state from |
|---|---|---|---|---|
Fresh |
nothing set |
enforce clean dir |
|
|
Fresh + force |
|
wipe artifacts |
|
|
Explicit restart |
|
skip |
|
the checkpoint at |
Auto restart |
|
skip |
|
auto-discovered checkpoint in |
--force is fresh-only. The combinations --force + --resume,
--force + init.restart_file, and --resume + init.restart_file are
mutually exclusive and rejected at argparse with SystemExit(2).
The output-dir gate¶
For fresh runs only. Scans working_dir for any of these patterns:
{prefix}.energies {prefix}.run*.energies
{prefix}.traj.* {prefix}.run*.traj.*
{prefix}.adaptation.h5 {prefix}.re_stats.h5
{prefix}.max_neighbors.h5 {prefix}.acc_rates.h5
{prefix}.checkpoint.h5 {prefix}.initial.checkpoint.h5
{prefix}.final.checkpoint.h5 {prefix}.config.snapshot.yaml
If any match exists, the run aborts with a message listing the first
ten offending files. Pass --force to delete them and proceed.
Code: jaxrens.cli.output_gate, enforce_clean_output_dir.
The glob set is the catalogue of every file a run writes into
working_dir. Log files ({prefix}.log, {prefix}.debug.log) live in
the parent directory and are out of scope of the gate — they follow
the same mode="w" / mode="a" rule as the writers (see below),
so on --resume the prior run’s log is preserved and the new segment
is appended to it. Per-walker snapshot files
({prefix}.traj.snap.NNNN.extxyz) are included via the .traj.* glob
— without that, --force would leave stale snapshots from a longer
prior run silently mixing iteration ranges into a re-run.
Auto-discovery (--resume)¶
When --resume is passed, jaxrens scans working_dir for a checkpoint
matching the configured prefix. The rule:
Look for
{prefix}.final.checkpoint.h5and{prefix}.checkpoint.h5.If neither exists → abort with a listing of expected names.
If exactly one exists → use it.
If both exist → use whichever has the higher mtime.
On exact mtime tie →
.final.checkpoint.h5wins (a clean termination beats the last rolling write that produced it).
The chosen path is logged so the audit trail records which file drove the restart:
[--resume] selected ns.final.checkpoint.h5 (mtime=…); also found
ns.checkpoint.h5 (mtime=…)
{prefix}.initial.checkpoint.h5 is not a discovery candidate —
it’s written once at run start, before any iterations have run, and
restarting from it would just redo the work.
Code: discover_checkpoint in jaxrens.cli.output_gate.
The config snapshot¶
Every fresh run writes {prefix}.config.snapshot.yaml into
working_dir immediately after the gate clears. The payload is exactly
root.model_dump(mode="json") — the same validated config that goes
into the run log, but in a structured file the restart validator can
read back.
When a later invocation restarts (either via --resume or via
init.restart_file: <path>), the snapshot located beside the
checkpoint is the source of truth for “what physics did the original
run use?”. Without it, the validator can only do the shape checks the
resolver does anyway.
output/
├── ns.config.snapshot.yaml ← written on fresh start
├── ns.checkpoint.h5 ← rolling, updated mid-run
├── ns.final.checkpoint.h5 ← written on clean termination
├── ns.energies
└── ns.traj.extxyz
If you restart from a checkpoint produced by a pre-2026-05-18 jaxrens (no snapshot beside it), the validator logs a warning and proceeds with shape checks only.
The compatibility validator (strict)¶
When restart_intent is true, after the resolver has built the
runtime config but before any callback wiring,
validate_restart_compatibility diffs the snapshot against the current
run’s config. Each field falls into one of three categories.
Hard refuse — immutable across restart¶
A mismatch on any of these is a SystemExit(2) with a per-field diff:
Field |
Why it must match |
|---|---|
|
walker-population shape; NS estimator depends on constant |
|
|
replica count ( |
sets |
|
energy function identity — including model file paths for ML backends |
|
pressure, temperature, volume limits — physical meaning of the trace |
|
replica-exchange flavor + per-replica conditions (pressures, μ) |
|
PBC flags, ndim — periodic-volume vs free-space |
The refusal message looks like:
jaxrens run: restart from output/ns.final.checkpoint.h5 is incompatible
with the current config on immutable fields:
run.n_live snapshot=64 current=128
ensemble snapshot={'type': 'npt', 'pressure': 0.001} current={'type': 'npt', 'pressure': 0.005}
backend snapshot={'type': 'lj', ...} current={'type': 'neuralil', ...}
snapshot: output/ns.config.snapshot.yaml
Use a different working_dir for this configuration, or revert the
conflicting fields.
Aborting.
No override flag. If you genuinely want to start from these positions under different physics, point at a new output dir — the checkpoint can be read from anywhere, the gate only protects the write side.
Soft warn — mutable but worth flagging¶
A change here logs a warning and proceeds:
moves— added/removed kernels, retuned step sizes/weights, different target acceptance.run.n_mcmc_steps,run.max_iterationstermination,adaptationsubtreesoutput.traj_interval,output.snapshot_interval,output.checkpoint_interval,output.info_interval,output.formatinterval_units
Unchanged-seed warning¶
run.seed is normally mutable, but a restart that keeps the seed
identical produces a continuation using the same PRNG stream from this
point — statistically useless as a second ensemble member. The
validator emits a single warning when this happens:
[restart] run.seed (1) is unchanged from the original run.
Bump the seed if you intend the restart as an independent ensemble member.
Code: jaxrens.cli.restart_validate.
Writer behavior across restart¶
All seven I/O writers honor a mode: Literal["w", "a"] constructor
parameter set once per run by the dispatcher. The log handlers
({prefix}.log, {prefix}.debug.log) honor the same mode so the
diagnostic trail spans the boundary too.
Writer |
|
|
|---|---|---|
|
truncate, write header |
open in append mode, header skipped if file non-empty |
|
overwrite on first frame, then append |
append from the first frame |
|
|
|
|
first flush truncates, subsequent flushes append |
every flush appends |
|
same |
same |
|
same |
same |
|
same |
same |
|
truncate |
append |
On a restart, each file ends up containing the prior run’s 0..Ncheckpoint rows followed by the new segment’s Ncheckpoint..Nfinal rows — one continuous trace per file, indistinguishable from a single long run aside from the iteration index at the boundary.
What you cannot do across restart¶
The strict policy refuses these by design:
Resize the walker population —
n_live,n_gpu,n_per_gpuimmutable. The NS evidence estimator assumes constantn_liveacross iterations; changing it silently invalidateslog_Z.Change the replica count —
len(ensemble.pressure)/len(inter_re.composition_targets)/len(inter_re.chemical_potentials)determinen_total; a change re-shapes the checkpoint’s batch axis. The validator names this case explicitly before the broader ensemble/inter_re diff fires.Swap the energy function —
backendimmutable. The energy scale shifts, the contour history becomes meaningless, the appended trace is garbage.Change physical conditions —
pressure,chemical_potentials,temperatureimmutable. A trace spanning two conditions cannot be post-processed as one run; per-segment analysis is what you actually want, and that means separate output dirs.Change the cell topology — PBC flags / ndim immutable. NPT volume moves are meaningless on a non-PBC checkpoint and vice versa.
For all of these the workaround is the same: set
output.working_dir to a new path and load the checkpoint via
init.restart_file. The new dir is empty so the gate passes, the
new run produces fresh files, and the original artifacts are
preserved.
Multi-replica restart¶
A multi-replica YAML — one that implies n_total > 1 via a
list-valued ensemble.pressure, inter_re.composition_targets, or
inter_re.chemical_potentials — restarts the same way as single-run:
either --resume (auto-discovers the checkpoint in working_dir) or
init.restart_file: <path> in the YAML.
The resolver loads the checkpoint exactly once and slices it per replica. The data layer handles both checkpoint shapes:
1-D
(n_runs,)(saved byrun_ns_parallelon a single-GPU host) → loaded asn_gpu=1, n_per_gpu=n_runs.2-D
(G, P)(saved byrun_ns_multi_gpu) → loaded asn_gpu=G, n_per_gpu=P. Cross-topology restart (saved G ≠ current host’s GPU count) is refused unless the saved checkpoint hadn_gpu=1, in which case the replicas are re-tiled across the current host’s GPUs.
Constraints specific to multi-replica restart:
The implied
n_totalfrom the current YAML must match the checkpoint’sn_total. The validator catches this before the resolver does (with a targeted “replica count changed” message).Per-replica conditions (entries of
ensemble.pressurelist, etc.) are still immutable across restart — they live under theensemble/inter_resubtrees and any value change fails the broader diff. The workaround stays the same: branch to a newworking_dir.Burn-in is skipped on restart for the multi-replica path, same as for single-run — the checkpoint already holds NS-loop walkers, well past the burn-in level.
Common scenarios¶
Crash recovery¶
# config.yaml — unchanged from the original run
init:
start_species: "18 64"
output:
working_dir: ./output
out_file_prefix: ns
jaxrens run -c config.yaml --resume
The checkpoint is auto-discovered. Validator passes (config identical), emits one warning about the unchanged seed. Writers append.
Extending a completed run¶
The previous run terminated cleanly on iteration: 10000. You want
20000.
run:
seed: 7 # bump from the original to suppress the seed warning
termination:
- type: iteration
max_iterations: 20000
jaxrens run -c config.yaml --resume
Picks ns.final.checkpoint.h5. Validator warns
termination.max_iterations changed, proceeds. The next 10000
iterations append into the same files.
Retuning MCMC mid-run¶
Acceptance was bad; tighten step sizes, drop a problematic kernel.
moves:
- type: random_walk
step_size: 0.05
weight: 1.0
# gmc removed
jaxrens run -c config.yaml --resume
Validator warns moves changed, proceeds. New segment uses the
retuned MCMC; the adaptation log gains a new row when adaptation fires.
Branching to a new output dir¶
Take a checkpoint, fork three independent continuations.
# branch_seed_42.yaml
run:
seed: 42
output:
working_dir: ./output_branch_42
out_file_prefix: ns
init:
restart_file: ./output/ns.final.checkpoint.h5
jaxrens run -c branch_seed_42.yaml
The new working_dir is empty so the gate passes; init.restart_file
triggers the restart branch (validator runs on the snapshot beside the
original checkpoint). Writers truncate output_branch_42/*; the
checkpoint is read from the original dir, not touched.
Fresh re-run, accepting that the previous output is gone¶
jaxrens run -c config.yaml --force
The gate finds the old artifacts and deletes them; writers truncate;
the run starts from init.start_* as if the previous dir never
existed.
Code map¶
Concern |
File |
Symbol |
|---|---|---|
Output-dir gate, artifact globs |
|
|
|
|
|
Config snapshot read/write |
|
|
Strict compatibility validator |
|
|
Mode plumbing into the run |
|
|
Walker-state loader for Mode D |
|
|
Resolver branch for restart |
|