Skip to content

Commit

Permalink
Avoid symbol clashes in plot_expressions (#2440)
Browse files Browse the repository at this point in the history
Ignore sympy constants when sympifying expression strings to avoid
clashes with sympy.*.
  • Loading branch information
dweindl authored May 14, 2024
1 parent 4eb4bbd commit 0c00046
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/sdist/amici/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import amici
import numpy as np
import sympy as sp

from sympy.abc import _clash
from . import ExpData, ExpDataPtr, Model, ReturnData, ReturnDataPtr

StrOrExpr = Union[str, sp.Expr]
Expand Down Expand Up @@ -497,7 +497,7 @@ def evaluate(expr: StrOrExpr, rdata: ReturnDataView) -> np.array:
from sympy.utilities.lambdify import lambdify

if isinstance(expr, str):
expr = sp.sympify(expr)
expr = sp.sympify(expr, locals=_clash)

arg_names = list(sorted(expr.free_symbols, key=lambda x: x.name))
func = lambdify(arg_names, expr, "numpy")
Expand Down

0 comments on commit 0c00046

Please sign in to comment.