Monte Carlo LCA on activities that have parameters with uncertainty from a SimaPro project returns constant value (no uncertainty) - brightway

I've imported a project from SimaPro in which almost every activity uses parameters that have uncertainty. When I run a Monte Carlo LCA on any of these in Brightway, the results are constant, as though the quantities have no uncertainty (the snippet shows 10 steps, but it's the same for 2000 steps).
sp = bw.SimaProCSVImporter(fp, name="All Param")
sp.apply_strategies()
sp.statistics() # returns 0 unlinked
sp.write_database(activate_parameters=True)
spdb = bw.Database("All Param")
imported_material = [act for act in spdb if 'Imported' in act['name']][0]
mciter=10
mc_imported = bw.MonteCarloLCA({imported_material:1},('IPCC 2013', 'climate change', 'GWP 100a'))
scores = [next(mc_imported) for _ in range(mciter)]
scores
[0.015027544172490276,
0.015027544172490276,
...
0.015027544172490276,
0.015027544172490276]
I'm at a loss, as everything loads without errors, and looking at the activities and exchanges show the expected formulas, parameters and uncertainties on parameters.
I suspect that the issue might be related to the distinction between active and passive parameters described in the documentation, but do not see how to make the designation that these parameters are (all) "active" beyond xxx.write_database(activate_parameters=True) as in the parameterized dataset example notebook. I also don't see how to list which parameters are active or passive, so the issue might be something else completely.
What do I need to do to get my parameterized activities to incorporate the uncertainty from the parameters in the MC LCA? Any help would be most appreciated!
For what it's worth, they do work in the SimaPro project whence they come - the uncertainty analysis uses the uncertainty on the parameters - so I don't think the issue is in the originating project.
Thank you for any guidance you can provide!

Parameterized inventories generally don't work in Monte Carlo, as the Monte Carlo class is focused on data point uncertainties described by PDFs. There is a separate project called presamples which allows for the use of parameterized inventories in Monte Carlo through some pre-calculations - however, it doesn't have great documentation yet. Look in the docs, and ParameterizedBrightwayModel.
Note: Check your parameter names and formulas from SimaPro, Brightway is stricter in what it allows (e.g. python is case sensitive and has more reserved words).

Related

How to deal with end of life scenarios on Brightway?

I am currently working on a project about life cycle models for vehicles on Brightway. The models I am using are inspired from models on the software Simapro. All the life cycle processes are created fine except for the end of life scenarios. On Simapro the end of life scenarios are described with percentages of recycled mass for each type of product (plastics, aluminium, glass, etc) but I can't find how to translate this into Brightway. Do you have ideas on how to deal with these end of life scenarios on Brightway ? Thank you for your answer.
Example of the definition of an end of life scenario on Simapro
There are many different ways to model End-of-Life, depending on what kind of abstraction you choose to map to the matrix math at the heart of Brightway. There is always some impedence between our intuitive understanding of physical systems, and the computational models we work with. Brightway doesn't have any built-in functionality to calculate fractions of material inputs, but you can do this manually by adding an appropriate EoL activity for each input to your vehicle. This can be in the vehicle activity itself, or as a separate activity. You could also write functions that would add these activities automatically, though my guess is that manual addition makes more sense, as you can check the reasonableness of the linked EoL activities more easily.
One thing to be aware of is that, depending on the background database you are using, the sign of the EoL activity might not be what you expect. Again, what we think of is not necessarily what fits into the model. For example, aluminium going to a recycling center is a physical output of an activity, and all outputs have positive signs (inputs have negative signs in the matrix, but Brightway sets this sign by the type of the exchange). However, ecoinvent models EoL treatment activities as negative inputs (which is identical to positive outputs, the negatives cancel). I would build a simple system to make sure you are getting results you expect before working on more complex systems.

Negative production for end of life treatment process

