0 votes
175 views

Dear OpenLCA team,

I have a python project loading data to OpenLCA and I noticed that in version 2.6.1 some of my exchanges are loaded with 0 value. I works fine with version 2.6.0. I ran the code twice and the only thing I changed was the OpenLCA version. Here is the result:

Sorry for the quality but it looks that your web page donwscales it like that. I tried to set bigger dimenions but it didn't help. Anyway, the area higlighted with red shows that in version 2.6.0 there are non-zero amounts, while in version 2.6.1 they are all zeros.

The latest version described in the changelog is still 2.6.0 (https://www.openlca.org/download/). Having a changelog for version 2.6.1 could help debug this issue. It appears that the issue affects only exchanges with amounts, while exchanges with formulas are loaded correctly.

Software versions I used:
python: 3.11
olca-ipc: 2.4.0
OpenLCA 2.6.0 and 2.6.1

in openLCA by (180 points)
edited by
by (146k points)
thank you we'll try to have a look. About the pictures: In my experience, if you just upload screenshots, they are already working and "legible".

2 Answers

0 votes
by (14.7k points)
The change-log is updated now but we are not aware of changes that could result in such a behavior. If you could share some script snippets to reproduce this, that would be helpful as the IPC test suite runs without errors.
ago by (180 points)
edited ago by
I removed the comment and posted it as an answer instead, because it seems that comments do not display code blocks properly.
0 votes
ago by (180 points)
edited ago by

I know what caused the issue. In my code, I always assigned the exchange value to the amount_formula property, regardless of whether the value was a formula/expression (string) or a numeric value (float). This worked in version 2.6.0. However, in version 2.6.1 it stopped working when a float was assigned to the amount_formula property. To make it work, I now need to either convert the number to a string before assigning it to amount_formula, or assign the float to the amount property instead.

Below I enclose the full code to reproduce the issue. The relevant part of the full code is here:

e.amount_formula = float(amount)  # doesn't work
e.amount_formula = str(amount)  # works
e.amount = float(amount)  # works

The full code:

import uuid
import olca_ipc as ipc
import olca_schema as o
from olca_schema import ProcessType

client = ipc.Client(endpoint=8080)

flow_property = client.get(o.FlowProperty, client.find(o.FlowProperty, name="Mass").id)
unit_group = client.get(o.UnitGroup, client.find(o.UnitGroup, name="Units of mass").id)
unit = [u for u in unit_group.units if u.name == "kg"][0]

ref_flow_id = str(uuid.uuid4())
ref_flow = o.Flow()
ref_flow.id = ref_flow_id
ref_flow.name = "example product"
ref_flow.flow_type = o.FlowType.PRODUCT_FLOW
ref_factor = o.FlowPropertyFactor()
ref_factor.conversion_factor = 1.0
ref_factor.flow_property = flow_property
ref_factor.is_ref_flow_property = True
ref_flow.flow_properties = [ref_factor]
client.put(ref_flow)

elementary_flow = o.Flow()
elementary_flow.id = str(uuid.uuid4())
elementary_flow.name = "example emission"
elementary_flow.flow_type = o.FlowType.ELEMENTARY_FLOW
elementary_factor = o.FlowPropertyFactor()
elementary_factor.conversion_factor = 1.0
elementary_factor.flow_property = flow_property
elementary_factor.is_ref_flow_property = True
elementary_flow.flow_properties = [elementary_factor]
client.put(elementary_flow)

def exchange(flow, amount=None, formula=None, is_input=False, is_reference=False):
    e = o.Exchange()
    e.id = str(uuid.uuid4())
    e.flow = flow
    e.unit = unit
    e.is_input = is_input
    e.is_quantitative_reference = is_reference
    if formula is not None:
        e.amount_formula = f"{formula}"
    elif amount is not None:
        e.amount_formula = float(amount)  # doesn't work
        e.amount_formula = str(amount)  # works
        e.amount = float(amount)  # works
    else:
        raise Exception('No formula or amount provided')
    return e

process = o.Process()
process.id = str(uuid.uuid4())
process.name = "example process"
process.process_type = ProcessType.UNIT_PROCESS
process.exchanges = [
    exchange(ref_flow, amount=1.0, is_reference=True),
    exchange(elementary_flow, amount=0.5, is_input=True),
    exchange(elementary_flow, formula="a * 2", is_input=True),
]
client.put(process
...