Skip to content

Commit

Permalink
Check for units error in ODE model and then solve via substitution if…
Browse files Browse the repository at this point in the history
… and error occurs (such as with older versions of numpy)
  • Loading branch information
langmm committed Oct 16, 2023
1 parent a38ebb6 commit 9e70065
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions yggdrasil/drivers/ODEModelDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,13 @@ def flambdified(*iargs):
raise RetryWithNumeric("Complex limit")
expr.append(x)
fexpr = lambdify(self.args, expr)
out = fexpr(*iargs)
out = [float(x) if isinstance(x, int) else x for x in out]
try:
out = fexpr(*iargs)
except unyts.UnitsError:
arg_map = {a: ia for a, ia in zip(self.args, iargs)}
out = [x.subs(arg_map) for x in self.expr]
out = [float(x) if isinstance(x, (int, sympy.core.numbers.Float))
else x for x in out]
out = [unyts.add_units(x, u)
if (u and not unyts.has_units(x)) else x
for x, u in zip(out, funcs_units)]
Expand Down

0 comments on commit 9e70065

Please sign in to comment.