Documentation

D.4 The settings system: extensions, templates, unknown keys and the echo

The life of a settings file

What you will learn

  • Explain why each command has its own settings extension, and where the table of extensions lives.
  • Describe the four artefacts that must agree for a setting to exist: the template, the reader, the resolved value and the echo.
  • Say what makes a settings file safe to change: unknown keys are errors, and a test parses the template.

Prerequisites: D.3 and Chapter 7, the settings system.

Why a file says which command it is for

Every command that reads a settings file (-c FILE) or writes one (--print-config, generate, the assistant) uses its own extension: .qcd for qc-data, .nca for nca, .er for er, and so on. The content is TOML in every case. There are sixteen registered kinds. The table lives in one place, the extensions module, as a list of (extension, what the file is, the commands that read it). The consequences are all useful:

  • a file with the wrong extension is refused with the name it should have (exit code 4), so a .vpc file handed to nca is caught at once;
  • a settings file for the covariate commands (.covar) serves several commands (cov, posterior, inspect, validate, resume, schema, fit, simulate-study), and the table records which;
  • a test checks that the extensions are distinct and are not extensions NONMEM itself uses.

Adding a command with a settings file therefore starts with one row in this table (page D.8).

The four artefacts

A setting is real only when four things agree.

Artefact What it is Where it is
The template an annotated, commented example with every key, its default and one line of explanation; what --print-config FILE writes a constant string in the command's settings module
The reader the structure that the file is parsed into; it rejects unknown keys, so a misspelled key is an error and not a silently ignored line the command's settings module
The resolved value the merge of the file, the command line and the defaults, with the command line winning the same module
The echo the resolved settings written into the run's output folder as a settings file of its own (for example vpc_settings.vpc, custom_settings.custom, power_settings_used.power), so that the run can be repeated with -c the output writer

The rule that ties them: a key that appears in one must appear in all four. The tests that enforce it differ by command, but follow one pattern.

  • A unit test parses the template and checks that it yields the defaults, so a template that is out of step with the reader fails at once.
  • A test checks that the echo parses back to the same settings (the round trip).
  • Where the template is generated (the qc-data template builds its list of 99 checks from the catalogue, with each check's default severity and its question as a comment), the template cannot lag, because there is no second copy.
  • A documentation test checks that every key and every identifier appears in the command's guide (page D.9).

Precedence and paths

The order of precedence is fixed everywhere: command line, then settings file, then built-in default. Relative paths in a settings file are resolved against the folder of the settings file, not against the folder where the command was started, so a project folder can be moved or archived. For the dataset path the order is the positional argument, then --data, then [data] file in the settings; if none is given the failure is a usage error whose hint shows all three ways.

Unknown keys are errors, and the message helps

The reader reports the file, the command and the offending key, lists the valid alternatives, and gives the hint "write the annotated reference with nlmx COMMAND --print-config". The commands that take a dataset share one routine (read_config) for this, so a change to the message is made once. A command with a bespoke reader (for example er, which has a template of its own) follows the same contract and has its own end-to-end test of the template, the plots and the errors.

A worked change

Illustration, not a feature of the program. Suppose nca should gain a setting [output] max_rows.

  1. Add the key to the template, with its default and one comment line.
  2. Add it to the reader (the section structure), as an optional value.
  3. Add it to the resolved settings, with the default, and use it.
  4. Add it to the echo, so the output folder's settings file contains it.
  5. Add a test: the template parses to the default; a settings file that sets the key changes the output; the echo round-trips; a settings file that misspells the key fails with exit code 4 and the message names the key.
  6. Add the key to the keys chapter of the book and to the command's guide, and mention it in the changelog (pages D.8 and D.14).

If you skip step 4, the run is not reproducible from its folder. If you skip step 2's strictness, a user's typo is silently ignored. Both are the kind of defect the book's validation chapters treat as a failure (Chapter 42, 42.13).

Review checklist

  • Does a new key appear in the template, the reader, the resolved value and the echo?
  • Is there a test of the template, of the echo, and of an unknown key?
  • Does a relative path resolve against the settings file's folder?
  • Is the command line still the highest precedence?

See the previous page, the next page and the developer reference.