def test_explicit_ode_system(testdata): model = Model(testdata / 'nonmem' / 'pheno.mod') explicit_odes(model) assert 'A_OUTPUT(0) = 0' in str(model.statements.ode_system) assert model.statements.ode_system.rhs_symbols == { S('t'), S('AMT'), S('CL'), S('V') }
def test_ode_free_symbols(testdata): model = Model(testdata / 'nonmem' / 'pheno_real.mod') assert model.statements.ode_system.free_symbols == {S('V'), S('CL'), S('AMT'), S('t')} explicit_odes(model) odes = model.statements.ode_system assert odes.free_symbols == {S('V'), S('CL'), S('AMT'), S('t')}
def force_des(model, odes): """Switch to $DES if necessary""" if isinstance(odes, ExplicitODESystem): return amounts = {sympy.Function(amt.name)(symbol('t')) for amt in odes.amounts} if odes.atoms(sympy.Function) & amounts: modeling.explicit_odes(model) new = model.statements.ode_system to_des(model, new)
def force_des(model, odes): """Switch to $DES if necessary""" if isinstance(odes, ExplicitODESystem): return # Import put here to avoid circular import in Python 3.6 import pharmpy.modeling as modeling amounts = {sympy.Function(amt.name)(symbol('t')) for amt in odes.amounts} if odes.atoms(sympy.Function) & amounts: modeling.explicit_odes(model) new = model.statements.ode_system to_des(model, new)
def test_explicit_ode_system(testdata): model = Model(testdata / 'nonmem' / 'pheno.mod') explicit_odes(model) assert 'A_OUTPUT(0) = 0' in str(model.statements.ode_system) assert model.statements.ode_system.rhs_symbols == {S('t'), S('AMT'), S('CL'), S('V')} odes = ExplicitODESystem([sympy.Eq(S('x'), S('y'))], {}) assert str(odes) == '{x = y' assert odes._repr_latex_() == '\\begin{cases} \\displaystyle x = y \\end{cases}' odes = ExplicitODESystem([sympy.Eq(S('x'), S('y')), sympy.Eq(S('z'), S('y'))], {}) assert 'x = y' in str(odes) odes = ExplicitODESystem([sympy.Eq(S('x'), 1)], {}) assert odes.free_symbols == {S('x')}
def test_to_explicit_odes(pheno_path, testdata): model = Model(pheno_path) explicit_odes(model) model.update_source() lines = str(model).split('\n') assert lines[5] == '$MODEL COMPARTMENT=(CENTRAL DEFDOSE)' assert lines[16] == '$DES' assert lines[17] == 'DADT(1) = -A(1)*CL/V' model = Model(testdata / 'nonmem' / 'modeling' / 'pheno_advan1_zero_order.mod') explicit_odes(model) model.update_source() lines = str(model).split('\n') assert lines[15] == 'D1 = THETA(4)'
def test_explicit_odes(model): explicit_odes(model)