powergridforge 1.1.3__tar.gz

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 (54) hide show
  1. powergridforge-1.1.3/.github/workflows/docs.yml +25 -0
  2. powergridforge-1.1.3/.gitignore +20 -0
  3. powergridforge-1.1.3/LICENSE +21 -0
  4. powergridforge-1.1.3/PKG-INFO +214 -0
  5. powergridforge-1.1.3/data/.placeholder +0 -0
  6. powergridforge-1.1.3/docs/bus-data-assignment.md +187 -0
  7. powergridforge-1.1.3/docs/configuration.md +614 -0
  8. powergridforge-1.1.3/docs/copyright.md +33 -0
  9. powergridforge-1.1.3/docs/examples.md +54 -0
  10. powergridforge-1.1.3/docs/github-pages.md +46 -0
  11. powergridforge-1.1.3/docs/grid-data-access.md +451 -0
  12. powergridforge-1.1.3/docs/image/gridforge.png +0 -0
  13. powergridforge-1.1.3/docs/image/gridforge_workflow.png +0 -0
  14. powergridforge-1.1.3/docs/image/visual-app/assets-sheets.png +0 -0
  15. powergridforge-1.1.3/docs/image/visual-app/case-preview.png +0 -0
  16. powergridforge-1.1.3/docs/image/visual-app/generated-preview.png +0 -0
  17. powergridforge-1.1.3/docs/image/visual-app/overview.png +0 -0
  18. powergridforge-1.1.3/docs/image/visual-app/topology-preview.png +0 -0
  19. powergridforge-1.1.3/docs/image/visual-app/yaml-export.png +0 -0
  20. powergridforge-1.1.3/docs/index.md +74 -0
  21. powergridforge-1.1.3/docs/pypower-case.md +19 -0
  22. powergridforge-1.1.3/docs/tx123bt.md +160 -0
  23. powergridforge-1.1.3/docs/visual-app.md +147 -0
  24. powergridforge-1.1.3/docs/workflow.md +192 -0
  25. powergridforge-1.1.3/examples/14bus_uc/14bus_config.xlsx +0 -0
  26. powergridforge-1.1.3/examples/14bus_uc/14bus_config.yaml +287 -0
  27. powergridforge-1.1.3/examples/14bus_uc/14bus_data_assignment.yaml +24 -0
  28. powergridforge-1.1.3/examples/14bus_uc/14bus_example.py +445 -0
  29. powergridforge-1.1.3/examples/14bus_uc/14bus_uc.ipynb +1343 -0
  30. powergridforge-1.1.3/examples/14bus_uc/14bus_utility_report.py +181 -0
  31. powergridforge-1.1.3/examples/readme.md +55 -0
  32. powergridforge-1.1.3/gridforge/__init__.py +8 -0
  33. powergridforge-1.1.3/gridforge/app_cli.py +21 -0
  34. powergridforge-1.1.3/gridforge/config_app.py +1944 -0
  35. powergridforge-1.1.3/gridforge/config_io.py +102 -0
  36. powergridforge-1.1.3/gridforge/construct.py +1065 -0
  37. powergridforge-1.1.3/gridforge/data.py +430 -0
  38. powergridforge-1.1.3/gridforge/matpower_io.py +473 -0
  39. powergridforge-1.1.3/gridforge/numpy_compat.py +35 -0
  40. powergridforge-1.1.3/gridforge/opt.py +583 -0
  41. powergridforge-1.1.3/gridforge/plot.py +324 -0
  42. powergridforge-1.1.3/gridforge/reference_data/__init__.py +13 -0
  43. powergridforge-1.1.3/gridforge/reference_data/tx123bt.py +456 -0
  44. powergridforge-1.1.3/mkdocs.yml +31 -0
  45. powergridforge-1.1.3/powergridforge.egg-info/PKG-INFO +214 -0
  46. powergridforge-1.1.3/powergridforge.egg-info/SOURCES.txt +52 -0
  47. powergridforge-1.1.3/powergridforge.egg-info/dependency_links.txt +1 -0
  48. powergridforge-1.1.3/powergridforge.egg-info/entry_points.txt +2 -0
  49. powergridforge-1.1.3/powergridforge.egg-info/requires.txt +30 -0
  50. powergridforge-1.1.3/powergridforge.egg-info/top_level.txt +1 -0
  51. powergridforge-1.1.3/pyproject.toml +39 -0
  52. powergridforge-1.1.3/readme.md +178 -0
  53. powergridforge-1.1.3/scripts/generate_tx123bt_bus_data.sh +93 -0
  54. powergridforge-1.1.3/setup.cfg +4 -0
