Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Named SymPy functions are not handled on the way into and out of TemplateModel #443

Open
liunelson opened this issue Mar 5, 2025 · 0 comments

Comments

@liunelson
Copy link

There are several places where SymPy functions could be used:

  • initial expressions
  • observable expressions
  • template/transition rate laws

MIRA throws no error when I use for example sympy.sin(t) as an expression string:

t = sympy.Symbol('t')
S, I, R, V = sympy.symbols('S I R V', cls = sympy.Function)
a, b, c, d, g, k = sympy.symbols('a b c d g k')

odes = [
    sympy.Eq(S(t).diff(t), - S(t) * (a * I(t) + b * R(t) + c * R(t) + d * V(t))),
    sympy.Eq(I(t).diff(t), S(t) * (a * I(t) + b * R(t) + c * R(t) + d * V(t)) - g * I(t)),
    sympy.Eq(R(t).diff(t), k * g * I(t)),
    sympy.Eq(V(t).diff(t), (1 - k) * g * I(t))
]

model4 = template_model_from_sympy_odes(odes)

model4.observables = {
    'Dummy': Observable(name = 'Dummy', expression = safe_parse_expr('S + I + R + V + sympy.sin(t)', local_dict = _clash))
}

However, it is interpreted as sympyXX_XXsin(t)
Image
and exported as is in the AMR.

If I were to use a SymPy function as part of the ODE:

odes[3] = sympy.Eq(V(t).diff(t), (1 - k) * g * I(t) - sympy.exp(a) * V(t))

then I get this error
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant