Skip to content

Commit

Permalink
Replace evalf by lambdify in freezeParams
Browse files Browse the repository at this point in the history
  • Loading branch information
gschwind committed Mar 1, 2024
1 parent 5007a5c commit ba79dbe
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lca_algebraic/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,13 @@ def freezeParams(db_name, **params) :
This enables parametric datasets to be used by standard, non parametric tools of Brightway2.
"""

# TODO: do proper sub-modules dependancy
from .lca import LambdaWithParamNames

db = bw.Database(db_name)

with DbContext(db) :
params_values = _completeParamValues(params, setDefaults=True)
for act in db :
for exc in act.exchanges():

Expand All @@ -858,11 +862,8 @@ def freezeParams(db_name, **params) :
# Amount is a formula ?
if isinstance(amount, Basic):

replace = [(name, value) for name, value in _completeParamValues(params, setDefaults=True).items()]
val = amount.subs(replace).evalf()

with ExceptionContext(val) :
val = float(val)
val = float(LambdaWithParamNames(amount, params=list(params_values))
.compute(**params_values))

print("Freezing %s // %s : %s => %d" % (act, exc['name'], amount, val))

Expand Down

0 comments on commit ba79dbe

Please sign in to comment.