oie-mines-paristech / lca_algebraic

Layer over brightway2 for algebraic definition of parametric models and super fast computation of LCA
BSD 2-Clause "Simplified" License
36 stars 18 forks source link

Issue with Unkown params from ecoinvent inventories #60

Closed RomainBes closed 1 week ago

RomainBes commented 1 week ago

I was working on the update of some previously working parameterized lca model, but using the ecoinvent 3.10 database and a newer version of lca_algebraic, I have some issues.

When I select an ecoinvent activity, and copy it to later modify it, I cannot compute its impacts.

act = agb.findActivity(  'uranium production, centrifuge, enriched 3.8%'  ,
    db_name=eidb.name, loc=     'DE'
) 
act2 = agb.copyActivity(activity = act,
                    code = act['name'] + ' adjusted',
                    db_name = USER_DB)
agb.compute_impacts(act2, impacts)

Exception Traceback (most recent call last) Cell In[68], line 1 ----> 1 agb.compute_impacts(act2, impacts)

File ~/conda/envs/python311/lib/python3.11/site-packages/lca_algebraic/lca.py:626, in compute_impacts(models, methods, axis, functional_unit, return_params, description, params) 623 if functional_unit != 1: 624 alpha = alpha / functional_unit --> 626 lambdas = _preMultiLCAAlgebric(model, methods, alpha=alpha, axis=axis) 628 res = _postMultiLCAAlgebric(methods, lambdas, with_params=return_params, params) 629 if return_params:

File ~/conda/envs/python311/lib/python3.11/site-packages/lca_algebraic/lca.py:368, in _preMultiLCAAlgebric(model, methods, alpha, axis) 365 exprs = _modelToExpr(model, methods, alpha=alpha, axis=axis) 367 # Lambdify (compile) expressions --> 368 return [LambdaWithParamNames(expr) for expr in exprs]

File ~/conda/envs/python311/lib/python3.11/site-packages/lca_algebraic/lca.py:368, in (.0) 365 exprs = _modelToExpr(model, methods, alpha=alpha, axis=axis) 367 # Lambdify (compile) expressions --> 368 return [LambdaWithParamNames(expr) for expr in exprs]

File ~/conda/envs/python311/lib/python3.11/site-packages/lca_algebraic/lca.py:296, in LambdaWithParamNames.init(self, exprOrDict, expanded_params, params, sobols) 294 if params is None: 295 expanded_params = _free_symbols(exprOrDict) --> 296 params = _expanded_names_to_names(expanded_params) 297 self.params = params 299 # We expand again the parameters 300 # If we expect an enum param name, we also expect the other ones : 301 # enumparam_val1 => enumparam_val1, enumparam_val2, ...

File ~/conda/envs/python311/lib/python3.11/site-packages/lca_algebraic/params.py:1209, in _expanded_names_to_names(param_names) 1207 missing = param_names - set(res.keys()) 1208 if len(missing) > 0: -> 1209 raise Exception("Unkown params : %s" % missing) 1211 return {param.name for param in res.values()}

Exception: Unkown params : {'C2H2F4'}

C2H2F4 is a flow indicated in the amount columns when printing the activity. By the way, it is a bit weird to have a mix of "parameters" and value returned by this printAct function.

agb.printAct(act2)

An idea on how to solve this problem?

raphaeljolivet commented 1 week ago

Hi Romain,

My guess is that it's linked to "chemical formulas" being imported in the "formula" properties on exchanges.

It was reported already. I provide a code to clean it : https://github.com/oie-mines-paristech/lca_algebraic/issues/44

It was also fixed in more recent version of bw2io : https://github.com/brightway-lca/brightway2-io/issues/247

RomainBes commented 1 week ago

Good guess. Thanks for the code to clean it.