distgridforge 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. distgridforge-0.3.0.dist-info/METADATA +266 -0
  2. distgridforge-0.3.0.dist-info/RECORD +38 -0
  3. distgridforge-0.3.0.dist-info/WHEEL +5 -0
  4. distgridforge-0.3.0.dist-info/licenses/LICENCE.txt +21 -0
  5. distgridforge-0.3.0.dist-info/top_level.txt +1 -0
  6. gridforge/__init__.py +32 -0
  7. gridforge/case_study/config.py +158 -0
  8. gridforge/case_study/dickert_lv_network_script.py +109 -0
  9. gridforge/case_study/mv_lv_feeder.py +314 -0
  10. gridforge/case_study/simbench_network_test_case.py +168 -0
  11. gridforge/core/__init__.py +0 -0
  12. gridforge/core/constraints.py +421 -0
  13. gridforge/core/cost_model.py +363 -0
  14. gridforge/core/grid_enhancement.py +1932 -0
  15. gridforge/core/power_flow.py +1146 -0
  16. gridforge/core/strategy.py +297 -0
  17. gridforge/engines/__init__.py +0 -0
  18. gridforge/engines/gridlabd_engine.py +527 -0
  19. gridforge/engines/opendss_engine.py +885 -0
  20. gridforge/engines/pandapower_engine.py +3766 -0
  21. gridforge/engines/roseau_engine.py +1234 -0
  22. gridforge/examples/__init__.py +0 -0
  23. gridforge/examples/quick_start.py +85 -0
  24. gridforge/main.py +0 -0
  25. gridforge/strategies/__init__.py +0 -0
  26. gridforge/strategies/flexibility.py +1476 -0
  27. gridforge/strategies/line_upgrade.py +1846 -0
  28. gridforge/strategies/path_to_source.py +596 -0
  29. gridforge/strategies/sizing.py +210 -0
  30. gridforge/strategies/step_check.py +183 -0
  31. gridforge/strategies/tap_change.py +267 -0
  32. gridforge/strategies/transformer_upgrade.py +622 -0
  33. gridforge/utils/__init__.py +0 -0
  34. gridforge/utils/config.py +55 -0
  35. gridforge/utils/interactive_plot.py +700 -0
  36. gridforge/utils/logging.py +86 -0
  37. gridforge/utils/plot.py +1078 -0
  38. gridforge/utils/reporting.py +0 -0
