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

Refactoring type checks and technosphere/biosphere split #1301

Open
cmutel opened this issue Jun 5, 2024 · 2 comments
Open

Refactoring type checks and technosphere/biosphere split #1301

cmutel opened this issue Jun 5, 2024 · 2 comments
Labels
feature Issues/PRs related to a new feature

Comments

@cmutel
Copy link
Contributor

cmutel commented Jun 5, 2024

Feature request

In bw2data, type checks are used for the following:

In current Brightway the labels used are configurable, i.e. nothing is hard coded. To maximize flexibility and reduce the potential for frustrating errors, we actually don't need to label nodes at all - rather, we let things be according to the context that they are used in. This means we don't have to worry about whether a node is a process, a product, or a chimaera.

The edge labels can be divided into three classes:

  • biosphere_edge_types
  • technosphere_negative_edge_types
  • technosphere_positive_edge_types

But I think you could join these last two for your purposes.

I am trying to get the refactoring branch usable in 2.5, and building on FOSS data, namely the USEEIO. This is easy to install:

import bw2io as bi
bi.remote.install_project('USEEIO-1.1', project_name="something")

However, I can't create a calculation setup - when I try to drag a node of type product into the "Reference flows" table (CSActivityTable), the drop event is not accepted. I think this is because of the getattr(event.source(), "technosphere", False) check, though I am not 100% certain.

My immediate problem is that this is stopping me from being able to create test fixtures to give to my colleagues so they can hack hack hack the night away; I would love to know where this "technosphere" attribute is attached, so that we can make that a bit more robust. I originally thought it was this line: "biosphere" if self.database == config.biosphere else "technosphere", but that doesn't appear true in this case.

In the medium term, I am really uncomfortable with the widespread use of bw2data.config.biosphere and the very concept that a given database is either technosphere or biosphere. This will just break for many, many people. A Database is a collection of nodes, and membership in a given Database says nothing about type or any other attribute. It's much better to let the ducks wander around here; if a node only has edges with types biosphere_edge_types, then it is should be blocked from being used as a product in a calculation setup. Otherwise, let everything in, and catch OutsideTechnosphere at calculation time.

@marc-vdm @mrvisscher @jsvgoncalves FYI

@cmutel cmutel added the feature Issues/PRs related to a new feature label Jun 5, 2024
@cmutel
Copy link
Contributor Author

cmutel commented Jun 5, 2024

Here's another example of how the current approach can break things:

In lca_setup.py, we currently check for the node type, and raise an error if the node type is not process:

if act.get("type", "process") != "process":
    raise TypeError("Activity is not of type 'process'")

However, this is precisely incorrect - the functional unit is of products, not processes; the only processes that are valid here are chimaeras which act as both product and process at the same time.

@mrvisscher
Copy link
Collaborator

Quick comment from mobile to get you on your way. The technosphere attribute in question is attached to the ActivitiesBiosphereModel here and is derived from a function in bwutils.commontasks called is_technosphere_db

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Issues/PRs related to a new feature
Projects
None yet
Development

No branches or pull requests

2 participants