brightway-lca / brightway2-parameters

Library for storing, validating, and calculating with parameters
BSD 3-Clause "New" or "Revised" License
1 stars 2 forks source link

Differences in ParameterSet.calculate_static() and calculate_stochastic() causes problems with PBM #4

Closed aleksandra-kim closed 5 years ago

aleksandra-kim commented 6 years ago

Original report by Pascal Lesage (Bitbucket: MPa, ).


A ParameterizedBrightwayModel (pbm) has two methods for recalculating parameter values, e.g. if presamples are loaded using load_existing .

1) pbm.calculate_stochastic(), which calls the evaluate_monte_carlo method of ParameterSet. 2) pbm.calculate_static(), which calls the evaluate method of ParameterSet.

In both cases, the pbm can update amounts. The code is:

if update_amounts:
        for key, value in self.data.items():
            value['amount'] = result[key]

This works fine with calculate_stochastic, but not with calculate_static. The reason is this:

There are multiple solutions, the two most evident being:
1) In  ParameterizedBrightwayModel.calculate_static(), catch and pass global parameters on update:

if update_amounts:
        for key, value in self.data.items():
            if key in self.global_params:
                pass
            else:
                value['amount'] = result[key]

This works, since global parameters are not updated by ParameterSet.evaluate().

2) In ParameterSet.evaluate(), add global params to results (as is done in evaluate_monte_carlo). This simply means replacing one line:

interpreter.symtable[key] = self.global_params[key]

becomes

interpreter.symtable[key] = result[key] = self.global_params[key]

Both work, but the latter adds consistency in ParameterSet, hence my dropping this here rather than changing the ParameterizedBrightwayModel.

aleksandra-kim commented 5 years ago

Original comment by Chris Mutel (Bitbucket: cmutel, GitHub: cmutel).


Return global parameter values after caalculate_static. Fixes #4

aleksandra-kim commented 5 years ago

Original comment by Chris Mutel (Bitbucket: cmutel, GitHub: cmutel).


Included in 0.6.6, available on pypi and conda.org.