Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for both Brightway 2 and 2.5 #123

Merged
merged 13 commits into from
Oct 12, 2023
Merged

Conversation

cmutel
Copy link
Collaborator

@cmutel cmutel commented Oct 12, 2023

🔨 Work in progress 🔨

Factors out Brightway functionality, and imports the correct function depending on which version is installed.

  • To install the 2.5 version via pip: pip install premise[bw25].
  • On conda we might be able to do the same variant, or just create two different packages.

To support this, I moved from setup.py to pyproject.toml. This also gives us:

  • The new standard packaging pipeline
  • Automatic building of wheels (run python -m build)
  • One place to define the version: __init__.py
  • One place to define the requirements: requirements.txt
  • Inclusion of pytest and other config data (pytest.ini is removed)

Note that 2.5 support requires bw2data 4.0.DEV32, which isn't yet released (will be in ~1 hour from this comment).

We need some testing before this should be released. I have tested the 2.5 functionality, and it builds a matrix and gives a sensible result. However, it would be nice to have a known good result, and test both BW2 and BW2.5 scores. @romainsacchi Could you give a known good result please?

TODO

  • Add notification for bw2data version imported, and bw2/2.5
  • Test export to normal DB on BW2
  • Test export to normal DB on BW2.5
  • Check packaging still works on CI

@cmutel
Copy link
Collaborator Author

cmutel commented Oct 12, 2023

There also might be some packaging weirdness, it seems to work for me now but pyproject.toml is a harsh mistress...

@cmutel
Copy link
Collaborator Author

cmutel commented Oct 12, 2023

Also, I don't know anything about how write_superstructure_db_to_brightway works, this might be broken? Not sure why it would be but ¯\_(ツ)_/¯

@tngTUDOR
Copy link
Collaborator

🔨 Work in progress 🔨

Factors out Brightway functionality, and imports the correct function depending on which version is installed.

* To install the 2.5 version via pip: `pip install premise[bw25]`.

* On `conda` we might be able to do the same variant, or just create two different packages.

By experience, it's "easier" to produce a different conda package (see the ui package building )

import bw_processing

from .brightway25 import write_brightway_database
except ImportError:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking): It would be useful to warn the user if the import goes OK or (bw2) or wrong.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to todo

@tngTUDOR
Copy link
Collaborator

There also might be some packaging weirdness, it seems to work for me now but pyproject.toml is a harsh mistress...

main branch has some fixes for the github actions to work fine now for packaging pypi pkgs and upload them to the registry.

@romainsacchi
Copy link
Collaborator

@cmutel the folowing

from premise import *
from datapackage import Package
bw.projects.set_current("ei39")

scenarios = [
    {"model": "image", "pathway":"SSP2-Base", "year": 2050},
    {"model": "remind", "pathway":"SSP2-PkBudg500", "year": 2050},
]

ndb = NewDatabase(
        scenarios = scenarios,        
        source_db="ecoinvent 3.9.1 cutoff",
        source_version="3.9",
        key='tUePmX_S5B8ieZkkM7WUU2CnO8SmShwmAeWK9x2rTFo=',
)
ndb.update_all()
ndb.write_db_to_brightway()

FU = [
    {act: 1} for db in [
        "ecoinvent 3.9.1 cutoff",
        "ecoinvent_cutoff_3.9_image_SSP2-Base_2050",
        "ecoinvent_cutoff_3.9_remind_SSP2-PkBudg500_2050"
    ] for act in bw2data.Database(db) 
    if act["name"]=="transport, passenger car, electric"
    and act["location"] == "GLO"
]

method = [('IPCC 2021', 'climate change: fossil', 'global warming potential (GWP100)')]

bw2calc.multi_lca.calculation_setups["BEVs"] = {
    "inv": FU,
    "ia": method
}

lca = bw2calc.MultiLCA("BEVs")

print(lca.results)

should return:

[[0.22982712]
 [0.20379977]
 [0.03638609]]

@romainsacchi
Copy link
Collaborator

Also, I don't know anything about how write_superstructure_db_to_brightway works, this might be broken? Not sure why it would be but ¯_(ツ)_/¯

.write_superstructure_db_to_brightway eventually writes a regular database. So if .write_db_to_brightway works, that should work too.

The dependency `sparse` is broken, it imports `Iterable` from collections which doesn't work.
@cmutel
Copy link
Collaborator Author

cmutel commented Oct 12, 2023

2.5 Scores look good:

0.22973739152327347 0.22982712
0.20376602910863864 0.20379977
0.0363075968642278 0.03638609

@cmutel
Copy link
Collaborator Author

cmutel commented Oct 12, 2023

Brightway 2 results are also good!

0.2298271180989315 0.22982712 
0.2038174193431219 0.20379977 
0.03630759719576193 0.03638609

@cmutel
Copy link
Collaborator Author

cmutel commented Oct 12, 2023

@romainsacchi I think this is ready to merge. We can push a release like 1.8.0.dev1 and see if it build correctly.

@romainsacchi romainsacchi merged commit 98ed648 into polca:master Oct 12, 2023
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants