Assignment#

class pharmpy.model.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 (Expr) – Symbol of assignment

  • expression (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)

from_dict(d)

replace(**kwargs)

subs(substitutions)

Substitute expressions or symbols in assignment

to_dict()

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.model 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.model 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]#
classmethod from_dict(d)[source]#
replace(**kwargs)[source]#
subs(substitutions)[source]#

Substitute expressions or symbols in assignment

Parameters:

substitutions (dict) – old-new pairs

Returns:

Assignment – Updated assignment object

Examples

>>> from pharmpy.model 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
to_dict()[source]#