cleanup_model#

pharmpy.modeling.cleanup_model(model)[source]#

Perform various cleanups of a model

This is what is currently done

  • Make model statements declarative, i.e. only one assignment per symbol

  • Inline all assignments of one symbol, e.g. X = Y

Notes

When creating NONMEM code from the cleaned model Pharmpy might need to add certain assignments to make it in line with what NONMEM requires.

Parameters:

model (Model) – Pharmpy model object

Returns:

Model – Reference to the same model

Examples

>>> from pharmpy.modeling import *
>>> model = load_example_model("pheno")
>>> model.statements
BTIME = {TIME  for AMT > 0
TAD = -BTIME + TIME
TVCL = PTVCL⋅WGT
TVV = PTVV⋅WGT
      ⎧TVV⋅(THETA₃ + 1)  for APGR < 5

TVV = ⎩       TVV           otherwise
           ETA₁
CL = TVCL⋅ℯ
         ETA₂
V = TVV⋅ℯ
S₁ = V
Bolus(AMT, admid=1) → CENTRAL
┌───────┐
│CENTRAL│──CL/V→
└───────┘
    A_CENTRAL(t)
    ────────────
F =      S₁
W = F
Y = EPS₁⋅W + F
IPRED = F
IRES = DV - IPRED
        IRES
        ────
IWRES =  W
>>> model = cleanup_model(model)
>>> model.statements
BTIME = {TIME  for AMT > 0
TAD = -BTIME + TIME
TVCL = PTVCL⋅WGT
      ⎧PTVV⋅WGT⋅(THETA₃ + 1)  for APGR < 5

TVV = ⎩      PTVV⋅WGT           otherwise
           ETA₁
CL = TVCL⋅ℯ
         ETA₂
V = TVV⋅ℯ
Bolus(AMT, admid=1) → CENTRAL
┌───────┐
│CENTRAL│──CL/V→
└───────┘
    A_CENTRAL(t)
    ────────────
F =      V
Y = EPS₁⋅F + F
IRES = DV - F
        IRES
        ────
IWRES =  F