GreenDelta / olca-ipc.py

Mozilla Public License 2.0
29 stars 17 forks source link

Conversion of olca_type to json's @type not reliable #11

Closed SebaJeku closed 2 months ago

SebaJeku commented 3 years ago

With the schema.py commit 144f5c9 (Aug 14,2020), the initialization of an Entity's olca_type has been changed from None to ''. So, without any further setting of the olca_type, a call to_json (e.g. via Client().insert()) results in @type left '' which -- at least in my environment with OpenLCA 1.10.3 as a server and Python 3.8 as an client -- results in JSON RPC error {'code': -32602, 'message': 'Invalid params: params must be an object with valid @id and @type'} when running the "steel" flow example from https://pypi.org/project/olca-ipc/ In fact, after setting steel.olca_type = olca.schema.Flow.__name__ it runs flawlessly.

msrocka commented 3 years ago

Could you check if this is still an issue when you install the version from the current master branch (e.g. via pip install -U git+https://github.com/GreenDelta/olca-ipc.py.git/@master)?

The olca_type field should be set in the constructor now. See also this test: https://github.com/GreenDelta/olca-ipc.py/blob/master/tests/test_model.py#L24

gthoma commented 3 years ago

Hi Michael, I updated to the current master as described below. I created a product system in olca and ran it with both 'as defined' and 'none' for the allocation type. I get different values for the impacts. I then ran the following via IPC and the result returned was the same as the manual run with 'none' - despite using the olca.AllocationType.USE_DEFAULT_ALLOCATION so the issue is not resolved. Thanks Greg

setup = olca.CalculationSetup() setup.calculation_type = olca.CalculationType.SIMPLE_CALCULATION setup.allocation_method = olca.AllocationType.USE_DEFAULT_ALLOCATION

select the product system and LCIA method

im = client.find(olca.ImpactMethod, 'ReCiPe 2016 Midpoint (H)') #find can take string arguments jl = client.get(olca.NwSet,'28298281-e344-33cf-818a-4b47371c47a3') #ReCiPe 2016 H, World (2010) H normalization. setup.impact_method = olca.ref( olca.ProductSystem, im.id ) #ref returns a pointer; takes UUID argument setup.product_system = client.get(olca.ProductSystem, prodSys.id) #get returns the object; takes UUID argument setup.nw_set = jl

setup.amount = 1000.0

calculate the result and export it to an Excel file

result1 = client.calculate(setup) client.excel_export(result1, farm.Name + 'tst3.xlsx')

From: Michael Srocka notifications@github.com Sent: Monday, January 25, 2021 6:58 AM To: GreenDelta/olca-ipc.py olca-ipc.py@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: Re: [GreenDelta/olca-ipc.py] Conversion of olca_type to json's @type not reliable (#11)

Could you check if this is still an issue when you install the version from the current master branch (e.g. via pip install -U git+https://github.com/GreenDelta/olca-ipc.py.git/@master)?

The olca_type field should be set in the constructor now. See also this test: https://github.com/GreenDelta/olca-ipc.py/blob/master/tests/test_model.py#L24https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FGreenDelta%2Folca-ipc.py%2Fblob%2Fmaster%2Ftests%2Ftest_model.py%23L24&data=04%7C01%7Cgthoma%40uark.edu%7Ca22d23a5e59349a4a4de08d8c130cf2d%7C79c742c4e61c4fa5be89a3cb566a80d1%7C0%7C0%7C637471762683703755%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=H6uZroGRqWern7EsRCiuAQ1vHaj1FVIyRgeIFaNRa90%3D&reserved=0

- You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FGreenDelta%2Folca-ipc.py%2Fissues%2F11%23issuecomment-766797401&data=04%7C01%7Cgthoma%40uark.edu%7Ca22d23a5e59349a4a4de08d8c130cf2d%7C79c742c4e61c4fa5be89a3cb566a80d1%7C0%7C0%7C637471762683703755%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=3mkmBiYeFHnl9sUkMbCOryhW6lmQPIEOYXy3bjNhvjs%3D&reserved=0, or unsubscribehttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAY35SQ52WX6FK5ZQE4NAFLS3VTERANCNFSM4VNO5QJA&data=04%7C01%7Cgthoma%40uark.edu%7Ca22d23a5e59349a4a4de08d8c130cf2d%7C79c742c4e61c4fa5be89a3cb566a80d1%7C0%7C0%7C637471762683713741%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=e9bNvwHHH0YhUoE4uaDVQvyHUgWBzmghyy3IGocy4Fg%3D&reserved=0.

msrocka commented 3 years ago

Hi Greg,

(this was another issue: #11 instead of #7)

I created this test to check this: https://github.com/GreenDelta/olca-ipc.py/blob/master/tests/test_allocation.py#L59

With the current test version of openLCA 2.0 from https://share.greendelta.com/index.php/s/2AJJMhfB1WSIFDO this works for me and a I get a different result for each allocation method. Does this test work for you?

Thanks, Michael

@gthoma @ju1ianr

ezrakahn commented 3 years ago

I am finding a similar issue regarding model_type. the attribute is coming in empty, '', both when I create a new model such as

new = olca.Flow()

or when I query one with ipc for example:

flow = client.get(olca.Flow, refid)

The returned olca.schema.flow object is missing an object type. I tried this with processes and categories too, with same behavior. I have the latest 0.0.10 package.

Sorry, I imported latest master commit and this problem is fixed.

alk22223 commented 2 years ago

@msrocka I am having the same issue w/r/t allocation as mentioned by @gthoma. I am currently using openLCA 1.10.3. Is there any solution to be able to account for allocation in the IPC calculations?

msrocka commented 2 months ago

closing as these are openLCA 1.x issues which are hopefully fixed in current versions