Documentation

Chapter 8. The model engine

The model engine is where a control stream becomes predictions, derivatives, likelihood contributions and simulated observations. Reproducing another pharmacometrics program requires more than accepting familiar syntax: the parser, compartment mapping, event ordering, solver, scaling and error model must agree at every record.

What you will learn

  • how nlmx normalises, parses, resolves and executes abbreviated NM-TRAN code;
  • which ADVAN/TRANS families, statements, functions and special variables are implemented;
  • how analytic, matrix-exponential, Michaelis–Menten and $DES systems advance amounts;
  • how doses, infusions, lags, bioavailability, additional doses, steady state and resets are ordered;
  • where forward-mode automatic differentiation is exact and where finite differences remain;
  • how model simulation and likelihood evaluation share the same event engine;
  • how to validate engine accuracy without overgeneralising from one fixture.

Prerequisites. Read Chapter 5 for control-stream structure, Chapter 6 for record semantics and Chapter 7 for reproducible settings and evidence.

Version scope and evidence

Behavior was checked against the model engine (NM-TRAN interpretation, PK solvers, likelihood and automatic differentiation). Executable evidence in documents/ch08 was produced with release 4.3.0 and is labelled accordingly.

pytools/ch08_examples.py fits the same one-compartment oral model as ADVAN2 and ADVAN13, compares both against the closed form at eight times, and captures an intentional unsupported-syntax failure. The maximum absolute errors were \(4.44\times10^{-16}\) for ADVAN2 and \(1.19\times10^{-11}\) for the ODE fixture.

Twenty pages in this chapter

Page Topic
8.1 From control stream to executable model
8.2 Source normalisation, lexing and names
8.3 Expressions, operators and functions
8.4 Statements, branches, loops and special variables
8.5 Unsupported constructs and diagnostic boundaries
8.6 ADVAN/TRANS support matrix
8.7 Parameter mappings, compartments and scaling
8.8 Analytic and matrix-exponential propagation
8.9 General linear models with ADVAN5/7
8.10 $DES models and solver selection
8.11 ODE tolerances, error control and stiffness
8.12 Subject timelines and record execution
8.13 Bolus, infusion, lag and bioavailability
8.14 ADDL, steady state, resets and model events
8.15 Predictions, residual error and likelihood records
8.16 Forward-mode automatic differentiation
8.17 Simulation from the compiled model
8.18 Worked analytic-versus-ODE verification
8.19 Accuracy boundaries and review checklist
From control stream to evaluable model

Continue with the compilation and execution pipeline.