Source code for bw_graph_tools.graph_traversal.settings

from typing import List, Optional, Any

from pydantic import BaseModel, Field, model_validator
from typing_extensions import Annotated


[docs] class GraphTraversalSettings(BaseModel): """ Graph traversal settings object with reasonable defaults. Parameters ---------- cutoff : float Cutoff value used to stop graph traversal. Fraction of total score, should be in `(0, 1)` biosphere_cutoff : float Cutoff value used to determine if a separate biosphere node is added. Fraction of total score. max_calc : int | None Maximum number of inventory calculations to perform max_depth : int Maximum depth in the supply chain traversal. Default is no maximum. skip_coproducts : bool Don't traverse co-production edges, i.e. production edges other than the reference product separate_biosphere_flows : bool Add separate `Flow` nodes for important individual biosphere emissions min_coverage_fraction : float Minimum fraction of the total LCA score that must be covered by the traversed nodes. A warning is raised if coverage falls below this value. Should be in `(0, 1]`. Default is 0.9. """
[docs] cutoff: Annotated[float, Field(strict=True, gt=0, lt=1)] = 5e-3
[docs] biosphere_cutoff: Annotated[float, Field(strict=True, gt=0, lt=1)] = 1e-4
[docs] max_calc: Annotated[int, Field(strict=True, gt=0)] = 1000
[docs] max_depth: Optional[int] = None
[docs] skip_coproducts: bool = False
[docs] separate_biosphere_flows: bool = True
[docs] caching_solver: Any | None = None
[docs] min_coverage_fraction: Annotated[float, Field(strict=True, gt=0, le=1)] = 0.9
@model_validator(mode="after")
[docs] def max_depth_positive(self): if self.max_depth is not None and self.max_depth <= 0: raise ValueError(f"If specified, `max_depth` must be greater than zero") return self
[docs] class TaggedGraphTraversalSettings(GraphTraversalSettings): """ Supply Chain Traversal Settings with a functional unit tag Parameters ---------- tags : List[str] A list of tags to group nodes by """
[docs] tags: List[str] = Field(default_factory=list)