Assignment#

class pharmpy.Assignment(symbol, expression)[source]#

Bases: Statement

Representation of variable assignment

This class represents an assignment of an expression to a variable. Multiple assignments are combined together into a Statements object.

Parameters:
  • symbol (sympy.Symbol or str) – Symbol of statement

  • expression (sympy.Expr) – Expression of assignment

Attributes Summary

expression

Expression of assignment

free_symbols

Get set of all free symbols in the assignment

rhs_symbols

Get set of all free symbols in the right hand side expression

symbol

Symbol of statement

Methods Summary

create(symbol, expression)

subs(substitutions)

Substitute expressions or symbols in assignment

Attributes Documentation

expression#

Expression of assignment

free_symbols#

Get set of all free symbols in the assignment

Note that the left hand side symbol will be in the set

Examples

>>> from pharmpy import Assignment
>>> a = Assignment.create('CL', 'POP_CL + ETA_CL')
>>> a.free_symbols      
{CL, ETA_CL, POP_CL}
rhs_symbols#

Get set of all free symbols in the right hand side expression

Examples

>>> from pharmpy import Assignment
>>> a = Assignment.create('CL', 'POP_CL + ETA_CL')
>>> a.rhs_symbols      
{ETA_CL, POP_CL}
symbol#

Symbol of statement

Methods Documentation

classmethod create(symbol, expression)[source]#
subs(substitutions)[source]#

Substitute expressions or symbols in assignment

Parameters:

substitutions (dict) – old-new pairs

Returns:

Assignment – Updated assignment object

Examples

>>> from pharmpy import Assignment
>>> a = Assignment.create('CL', 'POP_CL + ETA_CL')
>>> a
CL = ETA_CL + POP_CL
>>> b = a.subs({'ETA_CL' : 'ETA_CL * WGT'})
>>> b
CL = ETA_CL⋅WGT + POP_CL