Supply-chain API¶
Used by the runnable scripts in the supply-chain showcase.
The data dictionary defines all summary, detailed-report, and sweep columns, including solver signs and graph scope.
SupplyChainAnalyzer
¶
SupplyChainAnalyzer(
economy: Economy,
scenario: Scenario,
terminal_good: str,
*,
tolerance: float = 1e-09,
)
Compile and analyze one nominal single-terminal production scenario.
Parameters:
-
(economy¶Economy) –Economy containing production, goods, and workforce data.
-
(scenario¶Scenario) –Scenario with positive terminal exports and an enabled balance floor.
-
(terminal_good¶str) –Good key used to focus the graph and reports.
-
(tolerance¶float, default:1e-09) –Positive numerical threshold for active levels and edges.
Raises:
-
ValueError–If the target, objective, terminal good, or tolerance is invalid for a version-1 nominal analysis.
Methods:
-
run–Solve once and return an immutable supply-chain result.
Source code in src/vic3_analysis/analysis/supply_chain/analyzer.py
run
¶
run() -> SupplyChainResult
Solve once and return an immutable supply-chain result.
Source code in src/vic3_analysis/analysis/supply_chain/analyzer.py
SupplyChainResult
dataclass
¶
SupplyChainResult(
scenario: Scenario,
terminal_good: str,
target_quantity: float,
problem: LinearProblem,
state: EconomyState,
diagnostics: SolverDiagnostics,
production: DataFrame,
goods_index: tuple[str, ...],
config_index: tuple[str, ...],
profession_index: tuple[str, ...],
employment_matrix: ndarray,
employment_vector: ndarray,
construction_cost_vector: ndarray,
arable_land_vector: ndarray,
infrastructure_vector: ndarray,
realized_graph: DiGraph,
allowed_graph: DiGraph,
tolerance: float = 1e-09,
)
Immutable, reproducible result of one terminal-good analysis.
-
API Reference
Supply-chain API
SupplyChainSweepResult
Methods:
-
graph–Return a defensive copy of the requested bipartite graph.
-
processes–Return process economics and resource attributes for one view.
-
goods–Return good balances for processes present in one graph view.
-
flows–Return one row per goods/process edge in one graph view.
-
workforce–Return realized terminal-chain employment by process and profession.
-
constraints–Return named LP constraint values, slacks, and solver marginals.
-
bottlenecks–Return binding inequalities with a useful relaxation marginal.
-
alternatives–Return scenario-allowed producer alternatives for one or all goods.
-
summary–Return headline, structural, and aggregate production-unit metrics.
-
to_mermaid–Return a deterministic Mermaid representation.
-
plot_network–Return a deterministic weighted network figure.
-
plot_contributions–Return a process-contribution bar chart.
-
plot_goods_balance–Return a goods supply-and-demand chart.
-
plot_constraints–Return a binding-constraint marginal chart.
graph
¶
Return a defensive copy of the requested bipartite graph.
processes
¶
Return process economics and resource attributes for one view.
goods
¶
Return good balances for processes present in one graph view.
Source code in src/vic3_analysis/analysis/supply_chain/result.py
flows
¶
Return one row per goods/process edge in one graph view.
Source code in src/vic3_analysis/analysis/supply_chain/result.py
workforce
¶
Return realized terminal-chain employment by process and profession.
Source code in src/vic3_analysis/analysis/supply_chain/result.py
constraints
¶
Return named LP constraint values, slacks, and solver marginals.
Source code in src/vic3_analysis/analysis/supply_chain/result.py
bottlenecks
¶
Return binding inequalities with a useful relaxation marginal.
Source code in src/vic3_analysis/analysis/supply_chain/result.py
alternatives
¶
Return scenario-allowed producer alternatives for one or all goods.
Source code in src/vic3_analysis/analysis/supply_chain/result.py
summary
¶
Return headline, structural, and aggregate production-unit metrics.
Chain fields include whole realized processes and their coproducts; system fields include all solved configurations. Resource columns use full extraction-building keys from the production snapshot, including unused types, and report levels and levels per 10,000 employed workers. Wage metrics require finite coefficients for contributing processes. Known zero denominators produce zero; unavailable wage data produce NaN.
Source code in src/vic3_analysis/analysis/supply_chain/result.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 | |
to_mermaid
¶
Return a deterministic Mermaid representation.
Source code in src/vic3_analysis/analysis/supply_chain/result.py
plot_network
¶
plot_network(
view: str = "realized",
*,
metric: str = "value",
max_producers_per_good: int = 3,
) -> Figure
Return a deterministic weighted network figure.
Source code in src/vic3_analysis/analysis/supply_chain/result.py
plot_contributions
¶
Return a process-contribution bar chart.
Source code in src/vic3_analysis/analysis/supply_chain/result.py
plot_goods_balance
¶
Return a goods supply-and-demand chart.
Source code in src/vic3_analysis/analysis/supply_chain/result.py
plot_constraints
¶
Return a binding-constraint marginal chart.
Source code in src/vic3_analysis/analysis/supply_chain/result.py
SupplyChainSweepResult
dataclass
¶
SupplyChainSweepResult(
_summary: DataFrame,
_failures: DataFrame,
_building_levels: DataFrame,
_results: Mapping[str, SupplyChainResult],
)
Result of applying one scenario template across terminal goods.
-
API Reference
Supply-chain API
sweep_supply_chains
Methods:
-
result_for–Return the retained analysis for good.
Attributes:
-
summary(DataFrame) –Return one fixed-schema row per requested good.
-
failures(DataFrame) –Return unsuccessful sweep rows.
-
df_building_levels(DataFrame) –Return whole-system levels by production unit and terminal good.
-
results(Mapping[str, SupplyChainResult]) –Return retained successful results, empty when not requested.
df_building_levels
property
¶
Return whole-system levels by production unit and terminal good.
Rows follow the economy's production-unit order, indexed by config;
columns follow requested goods order. Failed solves contain NaN, while
successful unused units retain zero. Available even without retained
results; an empty sweep keeps every row with no goods columns.
results
property
¶
results: Mapping[str, SupplyChainResult]
Return retained successful results, empty when not requested.
result_for
¶
result_for(good: str) -> SupplyChainResult
Return the retained analysis for good.
Source code in src/vic3_analysis/analysis/supply_chain/result.py
sweep_supply_chains
¶
sweep_supply_chains(
economy: Economy,
scenario_template: Scenario,
*,
goods: Iterable[str] | None = None,
target_value: float = 100000.0,
keep_results: bool = False,
tolerance: float = 1e-09,
) -> SupplyChainSweepResult
Analyze goods with at least the requested base-price export value.
Each terminal export amount is the higher of its aggregated template
exports and target_value / base_price. Other exports and all imports
are retained. Target metadata reports the effective terminal exports.
Summary columns include fixed economic metrics and per-building resource
levels derived from the full economy, including banned and unused types.
Empty sweeps retain the same columns; failed solves use NaN for metrics.
df_building_levels retains every production unit's solved level for
each requested good, independently of keep_results; failures use NaN.
Source code in src/vic3_analysis/analysis/supply_chain/sweep.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |