1.3 Design principles
Five principles shaped nlmx, and almost every behaviour you will meet in the later chapters follows from one of them. They are worth knowing in advance, because several of them look like fussiness until you see the reason.
1.3.1 Everything is a text file
Inputs and outputs are plain text. The dataset is a CSV file, the model is a NONMEM control stream, the estimates
come back as the .ext, .cov, .cor, .coi and .phi files NONMEM itself writes, and every table the program
produces is a CSV file. Settings are written in TOML syntax, in files whose extension says which command they are for
(.covar, .eda, .nca, .vpc, …; Chapter 7).
What this means in practice:
- Every command can be reproduced from files. The settings a command used are written next to its results
(
fit_command.txt,normalized_config.covar,vpc_settings.vpc,power_settings_used.power, depending on the command). To repeat a run, you re-run that file. - Anything can be put under version control. The inputs are small text files; the program never asks you to save a project in a binary format of its own.
- Nothing is locked in. A table can be opened in R, Python or a spreadsheet; a control stream can be run in NONMEM.
- Settings are validated, not guessed. A settings file with a key the command does not know is refused, with the list of keys it does know. A misspelt option never silently falls back to a default:
$ nlmx vpc -c bad.vpc -o out
error FAILED during stage `startup`: VPC configuration `bad.vpc`: TOML parse error at line 7, column 1
|
7 | sampls = 500
| ^^^^^^
unknown field `sampls`, expected one of `type`, `samples`, `seed`, `idv`, `filter`, `stratify_on`, …
error exit code 4 (invalid configuration)
error hint: write the annotated reference with `nlmx vpc --print-config vpc_template.txt`
[exit 4]
1.3.2 Determinism: same seed, same results, for any number of threads
Simulation-based methods (the VPC, sims, power, the posterior engine, simulate-study) draw random numbers. nlmx
draws them from named streams: each use of randomness has a label (for example, the replicate number and the purpose),
and the numbers of a stream depend only on the master seed and that label. They do not depend on which thread happens to
run the work, or in what order.
The consequences are the ones a reviewer cares about:
- the same input, settings and
--seedgive the same output, bit for bit, whether you use--threads 1or--threads 16; - an interrupted run that is resumed gives the same result as one that was not interrupted (Chapter 25);
- a stream is tied to its label, not to the order of the work, so that dividing the work differently among threads cannot reorder the numbers.
Determinism has limits, which Section 4.3 states in full: a different program version can change an algorithm, and floating-point arithmetic on a different processor family can differ in the last digits. The promise is reproducibility on a given version and platform, and it is recorded: the version is written at the top of every log, and the seed is shown in the log and settings echo of the commands that use one.
1.3.3 No hidden state
nlmx keeps nothing between runs. There is no project database, no cache that changes results, no user profile that silently supplies defaults. Everything a run depends on is in one of three places:
- the inputs you name on the command line;
- the settings you give (a settings file and options; options win);
- the built-in defaults, which are documented and which
--print-config FILEwrites out as an annotated template.
Every run writes a checksums.sha256 file with the SHA-256 checksum of every file it produced, and the commands that
read several linked inputs (cov, for example) also write an input_manifest.json with the checksum of each input.
If a result changes, these files say whether an input changed; if the inputs are the same, a changed result points to a
change of version or of platform.
1.3.4 Sources are never rewritten, and outputs go to a fresh folder
- Your inputs are read-only to the program. The corrected control stream of
qc-nmis a copy (<stem>_qc.ctl); the original is not touched. A fit writes its final control stream into its output folder, not over the one you gave it.covwrites adraft_model.ctl, a starting point for the confirmatory run, never a replacement. - A command writes into a new folder. If the output folder already holds files, the command stops before it has written anything:
$ nlmx qc-nm models/run101.ctl -o out_qcn
error FAILED during stage `startup`: output directory `out_qcn` is not empty
error exit code 3 (file discovery or I/O failure)
error hint: pass --overwrite to write into it, or choose a fresh --output directory
[exit 3]
The rule costs a flag when you really do want to re-use a folder (--overwrite), and it buys a guarantee: a folder of
results is the results of one run, not a mixture of two. Section 4.2 describes the folder in detail.
1.3.5 Guardrails: failing loudly and refusing ambiguity
A pharmacometrics program that always produces an answer is dangerous. nlmx is built to stop, or to say so loudly, in four situations.
- Failures have stable exit codes. 0 is success; 2 to 12 each name a kind of failure (usage, file, configuration, unsupported feature, inconsistent NONMEM files, data, and so on) (Section 4.4). A script can act on the code, and the message also names the stage in which the run failed and, where possible, gives a hint for the fix.
- Ambiguity is refused, not resolved. Two control streams with the same stem in a folder, a settings file with the
wrong extension, a column that cannot be matched to
$INPUT: each stops the run and says what to choose. - Unsupported features are named. A control stream with a record nlmx does not support (such as
$MIXor$PRIOR) is rejected with the name of the record; it is never run as if the record were absent (Section 1.4). - Warnings stay visible. What is questionable but allowed is reported as a warning in the console, the log and the report (for example, an OMEGA variance that has collapsed to zero in a screening fit), and the verdict of a check says "ready with warnings" rather than "ready".
The same philosophy governs the assistant. Maxson cannot run anything itself: it can only propose commands, and nlmx decides whether a proposal is allowed, shows it to you, and runs it after your "yes" (Chapter 34).
1.3.6 What the principles ask of you
Four habits make the principles work for you.
- Give every analysis its own folder and keep the settings file with it. The program does the rest.
- Set
--seedyourself when a result will be reported, and write it down; the default seed is fixed, but a stated seed shows that you chose it. - Read the warnings. A run that ends with exit code 0 and warnings has told you what to look at.
- Treat a refusal as information. An error that names the stage and the hint is shorter to fix than a silent fallback would have been to find.