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

  • Remove all random variables with no variability (i.e. with omegas fixed to zero)

  • Put fixed thetas directly in the model statements

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 – Updated model

Examples

>>> from pharmpy.modeling import *
>>> model = load_example_model("pheno")
>>> model.statements
TVCL = POP_CL⋅WGT
TVV = POP_VC⋅WGT
      ⎧TVV⋅(COVAPGR + 1)  for APGR < 5

TVV = ⎩       TVV          otherwise
           ETA_CL
CL = TVCL⋅ℯ
          ETA_VC
VC = TVV⋅ℯ
V = VC
S₁ = VC
Bolus(AMT, admid=1) → CENTRAL
┌───────┐
│CENTRAL│──CL/V→
└───────┘
    A_CENTRAL(t)
    ────────────
F =      S₁
Y = EPS₁⋅F + F
>>> model = cleanup_model(model)
>>> model.statements
TVCL = POP_CL⋅WGT
      ⎧POP_VC⋅WGT⋅(COVAPGR + 1)  for APGR < 5

TVV = ⎩       POP_VC⋅WGT          otherwise
           ETA_CL
CL = TVCL⋅ℯ
          ETA_VC
VC = TVV⋅ℯ
V = VC
Bolus(AMT, admid=1) → CENTRAL
┌───────┐
│CENTRAL│──CL/V→
└───────┘
    A_CENTRAL(t)
    ────────────
F =      VC
Y = EPS₁⋅F + F