@@ -0,0 +1,266 @@
1
+ Metadata-Version: 2.4
2
+ Name: distgridforge
3
+ Version: 0.3.0
4
+ Summary: A package for analyzing constraints in power grids
5
+ Author-email: Yassine Abdelouadoud <yassine.abdelouadoud@minesparis.psl.eu>, Yoann Chiche <yoann.chiche@minesparis.psl.eu>
6
+ License: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.12
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.12
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENCE.txt
14
+ Requires-Dist: pandas<3,>=2.2
15
+ Requires-Dist: numpy>=1.26
16
+ Requires-Dist: scipy>=1.13
17
+ Requires-Dist: matplotlib>=3.8
18
+ Requires-Dist: networkx>=3.2
19
+ Requires-Dist: pandapower<3.3,>=3.1.2
20
+ Requires-Dist: numba>=0.60
21
+ Requires-Dist: pyyaml>=6.0
22
+ Requires-Dist: folium>=0.16
23
+ Requires-Dist: shapely>=2.0
24
+ Provides-Extra: roseau
25
+ Requires-Dist: roseau-load-flow>=0.12; extra == "roseau"
26
+ Provides-Extra: opendss
27
+ Requires-Dist: opendssdirect.py>=0.9; extra == "opendss"
28
+ Dynamic: license-file
29
+
30
+ # GridForge
31
+
32
+ ![Python Version](https://img.shields.io/badge/python-3.12+-blue.svg)
33
+ ![License](https://img.shields.io/badge/license-MIT-green.svg)
34
+
35
+ ## Description
36
+
37
+ GridForge is a Python library that finds how to resolve the constraint violations of a
38
+ distribution network (over- and under-voltages, overloaded lines and transformers) at the
39
+ lowest cost. A greedy algorithm applies operational and planning strategies, from tap
40
+ changes to equipment upgrades, checks their effect with a power flow, and reports what it
41
+ did, why, and at what cost.
42
+
43
+ ## Features
44
+
45
+ - **Power flow and constraint checks** with [pandapower](https://www.pandapower.org/):
46
+ voltage limits, line and transformer loading.
47
+ - **Grid enhancement algorithm**: a greedy loop over the violation types, which chooses,
48
+ for each type, the strategies that lead to the cheapest end of the run, and keeps the
49
+ best partial solution when it cannot resolve everything.
50
+ - **Strategies**: transformer tap changes, flexibility (load shedding and generation
51
+ curtailment, guided by power flow sensitivities), line upgrades along conductor ladders
52
+ (including a path-to-source variant), and transformer upgrades or parallel units.
53
+ - **Cost model**: prices of every action, checked before a run so that none is assumed.
54
+ - **Explainability**: each action is logged with the grid state, the target violation and
55
+ its quantitative justification.
56
+ - **Visualisation**: network plots of the violations, and an interactive HTML page of the
57
+ steps of a run.
58
+
59
+ pandapower is the only working engine. The Roseau, OpenDSS and GridLAB-D adapters in
60
+ `gridforge/engines` are incomplete and cannot run the algorithm yet; their future is
61
+ discussed in issue #7.
62
+
63
+ ## Installation
64
+
65
+ GridForge is managed with [uv](https://docs.astral.sh/uv/) and installed from source:
66
+
67
+ ```bash
68
+ git clone https://git.persee.minesparis.psl.eu/energy-alternatives/gridforge.git
69
+ cd gridforge
70
+ uv sync
71
+ ```
72
+
73
+ `uv sync` creates `.venv` from `uv.lock`, including the development tools. Run commands through it with `uv run`:
74
+
75
+ ```bash
76
+ uv run pytest gridforge/tests
77
+ uv run pre-commit install
78
+ ```
79
+
80
+ Optional dependencies are installed on request:
81
+
82
+ ```bash
83
+ uv sync --extra roseau --extra opendss # Roseau and OpenDSS libraries
84
+ uv sync --group docs # Sphinx documentation
85
+ uv sync --group notebooks # Jupyter, for the case-study notebooks
86
+ ```
87
+
88
+ The PyPI distribution is `distgridforge`, and its import name is `gridforge`:
89
+
90
+ ```bash
91
+ pip install distgridforge
92
+ ```
93
+
94
+ Do not run `pip install gridforge`: the PyPI project named `gridforge` is an unrelated
95
+ table-formatting library that provides the same import name, so the two cannot be installed
96
+ in one environment, and that command installs the wrong package.
97
+
98
+ ## Quick Start
99
+
100
+ The example below builds a small LV feeder with an overloaded cable and an under-voltage,
101
+ and lets GridForge resolve them. It is `gridforge/examples/quick_start.py`, which the
102
+ tests run, so you can also run it with `uv run python -m gridforge.examples.quick_start`.
103
+
104
+ ```python
105
+ import pandapower as pp
106
+
107
+ from gridforge import CostModel, PandaPowerEngine
108
+ from gridforge.core.grid_enhancement import (
109
+ EnhancementStrategyRegistry,
110
+ GridEnhancementAlgorithm,
111
+ )
112
+ from gridforge.strategies.line_upgrade import LineUpgradeStrategy
113
+ from gridforge.strategies.tap_change import TapChangeStrategy
114
+ from gridforge.strategies.transformer_upgrade import TransformerUpgradeStrategy
115
+
116
+ # A small LV feeder: a 250 kVA substation and a 250 m cable feeding 120 kW
117
+ net = pp.create_empty_network()
118
+ mv_bus = pp.create_bus(net, vn_kv=20.0, name="MV bus")
119
+ lv_bus = pp.create_bus(net, vn_kv=0.4, name="LV busbar")
120
+ end_bus = pp.create_bus(net, vn_kv=0.4, name="Feeder end")
121
+ pp.create_ext_grid(net, bus=mv_bus, vm_pu=1.0, name="Grid")
122
+ pp.create_transformer(
123
+ net, hv_bus=mv_bus, lv_bus=lv_bus, std_type="0.25 MVA 20/0.4 kV", name="Substation"
124
+ )
125
+ pp.create_line(
126
+ net,
127
+ from_bus=lv_bus,
128
+ to_bus=end_bus,
129
+ length_km=0.25,
130
+ std_type="NAYY 4x50 SE",
131
+ name="Cable",
132
+ )
133
+ pp.create_load(net, bus=end_bus, p_mw=0.12, q_mvar=0.04, name="Load")
134
+
135
+ engine = PandaPowerEngine()
136
+ engine.network = net
137
+
138
+ # The cable is overloaded and the feeder end is under-voltage
139
+ engine.run_power_flow()
140
+ for violation in engine.check_violations():
141
+ print(f"Before: {violation.constraint_type.value} at {violation.element_id}")
142
+
143
+ # The strategies try the cheapest fixes first: tap changes, then line and
144
+ # transformer upgrades: a larger type, or one more conductor or unit of the type
145
+ # in place, whichever is cheaper at the prices below.
146
+ registry = EnhancementStrategyRegistry()
147
+ registry.register_strategy(TapChangeStrategy())
148
+ registry.register_strategy(
149
+ LineUpgradeStrategy(
150
+ line_types={
151
+ "lv": {
152
+ "overhead": [],
153
+ "underground": ["NAYY 4x50 SE", "NAYY 4x120 SE", "NAYY 4x150 SE"],
154
+ }
155
+ }
156
+ )
157
+ )
158
+ registry.register_strategy(
159
+ TransformerUpgradeStrategy(["0.25 MVA 20/0.4 kV", "0.4 MVA 20/0.4 kV"])
160
+ )
161
+
162
+ # Every type of these ladders needs a price: a missing one raises
163
+ # MissingUnitCostError before the run (see "Unit Costs" in the usage docs).
164
+ cost_model = CostModel(
165
+ {
166
+ "line_upgrade": { # €/km
167
+ "NAYY 4x50 SE": 50.0e3,
168
+ "NAYY 4x120 SE": 70.0e3,
169
+ "NAYY 4x150 SE": 80.0e3,
170
+ },
171
+ "transformer_upgrade": { # € per unit
172
+ "0.25 MVA 20/0.4 kV": 5000.0,
173
+ "0.4 MVA 20/0.4 kV": 8000.0,
174
+ },
175
+ "tap_change": 10.0, # € per tap step
176
+ }
177
+ )
178
+
179
+ algorithm = GridEnhancementAlgorithm(
180
+ power_flow_engine=engine,
181
+ strategy_registry=registry,
182
+ cost_model=cost_model,
183
+ )
184
+ success, results = algorithm.run()
185
+
186
+ print(f"Resolved: {success}, total cost: {results['total_cost']:.0f} €")
187
+ for action in results["actions_applied"]:
188
+ print(f"- {action['type']}")
189
+ print(f"Remaining violations: {len(results['remaining_violations'])}")
190
+ ```
191
+
192
+ It prints the violations before the run, then:
193
+
194
+ ```
195
+ Resolved: True, total cost: 12500 €
196
+ - line_upgrade
197
+ Remaining violations: 0
198
+ ```
199
+
200
+ GridForge identifies buses, lines and transformers by their name, so each must have one
201
+ of its own, as in the example: `run_power_flow` refuses a network where one has none or
202
+ shares it. For a network that leaves elements unnamed, as several of pandapower's example
203
+ networks do, call `engine.fill_missing_names()` after assigning it; `engine.check_names()`
204
+ tells at once whether a network will be accepted.
205
+
206
+ The [usage documentation](https://pages.persee.minesparis.psl.eu/energy-alternatives/gridforge/usage.html)
207
+ describes the results, the unit costs and the visualisation. The case studies in
208
+ `gridforge/case_study` run the algorithm on real MV/LV feeders, the Dickert LV networks
209
+ and SimBench. The Dickert LV case study needs `igraph`, which the development environment
210
+ installed by `uv sync` provides.
211
+
212
+ ## Project Structure
213
+
214
+ ```
215
+ gridforge/
216
+ ├── core/
217
+ │ ├── constraints.py # Constraint types, limits and violations
218
+ │ ├── cost_model.py # Unit costs and pricing of actions
219
+ │ ├── grid_enhancement.py # The enhancement algorithm and the strategy registry
220
+ │ ├── power_flow.py # The engine interface
221
+ │ └── strategy.py # The strategy interface
222
+ ├── engines/
223
+ │ ├── pandapower_engine.py
224
+ │ ├── roseau_engine.py # Incomplete, see #7
225
+ │ ├── opendss_engine.py # Incomplete, see #7
226
+ │ └── gridlabd_engine.py # Incomplete, see #7
227
+ ├── strategies/
228
+ │ ├── tap_change.py
229
+ │ ├── flexibility.py
230
+ │ ├── line_upgrade.py
231
+ │ ├── path_to_source.py
232
+ │ └── transformer_upgrade.py
233
+ ├── utils/
234
+ │ ├── interactive_plot.py # HTML page of the steps of a run
235
+ │ ├── plot.py # Network plots of the violations
236
+ │ ├── logging.py
237
+ │ └── config.py
238
+ ├── case_study/ # Scripts and notebooks on example networks
239
+ ├── examples/ # The quick start
240
+ ├── data/ # Example feeders (most of the feeder data is not versioned, see #10)
241
+ └── tests/
242
+ benchmarks/ # Profiling of the case study
243
+ docs/ # Sphinx documentation
244
+ ```
245
+
246
+ ## Documentation
247
+
248
+ The documentation is published on GitLab Pages:
249
+ <https://pages.persee.minesparis.psl.eu/energy-alternatives/gridforge/>. To build it
250
+ locally, see the [installation guide](docs/source/installation.rst).
251
+
252
+ ## Contributing
253
+
254
+ Changes go through merge requests on
255
+ [GitLab](https://git.persee.minesparis.psl.eu/energy-alternatives/gridforge):
256
+
257
+ 1. Open or pick an issue that describes the change.
258
+ 2. Create a branch from `main`, named after the issue (`git checkout -b 42-short-description`).
259
+ 3. Run `uv run pre-commit install` once, so that ruff checks and formats each commit, and
260
+ run the tests with `uv run pytest gridforge/tests`.
261
+ 4. Push the branch and open a merge request that closes the issue (`Closes #42`).
262
+ 5. The CI pipeline (lint, tests, documentation build) must pass before merging.
263
+
264
+ ## License
265
+
266
+ This project is licensed under the MIT License. See [LICENCE.txt](LICENCE.txt) for details.
@@ -0,0 +1,38 @@
1
+ distgridforge-0.3.0.dist-info/licenses/LICENCE.txt,sha256=yMxqxX5xUKS0uMyfJo8beuWTnU5fGIjamQ2H71wTnZE,1096
2
+ gridforge/__init__.py,sha256=Qqc-wJYTzsFQvQAGJSuCn5avPmn3Ap4qHwi5v-6nUJ4,864
3
+ gridforge/main.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ gridforge/case_study/config.py,sha256=WXqCEY9Mx11EDvmSa6oumuGnS4J3NhwMAx5jkfJl180,6434
5
+ gridforge/case_study/dickert_lv_network_script.py,sha256=WTjeNiTddU7ybkfAKaKAvvLoHSktT9ZqOeQDnTmw3RU,3310
6
+ gridforge/case_study/mv_lv_feeder.py,sha256=Qwy7DpmmJpp_dN_dR1oVBYnazc5XvwrGvi3vxTuqlMQ,11405
7
+ gridforge/case_study/simbench_network_test_case.py,sha256=sLLaZJ1GSat2GptbdUwND_zT-2ra_YBaYkx3lACn-Lk,5384
8
+ gridforge/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ gridforge/core/constraints.py,sha256=dPY2E4NiKWcmIKeEtfInRcR6oXXCSJ6SPlnvdi4B_38,16255
10
+ gridforge/core/cost_model.py,sha256=g6INBnRMuSAiE_xLb6t9Xjk0SXkogcLo__68U3q1Zv4,13693
11
+ gridforge/core/grid_enhancement.py,sha256=EU1jCXHCluydPPNYb3wcN369vsHNOb4yj3ATQyFp2rA,87348
12
+ gridforge/core/power_flow.py,sha256=Rv6VJcJj1DodHblJOmPMh_FFuTW3RYoXpa3plSiGmP8,43347
13
+ gridforge/core/strategy.py,sha256=aUFpI-sJPgEg8lAXSuJhrvAnnSr-IK4jMf0WKxYLcmo,11793
14
+ gridforge/engines/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
+ gridforge/engines/gridlabd_engine.py,sha256=uyHhAfJNsJDqJ-rlAJJ2VIHaNq_esraigOC0tEGpWSU,15535
16
+ gridforge/engines/opendss_engine.py,sha256=fHI95PR-V1GfhpQ_M_Ifg5htPqSpb8gGyy2Ok31BUAU,29668
17
+ gridforge/engines/pandapower_engine.py,sha256=7QEMLIF5IaHtM54eU-MqeZvFS-4J4uZZO6yTjoIYjok,163222
18
+ gridforge/engines/roseau_engine.py,sha256=L1wwnSu5tbzlo_R-KzrksksDQAuxULBFLligltvw1wg,41862
19
+ gridforge/examples/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
+ gridforge/examples/quick_start.py,sha256=-8octQh2SRe9GKqyNcjIILymD-J9Pb0vYbHG3sTgxj0,2876
21
+ gridforge/strategies/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
+ gridforge/strategies/flexibility.py,sha256=CiAmO8QgbXK-AlomY0fVwvQD7kTghgnLx0SKUyDaoio,74347
23
+ gridforge/strategies/line_upgrade.py,sha256=-MgEyFhL8pVw13l0zJiRNUXs9-T6U7LlsmuNCQoAP_s,84526
24
+ gridforge/strategies/path_to_source.py,sha256=nrvxaILxB9vZL8VmK1CE4N11LIXna_Vnbq1WlW13BCE,26281
25
+ gridforge/strategies/sizing.py,sha256=IuDUUbgppGuQ9R3mZSYO1n02bV9h373MBTMCd7-BYPA,8430
26
+ gridforge/strategies/step_check.py,sha256=O2Q0SZpkhpfUZX8WlvFqAPWEbvCXtrQNjnonHMFmpOA,8565
27
+ gridforge/strategies/tap_change.py,sha256=t2eDENiJRVZRY1aTrREce6V71DQw3dd-SWajEo7NoGE,10688
28
+ gridforge/strategies/transformer_upgrade.py,sha256=HyaEzcr22yUTVMmg8aCORwVzTlp0DsKZ-hxEB0HEfMk,28358
29
+ gridforge/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
30
+ gridforge/utils/config.py,sha256=zruyc7EI4WePqI6UianhcAxZQGnQEPZeoj8ZvM9eJ0o,1578
31
+ gridforge/utils/interactive_plot.py,sha256=dJpiT-t4jSsWzvvKOXK3rhqrpJy1vZFSNlh9NeKrIw4,29876
32
+ gridforge/utils/logging.py,sha256=axtc-Kaj_VlSOdI5JPVhcUjPq_tBhs1p9ypvGKjMCfM,2616
33
+ gridforge/utils/plot.py,sha256=xzmCD_imdIq5dMCDAlZp77d3hgNVCwz_Z4uYnxew1vs,36534
34
+ gridforge/utils/reporting.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
+ distgridforge-0.3.0.dist-info/METADATA,sha256=LPK1h_FgOtKzf8g4QuN7ac3yL_b4WSauavwAeFOpU10,10239
36
+ distgridforge-0.3.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
37
+ distgridforge-0.3.0.dist-info/top_level.txt,sha256=W0KWee3AOCM2yWSVyKlYyWxLxL48vAKEF6mvc4ka_cs,10
38
+ distgridforge-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2026 PERSEE Mines Paris PSL
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the “Software”), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ gridforge
gridforge/__init__.py ADDED
@@ -0,0 +1,32 @@
1
+ """
2
+ Distribution Network Reinforcement Framework
3
+ -------------------------------------------
4
+
5
+ A framework for analyzing and reinforcing distribution networks
6
+ using various power flow engines and gridforge strategies.
7
+ """
8
+
9
+ __version__ = "0.3.0"
10
+ __author__ = "Yassine Abdelouadoud"
11
+
12
+ from pathlib import Path
13
+
14
+ from gridforge.core.constraints import (
15
+ ConstraintType,
16
+ ConstraintViolation,
17
+ )
18
+ from gridforge.core.cost_model import (
19
+ CostModel,
20
+ InvalidUnitCostError,
21
+ MissingUnitCostError,
22
+ )
23
+ from gridforge.core.power_flow import PowerFlowEngine, PowerFlowNotConverged
24
+ from gridforge.engines.pandapower_engine import (
25
+ PandaPowerControllerNotConverged,
26
+ PandaPowerEngine,
27
+ PandaPowerNotConverged,
28
+ )
29
+ from gridforge.utils.logging import setup_logging
30
+
31
+ # Path definition
32
+ data_path = {"pandapower": Path(__file__).parent / "data" / "pandapower"}
@@ -0,0 +1,158 @@
1
+ """
2
+ Shared configuration data for the case-study scripts.
3
+
4
+ Each script targets a different example network (a custom MV/LV feeder set, a
5
+ pandapower built-in Dickert LV network, and a SimBench network), so the
6
+ line/transformer type tables and unit costs below are genuinely distinct per
7
+ study — this module's only job is to give that data a single, discoverable
8
+ home instead of burying it inline in each script's functions.
9
+ """
10
+
11
+ from dataclasses import dataclass
12
+
13
+
14
+ @dataclass(frozen=True)
15
+ class CaseStudyConfig:
16
+ """Config for one case-study script: strategy inputs and unit costs."""
17
+
18
+ line_types: dict[str, dict[str, list[str]]]
19
+ trafo_types: list[str]
20
+ unit_costs: dict[str, dict[str, float] | float]
21
+ line_upgrade_max_iterations: int = 100
22
+ # Smallest voltage change (p.u.) that a line upgrade step must bring to the violated
23
+ # buses, on average, to be taken (see LineUpgradeStrategy)
24
+ line_upgrade_min_voltage_sensitivity: float = 0.0001
25
+ flexibility_n_activation: int = 1
26
+ # Passes through the violation types (see GridEnhancementAlgorithm)
27
+ algorithm_max_iterations: int = 3
28
+
29
+
30
+ MV_LV_FEEDER = CaseStudyConfig(
31
+ line_types={
32
+ "lv": {
33
+ "overhead": ["T_AL_50_lv", "T_AL_70_lv", "T_AL_150_lv"],
34
+ "underground": ["U_AL_95_lv", "U_AL_150_lv", "U_AL_240_lv", "U_AL_288_lv"],
35
+ },
36
+ "mv": {
37
+ "overhead": ["O_AM_54_mv", "O_AM_148_mv"],
38
+ "underground": ["U_AL_150_mv", "U_AL_240_mv", "U_AL_288_mv"],
39
+ },
40
+ },
41
+ trafo_types=[
42
+ "FT_Standard_Standard_100kVA",
43
+ "FT_Standard_Standard_160kVA",
44
+ "FT_Standard_Standard_250kVA",
45
+ "FT_Standard_Standard_400kVA",
46
+ "FT_Standard_Standard_630kVA",
47
+ ],
48
+ # No `new_line` prices: a conductor added in parallel to a line is priced at the
49
+ # `line_upgrade` price of the type in place, like the replacement of a conductor
50
+ # by that type. A conductor of the type in place thus costs less than one of the
51
+ # next type, and the thermal upgrades, which take the cheaper of the two (see
52
+ # "Thermal Sizing" in the methodology), mostly add conductors in parallel. This
53
+ # assumption drives nearly every thermal decision of the study.
54
+ unit_costs={
55
+ "line_upgrade": {
56
+ "T_AL_50_lv": 40.0e3, # €/km
57
+ "T_AL_70_lv": 50.0e3, # €/km
58
+ "T_AL_150_lv": 60.0e3, # €/km
59
+ "U_AL_95_lv": 55.0e3, # €/km
60
+ "U_AL_150_lv": 60.0e3, # €/km
61
+ "U_AL_240_lv": 70.0e3, # €/km
62
+ "U_AL_288_lv": 80.0e3, # €/km
63
+ "O_AM_54_mv": 70.0e3, # €/km
64
+ "O_AM_148_mv": 90.0e3, # €/km
65
+ "U_AL_150_mv": 90.0e3, # €/km
66
+ "U_AL_240_mv": 100.0e3, # €/km
67
+ "U_AL_288_mv": 110.0e3, # €/km
68
+ },
69
+ "transformer_upgrade": {
70
+ "FT_Standard_Standard_100kVA": 5000.0,
71
+ "FT_Standard_Standard_160kVA": 8000.0,
72
+ "FT_Standard_Standard_250kVA": 10000.0,
73
+ "FT_Standard_Standard_400kVA": 15000.0,
74
+ "FT_Standard_Standard_630kVA": 20000.0,
75
+ # Types of the feeders outside the upgrade ladder, which can be given a
76
+ # unit in parallel. Prices on the line through those of 400 and 630 kVA,
77
+ # rounded: assumptions to review.
78
+ "FT_Standard_Standard_315kVA": 12000.0,
79
+ "FT_Standard_Standard_500kVA": 17000.0,
80
+ "FT_Standard_Standard_800kVA": 24000.0,
81
+ "FT_Standard_Standard_1000kVA": 28000.0,
82
+ "FT_Standard_Standard_2000kVA": 50000.0,
83
+ "FT_Standard_Standard_3150kVA": 75000.0,
84
+ },
85
+ "tap_change": 10.0, # € by tap change
86
+ "load_shedding": 10000.0, # €/MW
87
+ },
88
+ line_upgrade_max_iterations=500,
89
+ # 0.1 % of the nominal voltage at a violated bus, or what the bus exceeds its limit
90
+ # by if that is less: a step that brings less is not worth its works
91
+ line_upgrade_min_voltage_sensitivity=0.001,
92
+ flexibility_n_activation=5,
93
+ # The 3 passes that the former 10 per-type steps made
94
+ algorithm_max_iterations=3,
95
+ )
96
+
97
+ DICKERT_LV = CaseStudyConfig(
98
+ line_types={
99
+ "lv": {
100
+ "overhead": ["NFA2X 4x70", "NFA2X 4x95", "NFA2X 4x150"],
101
+ "underground": ["NAYY 4x50 SE", "NAYY 4x120 SE", "NAYY 4x150 SE"],
102
+ }
103
+ },
104
+ trafo_types=["0.25 MVA 20/0.4 kV", "0.4 MVA 20/0.4 kV", "0.63 MVA 20/0.4 kV"],
105
+ unit_costs={
106
+ "line_upgrade": {
107
+ "NFA2X 4x70": 50000.0, # €/km
108
+ "NFA2X 4x95": 55000.0, # €/km
109
+ "NFA2X 4x150": 60000.0, # €/km
110
+ "NAYY 4x50 SE": 70000.0, # €/km
111
+ "NAYY 4x120 SE": 70000.0, # €/km
112
+ "NAYY 4x150 SE": 80000.0, # €/km
113
+ },
114
+ "transformer_upgrade": {
115
+ "0.25 MVA 20/0.4 kV": 5000.0, # € per transformer
116
+ "0.4 MVA 20/0.4 kV": 8000.0, # € per transformer
117
+ "0.63 MVA 20/0.4 kV": 12000.0, # € per transformer
118
+ },
119
+ },
120
+ line_upgrade_max_iterations=100,
121
+ # The 3 passes that the former 10 per-type steps made
122
+ algorithm_max_iterations=3,
123
+ )
124
+
125
+ SIMBENCH = CaseStudyConfig(
126
+ line_types={
127
+ "lv": {
128
+ "overhead": [],
129
+ "underground": ["NAYY 4x150SE 0.6/1kV", "NAYY 4x240SE 0.6/1kV"],
130
+ }
131
+ },
132
+ trafo_types=[
133
+ "0.16 MVA 20/0.4 kV DOTE 160/20 SGB",
134
+ "0.25 MVA 20/0.4 kV Dyn5 ASEA",
135
+ "0.4 MVA 20/0.4 kV Dyn5 ASEA",
136
+ "0.63 MVA 20/0.4 kV Dyn5 ASEA",
137
+ ],
138
+ unit_costs={
139
+ "line_upgrade": {
140
+ "NAYY 4x150SE 0.6/1kV": 50000.0, # €/km
141
+ "NAYY 4x240SE 0.6/1kV": 55000.0, # €/km
142
+ },
143
+ "transformer_upgrade": {
144
+ "0.16 MVA 20/0.4 kV DOTE 160/20 SGB": 5000.0, # € per transformer
145
+ "0.25 MVA 20/0.4 kV Dyn5 ASEA": 8000.0, # € per transformer
146
+ "0.4 MVA 20/0.4 kV Dyn5 ASEA": 12000.0, # € per transformer
147
+ "0.63 MVA 20/0.4 kV Dyn5 ASEA": 18000.0, # € per transformer
148
+ },
149
+ "tap_change": 10.0,
150
+ "load_shedding": 10000.0, # €/MW, same price as MV_LV_FEEDER
151
+ },
152
+ line_upgrade_max_iterations=100,
153
+ # 0.01 % of the nominal voltage: only stops the steps that bring next to nothing
154
+ line_upgrade_min_voltage_sensitivity=0.0001,
155
+ flexibility_n_activation=3,
156
+ # The 25 passes that the former 100 per-type steps made
157
+ algorithm_max_iterations=25,
158
+ )
@@ -0,0 +1,109 @@
1
+ import logging
2
+
3
+ import pandapower as pp
4
+ import pandapower.networks as pn
5
+ import pandapower.plotting as pp_plot
6
+
7
+ from gridforge.case_study.config import DICKERT_LV
8
+ from gridforge.core.cost_model import CostModel
9
+ from gridforge.core.grid_enhancement import (
10
+ EnhancementStrategyRegistry,
11
+ GridEnhancementAlgorithm,
12
+ )
13
+ from gridforge.engines.pandapower_engine import PandaPowerEngine
14
+ from gridforge.strategies.line_upgrade import LineUpgradeStrategy
15
+ from gridforge.strategies.transformer_upgrade import TransformerUpgradeStrategy
16
+ from gridforge.utils.logging import setup_logging
17
+
18
+ setup_logging(logging.INFO)
19
+
20
+
21
+ def import_network():
22
+ net = pn.create_dickert_lv_network(
23
+ feeders_range="long", linetype="C&OHL", customer="multiple", case="average"
24
+ )
25
+ # Creating missing STD types NFA2X 4x70
26
+ ol_95 = {
27
+ "c_nf_per_km": 12.8,
28
+ "r_ohm_per_km": 0.30,
29
+ "x_ohm_per_km": 0.075,
30
+ "max_i_ka": 0.30,
31
+ "g_us_per_km": 0.0,
32
+ "type": "ol",
33
+ }
34
+ ol_150 = {
35
+ "c_nf_per_km": 13.0,
36
+ "r_ohm_per_km": 0.20,
37
+ "x_ohm_per_km": 0.08,
38
+ "max_i_ka": 0.42,
39
+ "g_us_per_km": 0.0,
40
+ "type": "ol",
41
+ }
42
+ pp.create_std_type(net, ol_95, name="NFA2X 4x95")
43
+ pp.create_std_type(net, ol_150, name="NFA2X 4x150")
44
+
45
+ # We add generic coordinates to the buses for visualization purposes
46
+ pp_plot.create_generic_coordinates(net, respect_switches=True)
47
+
48
+ # Create element name for the engine to work properly
49
+ for bus in net.bus.index:
50
+ net.bus.at[bus, "name"] = f"Bus {bus}"
51
+ for line in net.line.index:
52
+ net.line.at[line, "name"] = f"Line {line}"
53
+ for trafo in net.trafo.index:
54
+ net.trafo.at[trafo, "name"] = f"Trafo {trafo}"
55
+ for load in net.load.index:
56
+ net.load.at[load, "name"] = f"Load {load}"
57
+
58
+ return net
59
+
60
+
61
+ def create_strategy_registry():
62
+ """Create the strategy registry of the case study."""
63
+ registry = EnhancementStrategyRegistry()
64
+
65
+ # Add voltage strategies
66
+ # tap_changer_strategy = TapChangeStrategy()
67
+ # registry.register_strategy(tap_changer_strategy)
68
+
69
+ # Add loading strategies
70
+ line_upgrade_strategy = LineUpgradeStrategy(
71
+ line_types=DICKERT_LV.line_types,
72
+ max_iterations=DICKERT_LV.line_upgrade_max_iterations,
73
+ )
74
+ registry.register_strategy(line_upgrade_strategy)
75
+
76
+ # Add custom transformer upgrade strategy
77
+ transformer_upgrade_strategy = TransformerUpgradeStrategy(DICKERT_LV.trafo_types)
78
+ registry.register_strategy(transformer_upgrade_strategy)
79
+
80
+ return registry
81
+
82
+
83
+ def create_cost_model():
84
+ """Create the cost model of the case study."""
85
+ return CostModel(DICKERT_LV.unit_costs)
86
+
87
+
88
+ if __name__ == "__main__":
89
+ net = import_network()
90
+
91
+ engine = PandaPowerEngine()
92
+ engine.network = net
93
+ engine.run_power_flow()
94
+ engine.check_violations()
95
+
96
+ engine.plot_network_violations(show_ids=True)
97
+
98
+ cost_model = create_cost_model()
99
+ registry = create_strategy_registry()
100
+
101
+ ge = GridEnhancementAlgorithm(
102
+ power_flow_engine=engine,
103
+ strategy_registry=registry,
104
+ cost_model=cost_model,
105
+ max_iterations=DICKERT_LV.algorithm_max_iterations,
106
+ )
107
+ success, results = ge.run()
108
+
109
+ engine.plot_network_violations(show_ids=True, enhancement_results=results)