I am currently working with the ecoinvent 3.6 database in Brightway and I have a question about the end of life treatment processes. I found out that some of these treatment processes have a negative production amount and give negative results when tested. For the same processes opened in Simapro, the production amount is positive and the LCA score is also positive. Screenshot of an activity details in Brightway
Screenshot of the result for this activity in Brightway
Screenshot of the activity details in Simapro
Screenshot of the result for this activity in Simapro
Is there an explanation for this ? And is it possible to know which processes are concerned ? Than you very much for your answer.
it is a thorny sign convention issue. One needs to be aware of these conventions because different LCA softwares and databases can have different conventions.
if you look into the same dataset in ecoinvent website you'll see that the reference product is -1 waste polypropylene. What that means is that it treats 1 kg of polypropylene.
Following the same convention the production flow of that activity on brightway is -1 (unlike normal "production" activities that have a positive production). To be consistent, the use of waste treatment services has also a negative amount (if you look into technosphere exchanges you'll see waste with - sign).
I think simapro treats them differently, and flips the sign of waste treatment activities, that is why you see it positive. It then flips the sign at some point in the calculation.
A good explanation is probably buried in the LCA mailing list somewhere, but I could not find it.

Brightway2 - Get LCA scores of immediate exchanges

I'm having some problems regarding the post-processing analysis of my LCA results from brightway2. After running a LCA calculation, if, for example, I type top_activities() I get a list of a bunch of activities and their associated scores, however none of the activities/scores are the ones associated directly with my functional unit (they appear to be some exchanges of my exchanges...).
How can I get the LCA scores of the exchanges (both technosphere and biosphere) I defined when constructing my Functional Unit?
Thanks!
I've found the best way to get aggregated results for your foreground model in brightway is using the bw2analyzer.traverse_tagged_databases() function rather than top_activities(). Details in the docs are here.
It's designed to calculate upstream impacts of the elements of your foreground model and then aggregate the impacts based on a tag it finds in the activity. e.g. if you add 'tag':'use phase' or 'tag':'processing' to your activities you can aggregate impact results by life cycle stage.
BUT you can change the default label it looks for, so instead of tag you can tell it to look for name - that'll give you the aggregated upstream impact of each of the activities in your foreground model. It returns a dictionary with the names of your tags as keys, and impacts as values. It also returns a graph of your foreground system which you can use to create some cool tree/bullseye charts - see the docs for the format.
Here's the function you need:
results, graph = recurse_tagged_databases(functional_unit, method, label='name')
Here are a couple of examples of the kinds of visualisations you can make using the data recurse_tagged_databases gives you:
Waterfall chart example from the results dictionary
Bullseye chart example from the tagged graph
It is pretty easy to traverse the supply chain manually, and everyone wants to do this a slightly different way, so it isn't built in to Brightway yet. Here is a simple example:
from brightway2 import *
func_unit = Database("ecoinvent 3.4 cutoff").random()
lca = LCA({func_unit: 1}, methods.random())
lca.lci()
lca.lcia()
print(func_unit)
for exc in func_unit.technosphere():
lca.redo_lcia({exc.input: exc['amount']})
print(exc.input, exc['amount'], lca.score)

Learning Optimal Parameters to Maximize a Reward

I have a set of examples, which are each annotated with feature data. The examples and features describe the settings of an experiment in an arbitrary domain (e.g. number-of-switches, number-of-days-performed, number-of-participants, etc.). Certain features are fixed (i.e. static), while others I can manually set (i.e. variable) in future experiments. Each example also has a "reward" feature, which is a continuous number bounded between 0 and 1, indicating the success of the experiment as determined by an expert.
Based on this example set, and given a set of static features for a future experiment, how would I determine the optimal value to use for a specific variable so as to maximise the reward?
Also, does this process have a formal name? I've done some research, and this sounds similar to regression analysis, but I'm still not sure if it's the same thing.
The process is called "design of experiments." There are various techniques that can be used depending on the number of parameters, and whether you are able to do computations between trials or if you have to pick all your treatments in advance.
full factorial - try each combination, the brute force method
fractional factorial - eliminate some of the combinations in a pattern and use regression to fill in the missing data
Plackett-Burman, response surface - more sophisticated methods, trading off statistical effort for experimental effort
...and many others. This is an active area of statistical research.
Once you've built a regression model from the data in your experiments, you can find an optimum by applying the usual numerical optimization techniques.

Why use Monte-Carlo method?

When should the Monte-Carlo method be used?
For example, why did Joel decide to use the Monte-Carlo method for Evidence Based Scheduling instead of methodically processing all user data for the past year?
Monte Carlo methods are commonly used when the dimensionality of the problem is too high for traditional schemes. A great introductory paper on the subject is Persi Diaconis' The Markov Chain Monte Carlo Revolution.
Suppose that you want to estimate some quantity of interest. In the Joel's example 'ship date' is what you want to estimate. In most such situations, there are random factors that impact our estimates.
When you have a random quantity, you typically wants to know its mean and the standard deviation so that you can take appropriate actions. In simple situations, you can model the quantity as a standard distribution (e.g., normal distribution) for which analytical formulas exist for the mean and the standard deviation. However, there exist many situations where analytical formulas do not exist. In such situations, instead of an analytic solution for the mean and the standard deviation, we resort to simulation. The idea is:
Step 1: Generate factors that impact the quantity of interest using appropriate distributions
Step 2: Compute quantity of interest
Repeat steps 1 and 2 many times and compute the empirical average and standard deviation for what you want to know.
The above is by far the typical application of monte carlo application. See the wikipedia link provided by Jarrod for several such applications and some examples of interesting applications where there is no inherent randomness (e.g., estimation of pi).
Wikipedia has a good article on monte carlo simulation methods. I've used monte carlo on a few occasions - in a nutshell MC methods tend to give accurate-ish answers when trying to project results using sample sets that are pretty much random and somebody would typically use intuition to try and guess at a trend. Unfortunately trying to explain MC methods is pretty tough so check out the article.
Sometimes checking all the options is simply prohibitive.
Because the estimates are usually pretty widely distributed when scheduling programming tasks it makes more sense to treat them statistically.
If we take a project which takes 100's of tasks the errors on the estimates will even out and you end up with a distribution which shows the likelihood of project completion as a range.
It also circumvents some serious issues like task buffering and student syndrome skewing the results even further.

Resources