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:
When one calls pbm.load_existing( [presample_packages]) , all loaded presamples are copied to global_params, but are not removed from data. This is as expected.
Hence, when iterating through the pbm.data, all parameters that were loaded from existing are still in pbm.data but are missing from the result dict obtained from calculate_static, leading to KeyErrors.
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:
Original report by Pascal Lesage (Bitbucket: MPa, ).
A
ParameterizedBrightwayModel
(pbm) has two methods for recalculating parameter values, e.g. if presamples are loaded usingload_existing
.1)
pbm.calculate_stochastic()
, which calls theevaluate_monte_carlo
method of ParameterSet. 2)pbm.calculate_static()
, which calls theevaluate
method of ParameterSet.In both cases, the pbm can update amounts. The code is:
This works fine with
calculate_stochastic
, but not withcalculate_static
. The reason is this:When one calls
pbm.load_existing( [presample_packages])
, all loaded presamples are copied toglobal_params
, but are not removed fromdata
. This is as expected.The
parameter_set.calculate_static()
does not add global parameters toresult
.Hence, when iterating through the
pbm.data
, all parameters that were loaded from existing are still inpbm.data
but are missing from theresult
dict obtained fromcalculate_static
, leading to KeyErrors.There are multiple solutions, the two most evident being:
1) In
ParameterizedBrightwayModel.calculate_static()
, catch and pass global parameters on update: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:becomes
Both work, but the latter adds consistency in
ParameterSet
, hence my dropping this here rather than changing the ParameterizedBrightwayModel.