brightway-lca / brightway2-calc

The calculation engine for the Brightway2 life cycle assessment framework.
BSD 3-Clause "New" or "Revised" License
12 stars 15 forks source link

Missing ability to create RNGs for Monte Carlo in Brightway 2.5? #73

Closed Joshua-Schroijen closed 11 months ago

Joshua-Schroijen commented 1 year ago

The issue

Monte Carlo calculations require a RNG object to implement according to the latest Brightway (2.5) docs, but Brightway 2.5's LCA object doesn't have tech_params/bio_params/... attributes anymore. All the documented ways of building these RNGs thus fail now. There don't seem to be any examples of what users are supposed to do now.

Details

In Brightway 2.4 we could create RNG's for Monte Carlo calculations like this using the stats_arrays PyPI package:

#...
from bw2calc import LCA
from stats_arrays import MCRandomNumberGenerator, UncertaintyBase
#...
lca = LCA(demand = func_units, method = ia_methods[0])
#...
tech_rng = MCRandomNumberGenerator(lca.tech_params, seed=my_seed)
#...

That last line can't run in Brightway 2.5. The latest Brightway (2.5) docs don't mention how we can build this RNG in the new Brightway 2.5. But the rest of its explanation on how to do Monte Carlo in 2.5 rests on it.

What could resolve it

A self-contained, executable demonstration script or Jupyter notebook giving a full end to end example of how a very basic Monte Carlo simulation can be done in Brightway 2.5

Thank you in advance for your time, Joshua Schroijen

cmutel commented 1 year ago

@Joshua-Schroijen Thanks a lot for this detailed report. You are totally correct that the documentation needs to improve.

Can you be a bit more specific on what you are trying to do? Having access to an RNG is a means, not an end. You can go to https://try.brightway.dev and notebooks 1 and 2 will show you how to do uncertainty analysis using Monte Carlo, using uncertainty distributions but also correlated exchanges and interfaces to other systems. In order to add these more advanced concepts we need to move away from the simplicity of a single RNG class instance.

Joshua-Schroijen commented 1 year ago

Thank you for your response!

A few months back, we were trying to basically port the code behind Activity Browser's Monte Carlo simulation tab to Brightway 2.5 and use it in our own Brightway 2.5 based project. There were some notebooks floating around at that time for 2.5, but they didn't seem to completely show the workflow of a Monte Carlo simulation. But the notebooks you linked at first glance appear to do so.

Unfortunately, I am not a part of this project anymore and don't have the spare time to go in depth anymore. I invite my former colleagues @rafaelrpinto and @edward-DM to check if they can move ahead and to move ahead with this issue. Otherwise I will close it in a week or so.

Thank you!

cmutel commented 11 months ago

@rafaelrpinto and @edward-DM I am closing this - we need to get the Monte Carlo working for the AB, and are tracking progress on that here: https://github.com/cauldron/activity-browser/issues/4