@@ -0,0 +1,25 @@
1
+ name: Publish Docs
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ paths:
8
+ - docs/**
9
+ - mkdocs.yml
10
+ - .github/workflows/docs.yml
11
+ workflow_dispatch:
12
+
13
+ permissions:
14
+ contents: write
15
+
16
+ jobs:
17
+ deploy:
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - uses: actions/setup-python@v5
22
+ with:
23
+ python-version: "3.11"
24
+ - run: pip install mkdocs mkdocs-material pymdown-extensions
25
+ - run: mkdocs gh-deploy --force
@@ -0,0 +1,20 @@
1
+ __pycache__/
2
+ *.py[codz]
3
+ *$py.class
4
+ *.pyc
5
+ .ipynb_checkpoints/
6
+ .pytest_cache/
7
+ .venv/
8
+ build/
9
+ site/
10
+ # *.xlsx
11
+ 14bus_data/
12
+ data/bus_data/
13
+ data/raw_data.zip
14
+ data/Data_public/
15
+ *.egg-info/
16
+ examples/14bus_uc/*.png
17
+ examples/14bus_uc/*.html
18
+ examples/14bus_uc/14bus_data_assignment_resolved.yaml
19
+ .DS_Store
20
+ .codex
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Wangkun Xu and GridForge contributors
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,214 @@
1
+ Metadata-Version: 2.4
2
+ Name: powergridforge
3
+ Version: 1.1.3
4
+ Summary: Power system configuration and optimization toolkit.
5
+ Author: Wangkun Xu
6
+ License-Expression: MIT
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: numpy>=1.23
11
+ Requires-Dist: pandas>=1.5
12
+ Requires-Dist: pyyaml>=6
13
+ Requires-Dist: tqdm>=4.60
14
+ Requires-Dist: openpyxl>=3.1
15
+ Requires-Dist: cvxpy>=1.3
16
+ Requires-Dist: PYPOWER>=5.1
17
+ Requires-Dist: cvxpy-summary>=0.1.2
18
+ Provides-Extra: gurobi
19
+ Requires-Dist: gurobipy; extra == "gurobi"
20
+ Provides-Extra: viz
21
+ Requires-Dist: networkx>=2.8; extra == "viz"
22
+ Requires-Dist: matplotlib>=3.6; extra == "viz"
23
+ Requires-Dist: plotly>=5; extra == "viz"
24
+ Provides-Extra: app
25
+ Requires-Dist: streamlit>=1.28; extra == "app"
26
+ Provides-Extra: docs
27
+ Requires-Dist: mkdocs>=1.5; extra == "docs"
28
+ Requires-Dist: mkdocs-material>=9; extra == "docs"
29
+ Requires-Dist: pymdown-extensions>=10; extra == "docs"
30
+ Provides-Extra: full
31
+ Requires-Dist: streamlit>=1.28; extra == "full"
32
+ Requires-Dist: networkx>=2.8; extra == "full"
33
+ Requires-Dist: matplotlib>=3.6; extra == "full"
34
+ Requires-Dist: plotly>=5; extra == "full"
35
+ Dynamic: license-file
36
+
37
+ # GridForge
38
+
39
+ <p align="center">
40
+ <img src="docs/image/gridforge.png" alt="GridForge Logo" width="250"/>
41
+ </p>
42
+
43
+ **GridForge** helps build optimization-ready power-system cases from standard
44
+ PYPOWER/MATPOWER grids. It lets you describe grid edits in YAML, generate a
45
+ structured Excel workbook, attach bus-level time-series data, and load the
46
+ result into Python for your own optimization model.
47
+
48
+ GridForge is useful when a standard test case is not enough: for example, when
49
+ you need custom assets such as load, solar, wind, or storage, time-series data
50
+ attached to selected buses, and convenient access to the final case in CVXPY.
51
+
52
+ Read the full documentation at
53
+ [xuwkk.github.io/gridforge](https://xuwkk.github.io/gridforge/).
54
+
55
+ ## Workflow
56
+
57
+ ```text
58
+ base PYPOWER/MATPOWER case
59
+ -> grid configuration YAML
60
+ -> generated Excel workbook
61
+ -> bus-data assignment YAML
62
+ -> bus_<BUS_IDX>.csv files
63
+ -> Grid(...) and Data(...) classes for efficient access to the case and data
64
+ -> user-defined optimization model
65
+ ```
66
+
67
+ The grid configuration YAML can be written manually or created with the visual
68
+ app. The bus-data assignment step is separate because it depends on the
69
+ generated `BUS_IDX` values in the workbook.
70
+
71
+ ## Installation
72
+
73
+ Install the latest release from PyPI:
74
+
75
+ ```bash
76
+ pip install powergridforge
77
+ ```
78
+
79
+ To run the examples and edit the docs, clone the repository:
80
+
81
+ ```bash
82
+ git clone https://github.com/xuwkk/gridforge.git
83
+ cd gridforge
84
+ python -m venv .venv
85
+ source .venv/bin/activate
86
+ pip install -e ".[full]"
87
+ ```
88
+
89
+ ## What You Need First
90
+
91
+ GridForge does not invent the grid design automatically. Before constructing a
92
+ case, prepare:
93
+
94
+ - a **grid configuration YAML** that selects a base case and describes static grid edits, see [configuration.md](docs/configuration.md) for details.
95
+ - a **bus-data assignment YAML** that declares which time-series signals should be mapped to generated buses, see [bus-data-assignment.md](docs/bus-data-assignment.md) for details.
96
+ - source CSV files if you want to materialize time-series data.
97
+
98
+ For a first run, use the prepared 14-bus example in a source checkout of this
99
+ repository.
100
+
101
+ ## 14-Bus Example
102
+
103
+ The worked unit-commitment example is in
104
+ [`examples/14bus_uc/`](examples/14bus_uc/).
105
+
106
+ Important files:
107
+
108
+ - [`14bus_config.yaml`](examples/14bus_uc/14bus_config.yaml): grid
109
+ configuration rules.
110
+ - [`14bus_config.xlsx`](examples/14bus_uc/14bus_config.xlsx): generated static
111
+ workbook.
112
+ - [`14bus_data_assignment.yaml`](examples/14bus_uc/14bus_data_assignment.yaml):
113
+ bus-data signal template used to generate bus assignments.
114
+ - [`14bus_data/`](examples/14bus_uc/14bus_data/): generated
115
+ `bus_<BUS_IDX>.csv` files.
116
+ - [`14bus_example.py`](examples/14bus_uc/14bus_example.py): runnable
117
+ end-to-end example.
118
+ - [`14bus_uc.ipynb`](examples/14bus_uc/14bus_uc.ipynb): interactive notebook
119
+ for inspecting the case, data, topology, and UC model setup.
120
+
121
+ Run the example from the repository root:
122
+
123
+ ```bash
124
+ python examples/14bus_uc/14bus_example.py
125
+ ```
126
+
127
+ Or open the notebook:
128
+
129
+ ```bash
130
+ jupyter lab examples/14bus_uc/14bus_uc.ipynb
131
+ ```
132
+
133
+ The same workflow can be called from Python:
134
+
135
+ ```python
136
+ from gridforge.construct import construct_grid_config
137
+ from gridforge.data import (
138
+ load_bus_data_assignment,
139
+ prepare_bus_data,
140
+ )
141
+ from gridforge.opt import Grid, Data
142
+
143
+ config_yaml = "examples/14bus_uc/14bus_config.yaml"
144
+ config_xlsx = "examples/14bus_uc/14bus_config.xlsx"
145
+ assignment_yaml = "examples/14bus_uc/14bus_data_assignment.yaml"
146
+ resolved_assignment_yaml = "examples/14bus_uc/14bus_data_assignment_resolved.yaml"
147
+ data_dir = "examples/14bus_uc/14bus_data"
148
+ source_data_dir = "data/bus_data"
149
+
150
+ construct_grid_config(config_yaml, config_xlsx, random_seed=404)
151
+
152
+ assignment_template = load_bus_data_assignment(assignment_yaml)
153
+ assignment, _ = prepare_bus_data(
154
+ grid_xlsx_path=config_xlsx,
155
+ source_data_dir=source_data_dir,
156
+ signals=assignment_template["signals"],
157
+ output_data_dir=data_dir,
158
+ resolved_assignment_path=resolved_assignment_yaml,
159
+ random_seed=404,
160
+ )
161
+
162
+ grid = Grid(config_xlsx, verbose=0)
163
+ data = Data(
164
+ grid_xlsx_path=config_xlsx,
165
+ data_dir=data_dir,
166
+ sheet_names=["load", "solar", "wind"],
167
+ )
168
+
169
+ print(grid.gen.pmax)
170
+ print(grid.branch.ptdf.shape)
171
+ print(grid.load.Cbus.shape)
172
+ print(data.get_series("load").shape)
173
+ ```
174
+
175
+ ## Visual Config App
176
+
177
+ The visual app helps create and inspect the grid configuration YAML used in the
178
+ first stage.
179
+
180
+ <p align="center">
181
+ <img src="docs/image/visual-app/overview.png" alt="GridForge Visual Config App" width="850"/>
182
+ </p>
183
+
184
+ Launch it after installing the app dependencies, for example with
185
+ `pip install -e ".[full]"` from a source checkout:
186
+
187
+ ```bash
188
+ gridforge-app
189
+ ```
190
+
191
+ From a local checkout:
192
+
193
+ ```bash
194
+ streamlit run gridforge/config_app.py
195
+ ```
196
+
197
+ ## Documentation
198
+
199
+ The published documentation is available at
200
+ [xuwkk.github.io/gridforge](https://xuwkk.github.io/gridforge/).
201
+
202
+ - [Workflow](https://xuwkk.github.io/gridforge/workflow/): complete YAML -> Excel -> bus data -> Python
203
+ pipeline.
204
+ - [Visual config app](https://xuwkk.github.io/gridforge/visual-app/): Streamlit builder for grid YAML.
205
+ - [Configuration reference](https://xuwkk.github.io/gridforge/configuration/): GridForge YAML schema.
206
+ - [Bus-data assignment](https://xuwkk.github.io/gridforge/bus-data-assignment/): assign source CSV
207
+ profiles to generated buses.
208
+ - [Grid and Data access](https://xuwkk.github.io/gridforge/grid-data-access/): entries exposed by
209
+ `Grid(...)` and `Data(...)`.
210
+ - [TX-123BT workflow](https://xuwkk.github.io/gridforge/tx123bt/): optional public source-data
211
+ preparation.
212
+ - [Examples](https://xuwkk.github.io/gridforge/examples/): runnable examples included in this repository.
213
+
214
+ The source Markdown files for the site live in [`docs/`](docs/).
File without changes
@@ -0,0 +1,187 @@
1
+ # Bus Data Assignment
2
+
3
+ > The visual app currently helps build the static grid YAML. Bus-data assignment
4
+ > is handled by this YAML/Python workflow. TX-123BT is one optional source-data
5
+ > example; see [tx123bt.md](tx123bt.md).
6
+
7
+ GridForge separates static grid construction from time-series assignment.
8
+
9
+ The grid workbook decides which assets exist and which generated buses they are
10
+ attached to. A bus-data assignment file then decides which source CSV profile is
11
+ used for each generated bus that needs data.
12
+
13
+ This step happens after the Excel workbook has been generated. The assignment
14
+ tools read the workbook to discover which generated `BUS_IDX` values need data.
15
+ The output CSV files can contain more than asset profiles. For example, a bus
16
+ CSV may also contain calendar, weather, or other contextual columns.
17
+
18
+ ## Assignment File
19
+
20
+ An assignment template has three parts:
21
+
22
+ - where to find candidate source CSV files as `source_data_dir`,
23
+ - which signals require time-series columns as `signals`,
24
+ - optionally, where GridForge should write case-specific bus CSV files as
25
+ `output_data_dir`.
26
+
27
+ ```yaml
28
+ source_data_dir: data/bus_data
29
+ output_data_dir: examples/14bus_uc/14bus_data
30
+ signals:
31
+ load:
32
+ workbook_sheet: load # the data is related to the load sheet in the workbook
33
+ source_column: load # the column name in the source CSV file that contains the time-series data for the load
34
+ output_column: load # the column name in the output CSV file that contains the time-series data for the load
35
+ scale_to:
36
+ column: PMAX
37
+ method: max
38
+ solar:
39
+ workbook_sheet: solar
40
+ source_column: solar
41
+ output_column: solar
42
+ scale_to:
43
+ column: PMAX
44
+ method: max
45
+ wind:
46
+ workbook_sheet: wind
47
+ source_column: wind
48
+ output_column: wind
49
+ scale_to:
50
+ column: PMAX
51
+ method: max
52
+ ```
53
+
54
+ This template is not yet materializable because it does not say which generated
55
+ bus should use which source file. Use `prepare_bus_data(...)` after the workbook
56
+ exists to produce a resolved assignment with a `buses` mapping and materialize
57
+ the case-specific bus CSVs.
58
+
59
+ ## What The User Provides
60
+
61
+ The user controls:
62
+
63
+ - `source_data_dir`: directory of candidate source CSV files. Each file is a
64
+ time-series table with shape `(T, n_features)`, where rows are time steps and
65
+ columns are signals or context features such as `load`, `solar`, `wind`,
66
+ weather, or calendar fields.
67
+ - `output_data_dir`: directory where GridForge writes the case-specific
68
+ `bus_<BUS_IDX>.csv` files.
69
+ - `signals`: named time-series signals. Each signal states which workbook sheet
70
+ supplies required `BUS_IDX` values, which source CSV column to read, and which
71
+ output CSV column to write.
72
+ - `buses`: optional mapping from generated GridForge `BUS_IDX` values to source
73
+ CSV filenames. In the common workflow this is generated by `prepare_bus_data(...)`
74
+ after the workbook exists. See [Prepare Bus Data](#prepare-bus-data) for more details.
75
+
76
+ ## How Required Buses Are Found
77
+
78
+ GridForge does not assume that every custom sheet needs time-series data. Only
79
+ sheets referenced by `signals.<name>.workbook_sheet` are data-backed.
80
+
81
+ For each signal, GridForge reads `BUS_IDX` from the referenced workbook sheet.
82
+ The union of those bus IDs becomes the set of buses that need source CSV
83
+ assignments.
84
+
85
+ ## Scaling
86
+
87
+ For a signal like:
88
+
89
+ ```yaml
90
+ load:
91
+ workbook_sheet: load
92
+ source_column: load
93
+ output_column: load
94
+ scale_to:
95
+ column: PMAX
96
+ method: max
97
+ ```
98
+
99
+ GridForge:
100
+
101
+ 1. reads the assigned source CSV's `load` column,
102
+ 2. finds the generated bus's `load.PMAX` value in the workbook,
103
+ 3. scales the source profile so `max(load)` equals `PMAX`,
104
+ 4. writes the scaled profile into the case-specific output CSV.
105
+
106
+ The current scaling method is `max`. This matches the peak of the source profile
107
+ to a static workbook value such as peak demand or installed capacity.
108
+
109
+ > More options will be supported in the future.
110
+
111
+ `scale_to` uses the signal's `workbook_sheet` by default.
112
+
113
+ ## Prepare Bus Data
114
+
115
+ The user can use `prepare_bus_data(...)` to generate a resolved assignment,
116
+ optionally save it, and write the case-specific `bus_<BUS_IDX>.csv` files. A
117
+ complete example is shown below:
118
+
119
+ ```python
120
+ from gridforge.data import prepare_bus_data
121
+
122
+ # Assignment config without buses mapping
123
+ signals = {
124
+ "load": {
125
+ "workbook_sheet": "load",
126
+ "source_column": "load",
127
+ "output_column": "load",
128
+ "scale_to": {"column": "PMAX", "method": "max"},
129
+ },
130
+ "solar": {
131
+ "workbook_sheet": "solar",
132
+ "source_column": "solar",
133
+ "output_column": "solar",
134
+ "scale_to": {"column": "PMAX", "method": "max"},
135
+ },
136
+ "wind": {
137
+ "workbook_sheet": "wind",
138
+ "source_column": "wind",
139
+ "output_column": "wind",
140
+ "scale_to": {"column": "PMAX", "method": "max"},
141
+ },
142
+ }
143
+
144
+ # GridForge suggests a mapping and materializes the required bus CSVs.
145
+ assignment, materialized = prepare_bus_data(
146
+ grid_xlsx_path="examples/14bus_uc/14bus_config.xlsx",
147
+ source_data_dir="data/bus_data",
148
+ signals=signals,
149
+ output_data_dir="examples/14bus_uc/14bus_data",
150
+ resolved_assignment_path="examples/14bus_uc/14bus_data_assignment_resolved.yaml",
151
+ random_seed=404,
152
+ )
153
+ ```
154
+
155
+ ## Materialize A Saved Assignment
156
+
157
+ If you want to inspect or edit a resolved assignment before writing bus CSVs, use
158
+ the lower-level `suggest_bus_data_assignment(...)` and
159
+ `materialize_bus_data_assignment(...)` helpers separately.
160
+
161
+ ```python
162
+ from gridforge.data import materialize_bus_data_assignment
163
+
164
+ materialize_bus_data_assignment(
165
+ grid_xlsx_path="examples/14bus_uc/14bus_config.xlsx",
166
+ assignment_path="examples/14bus_uc/14bus_data_assignment_resolved.yaml",
167
+ output_data_dir="examples/14bus_uc/14bus_data",
168
+ )
169
+ ```
170
+
171
+ This reads the assigned source files, _scales_ requested columns when configured,
172
+ and writes files such as:
173
+
174
+ ```text
175
+ examples/14bus_uc/14bus_data/bus_2.csv
176
+ examples/14bus_uc/14bus_data/bus_3.csv
177
+ examples/14bus_uc/14bus_data/bus_8.csv
178
+ ```
179
+
180
+ The output filenames use generated GridForge bus IDs. The source files can come
181
+ from any CSV pool that contains the required columns.
182
+
183
+ ## Next Step
184
+
185
+ After materialization, load the generated `bus_<BUS_IDX>.csv` files with
186
+ `Data(...)`. For sheet-backed profile matrices and contextual CSV columns, see
187
+ [Grid And Data Access](grid-data-access.md#5-time-series-data-data).