[Python] Problems with MultiLCA and monte carlo simulation in brightway25

Discussão em 'Python' iniciado por Stack, Maio 19, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to perform a Monte Carlo simulation on my LCIA results with brightway25. Unfortunately, I am facing multiple problems.But step by step.

    If I try to perform a Monte Carlo simulation using the LCA class I use the following code:

    lca_results = {}
    relevant_contributions = []
    relevant_flows = []
    first_level_impact = []
    iter_monteCarlo = 100
    for method in LCIA_methods:
    lca = bc.LCA(functional_unit, method)
    try:
    lca.lci()
    lca.lcia()
    lca_results[method] = lca.score

    ## Get relevant processes
    relevant_processes = bw2analyzer.ContributionAnalysis().annotated_top_processes(lca,limit=0.01,limit_type='percent')
    ## Get relevant emissions
    relevant_emission = bw2analyzer.ContributionAnalysis().annotated_top_emissions(lca,limit=0.01,limit_type='percent')
    ## sum the relevant data up
    relevant_contributions.append({
    "Methode": method,
    "Total score": lca.score,
    "Processes": relevant_processes,
    "CutOff": 0.01,
    })
    relevant_flows.append({
    "Methode": method,
    "Total score": lca.score,
    "Processes": relevant_emission,
    "CutOff": 0.01,
    })

    ## perform Monte carlo simulation
    lca = bc.LCA(functional_unit, method,selective_use={
    'technosphere_matrix': {'use_distributions': True},
    'biosphere_matrix': {'use_distributions': True},
    'characterization_matrix': {'use_distributions': False}},seed_override=None) # Critical for random sampling)
    lca.lci()
    monte_carloResults = np.zeros(iter_monteCarlo)
    for i in range(iter_monteCarlo):
    lca.lci()
    lca.lcia()
    monte_carloResults = lca.score
    except Exception as e:
    print("Error loading LCI data: ", e)


    The problem is that for every iteration of the Monte Carlo simulation, I obtain the same value. Also, the value is, compared to the static LCIA result (~24 kg CO2-eq), much higher, 4000-40000kg CO2-eq. After calling the constructor of the LCA class I get different results, but as I understand, this is not the correct way.

    Also if I use the MultiLCA class I do not obtain different results between the iterations. Here is my code with the MultiLCA class:

    test_func_unit = {"CellProduction": {activity.id: 1}}
    method_config = {"impact_categories": LCIA_methods}
    data_objs = bd.get_multilca_data_objs(test_func_unit,method_config=method_config)
    mlca = bc.MultiLCA(demands=test_func_unit,method_config=method_config,data_objs=data_objs,use_distributions=True)
    # monte carlo
    for i in range(iter_monteCarlo):
    mlca.lci()
    mlca.lcia()
    monte_carloResults = next(iter(mlca.scores.values()))


    Of course, some probabilites have to be wrongly defined, otherwise I would not get results multiple orders of magnitude higher than the static LCIA results. Nevertheless, the results should at least differ from iteration to iteration. What did I do wrong?

    Thanks already a lot for your help. I hope I could describe everything in an understandable way.

    Continue reading...

Compartilhe esta Página