D.5 Outputs, logging and determinism: the three promises behind every run
What you will learn
- Describe the output set, the transcript and the checksum list, and the order in which a command writes them.
- Explain how random streams are derived, and why results do not depend on the thread count.
- State what a resumed run must guarantee, and which version number guards it.
Prerequisites: D.2, Chapter 9, the numerical core and reproducibility and Chapter 10, outputs.
Every run makes three promises to its user: it records what it did, it records what it wrote, and it gives the same numbers again. Each promise has one piece of machinery.
Promise 1: it records what it did (logging)
The logging module offers a small vocabulary used by every command: a banner of the command line, stage headers (reading the dataset, checking, writing outputs), information, success, warning and debug lines, and a final status. The console shows them according to --log-level and --quiet; the transcript in the output folder records them, regardless of what the console shows.
Two properties matter to a maintainer.
- The transcript is attached as early as the folder is known (page D.2, stage 6), so a failure in a later stage is already on disk. A failure itself is logged through the same module, in the same format.
- Stage names are part of the interface. The book quotes them, the assistant reads them, and tests look for them. Rename a stage and you rename documentation.
Promise 2: it records what it wrote (the output set)
Commands do not write files directly. They write through an output set: a small object that holds the output folder and a list of everything written through it. At the end, the set writes checksums.sha256: one hash for each file, so a reviewer can prove that a folder is the one the run produced (Chapter 10, 10.16).
This gives the standard order of the end of a command: write every output through the set; write the summary; let the set write the checksums; print the listing; then decide the exit code. Two traps follow.
- A file written around the set is missing from the checksum list. A new output must go through it.
- The checksum file is written last, so a file written after it is not covered. The output chapters of the book say which commands write the checksum file; the validation audit once found commands that were documented to write it and did not, so this is worth testing for every command.
Promise 3: it gives the same numbers (random streams)
Every random quantity comes from a stream derived from a seed and a label: a function takes the seed and the label (a string naming what the stream is for, such as a replicate or a subject) and mixes them with a constant and a derivation version into the start of a generator. The consequences:
| Property | Why it holds |
|---|---|
| The same seed gives the same results | the generator is a fixed algorithm with no hidden state |
Results do not depend on --threads |
every parallel unit (a subject, a replicate) has its own labelled stream, so the order in which threads reach it does not matter |
| Adding a new random consumer does not change old results | it uses a new label, so the other streams do not move |
| A resumed run equals an uninterrupted one | a unit's stream can be recomputed from the seed and its label, so the state of a generator need not be stored |
The derivation carries a version number. If the way streams are derived is ever changed, the number changes, and checkpoints written under the old derivation cannot be resumed, because the random streams would differ; the run stops with a checkpoint failure (exit code 11) instead of producing numbers that look right but are not the same. A maintainer who changes the derivation must change the number, and know that every stored checkpoint becomes unusable.
What goes wrong, and how to catch it
| Failure | The kind of test that catches it |
|---|---|
| A shared random stream consumed in thread order | run the same analysis with one and with several threads and compare the files (page D.12) |
| A file written outside the output set | compare the checksum list with the folder contents |
| An unstable summation order | the tolerance policy of the validation package (Chapter 42, 42.6) |
| A resumed run that differs | stop, resume and compare with an uninterrupted control, as in Case 5 (page 41.23) |
Review checklist
- Does every new output go through the output set?
- Does every new random consumer use a labelled stream, and not a shared one?
- If a change touches how streams are derived, was the derivation number changed, and was the effect on checkpoints considered?
- Does a stage keep its name?
Navigation
See the previous page, the next page and the developer reference.