pf-tool 0.2.1__tar.gz → 0.2.2__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.
- pf_tool-0.2.2/PKG-INFO +115 -0
- pf_tool-0.2.2/README.md +102 -0
- {pf_tool-0.2.1 → pf_tool-0.2.2}/pyproject.toml +9 -12
- pf_tool-0.2.2/src/pf_tool/__init__.py +21 -0
- {pf_tool-0.2.1 → pf_tool-0.2.2/src/pf_tool}/exporter.py +9 -7
- pf_tool-0.2.2/src/pf_tool/models/__init__.py +7 -0
- {pf_tool-0.2.1 → pf_tool-0.2.2/src/pf_tool}/models/case.py +6 -6
- {pf_tool-0.2.1 → pf_tool-0.2.2/src/pf_tool}/models/csc.py +1 -1
- {pf_tool-0.2.1 → pf_tool-0.2.2/src/pf_tool}/models/hvdc_lcc.py +1 -1
- {pf_tool-0.2.1 → pf_tool-0.2.2/src/pf_tool}/models/network_reduction.py +4 -4
- {pf_tool-0.2.1 → pf_tool-0.2.2/src/pf_tool}/models/shunt.py +1 -1
- {pf_tool-0.2.1 → pf_tool-0.2.2/src/pf_tool}/models/svc.py +2 -2
- {pf_tool-0.2.1 → pf_tool-0.2.2/src/pf_tool}/models/transformer.py +4 -4
- {pf_tool-0.2.1 → pf_tool-0.2.2/src/pf_tool}/newton_raphson.py +13 -18
- {pf_tool-0.2.1 → pf_tool-0.2.2/src/pf_tool}/optimization.py +31 -20
- {pf_tool-0.2.1 → pf_tool-0.2.2/src/pf_tool}/utils/network.py +2 -2
- {pf_tool-0.2.1 → pf_tool-0.2.2/src/pf_tool}/utils/utils.py +9 -9
- pf_tool-0.2.2/src/pf_tool.egg-info/PKG-INFO +115 -0
- pf_tool-0.2.2/src/pf_tool.egg-info/SOURCES.txt +30 -0
- pf_tool-0.2.2/src/pf_tool.egg-info/top_level.txt +1 -0
- {pf_tool-0.2.1 → pf_tool-0.2.2}/tests/test_exporter.py +5 -5
- {pf_tool-0.2.1 → pf_tool-0.2.2}/tests/test_newton_raphson.py +12 -12
- {pf_tool-0.2.1 → pf_tool-0.2.2}/tests/test_optimization.py +15 -5
- pf_tool-0.2.1/PKG-INFO +0 -69
- pf_tool-0.2.1/README.md +0 -56
- pf_tool-0.2.1/models/__init__.py +0 -7
- pf_tool-0.2.1/pf_tool.egg-info/PKG-INFO +0 -69
- pf_tool-0.2.1/pf_tool.egg-info/SOURCES.txt +0 -29
- pf_tool-0.2.1/pf_tool.egg-info/top_level.txt +0 -5
- {pf_tool-0.2.1 → pf_tool-0.2.2}/LICENSE.txt +0 -0
- {pf_tool-0.2.1 → pf_tool-0.2.2}/setup.cfg +0 -0
- {pf_tool-0.2.1 → pf_tool-0.2.2/src/pf_tool}/models/branch.py +0 -0
- {pf_tool-0.2.1 → pf_tool-0.2.2/src/pf_tool}/models/bus.py +0 -0
- {pf_tool-0.2.1 → pf_tool-0.2.2/src/pf_tool}/models/generator.py +0 -0
- {pf_tool-0.2.1 → pf_tool-0.2.2/src/pf_tool}/utils/__init__.py +0 -0
- {pf_tool-0.2.1 → pf_tool-0.2.2/src/pf_tool}/utils/dat_parser.py +0 -0
- {pf_tool-0.2.1 → pf_tool-0.2.2/src}/pf_tool.egg-info/dependency_links.txt +0 -0
- {pf_tool-0.2.1 → pf_tool-0.2.2/src}/pf_tool.egg-info/requires.txt +0 -0
pf_tool-0.2.2/PKG-INFO
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pf-tool
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: AC/DC power flow for the Brazilian Interconnected Power System (BIPS): Newton-Raphson and optimization (Pyomo/Ipopt) solvers for ANAREDE .dat cases.
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE.txt
|
|
8
|
+
Requires-Dist: numpy>=1.24
|
|
9
|
+
Requires-Dist: openpyxl>=3.1
|
|
10
|
+
Requires-Dist: pyomo>=6.8
|
|
11
|
+
Requires-Dist: scipy>=1.10
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
<h1 align="center">pf-tool</h1>
|
|
15
|
+
|
|
16
|
+
<p align="center"><em>AC/DC power flow for the Brazilian Interconnected Power System (BIPS).</em></p>
|
|
17
|
+
|
|
18
|
+
<p align="center">
|
|
19
|
+
<a href="https://github.com/mcllerena/pf-tool/actions/workflows/ci.yaml"><img src="https://github.com/mcllerena/pf-tool/actions/workflows/ci.yaml/badge.svg" alt="CI"></a>
|
|
20
|
+
<a href="https://pypi.org/project/pf-tool/"><img src="https://img.shields.io/pypi/v/pf-tool?label=PyPI&color=0079c2&logo=pypi" alt="PyPI"></a>
|
|
21
|
+
<a href="https://mcllerena.github.io/pf-tool/"><img src="https://img.shields.io/badge/docs-guides-0079c2?style=flat-square" alt="Docs"></a>
|
|
22
|
+
<a href="https://github.com/mcllerena/pf-tool/blob/main/pyproject.toml"><img src="https://img.shields.io/badge/Python-3.12+-3776ab?logo=python&logoColor=white" alt="Python 3.12+"></a>
|
|
23
|
+
<a href="https://docs.astral.sh/uv/"><img src="https://img.shields.io/badge/managed%20with-uv-6f42c1" alt="Managed with uv"></a>
|
|
24
|
+
<a href="https://github.com/mcllerena/pf-tool/blob/main/LICENSE.txt"><img src="https://img.shields.io/badge/license-BSD--3--Clause-blue.svg" alt="BSD 3-Clause"></a>
|
|
25
|
+
</p>
|
|
26
|
+
|
|
27
|
+
`pf-tool` solves ANAREDE-style `.dat` cases of the BIPS, about 12,600 buses
|
|
28
|
+
each, with a sparse Newton-Raphson solver or an optimization-based AC power
|
|
29
|
+
flow (Pyomo NLP solved with Ipopt), and exports every solved component to an
|
|
30
|
+
Excel workbook.
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
### Install
|
|
35
|
+
|
|
36
|
+
Use Python 3.12 or newer:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
python -m pip install pf-tool
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Ipopt
|
|
43
|
+
|
|
44
|
+
`OptimizationPowerFlow` solves its NLP with
|
|
45
|
+
[Ipopt](https://coin-or.github.io/Ipopt/). Download a prebuilt binary from the
|
|
46
|
+
[Ipopt releases](https://github.com/coin-or/Ipopt/releases) (or run
|
|
47
|
+
`conda install -c conda-forge ipopt`), then either add its `bin` folder to `PATH`:
|
|
48
|
+
|
|
49
|
+
```powershell
|
|
50
|
+
# Windows (PowerShell), current session; use System Properties > Environment
|
|
51
|
+
# Variables to make it permanent
|
|
52
|
+
$env:Path += ";C:\ipopt\bin"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Linux/macOS; add the line to ~/.bashrc or ~/.zshrc to make it permanent
|
|
57
|
+
export PATH="$PATH:/opt/ipopt/bin"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Check it with `ipopt --version`. Or skip `PATH` and pass the executable directly:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
nlp = OptimizationPowerFlow(
|
|
64
|
+
"CASO01-FLOW.dat", ipopt_executable="path/to/solver", warm_start=True, print_iterations=True
|
|
65
|
+
).solve()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`NewtonRaphsonPowerFlow` does not need Ipopt.
|
|
69
|
+
|
|
70
|
+
### Solve a case
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from pf_tool import ExportSolution, NewtonRaphsonPowerFlow, OptimizationPowerFlow
|
|
74
|
+
|
|
75
|
+
solver = NewtonRaphsonPowerFlow("CASO01-FLOW.dat")
|
|
76
|
+
result = solver.solve()
|
|
77
|
+
print(result.converged, result.iterations, result.max_mismatch)
|
|
78
|
+
|
|
79
|
+
ExportSolution(solver, output_path="results/CASO01-FLOW-nr.xlsx")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The eleven sample cases are in
|
|
83
|
+
[`tests/data/`](https://github.com/mcllerena/pf-tool/tree/main/tests/data), and
|
|
84
|
+
runnable scripts are in
|
|
85
|
+
[`examples/`](https://github.com/mcllerena/pf-tool/tree/main/examples).
|
|
86
|
+
|
|
87
|
+
## Documentation
|
|
88
|
+
|
|
89
|
+
- [Getting started](https://mcllerena.github.io/pf-tool/getting-started/): installation and first solve.
|
|
90
|
+
- [Solution pipeline](https://mcllerena.github.io/pf-tool/pipeline/): parsing, reduction, solve, and write-back.
|
|
91
|
+
- [Data file](https://mcllerena.github.io/pf-tool/data/blocks/): every `.dat` block and column.
|
|
92
|
+
- [Components](https://mcllerena.github.io/pf-tool/components/buses/): how each power-system component is modeled.
|
|
93
|
+
- [Newton-Raphson](https://mcllerena.github.io/pf-tool/methods/newton-raphson/) and [optimization](https://mcllerena.github.io/pf-tool/methods/optimization/): full formulations.
|
|
94
|
+
- [Results and benchmarks](https://mcllerena.github.io/pf-tool/methods/results/): convergence on all eleven cases.
|
|
95
|
+
- [Exporting results](https://mcllerena.github.io/pf-tool/export/): the Excel workbook layout.
|
|
96
|
+
- [Changelog](https://github.com/mcllerena/pf-tool/blob/main/CHANGELOG.md): release history.
|
|
97
|
+
|
|
98
|
+
## Development
|
|
99
|
+
|
|
100
|
+
From the repository root, install the development dependencies with `uv`:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
uv sync --locked --all-groups
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Then run the tests and the formatting and lint hooks:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
uv run pytest
|
|
110
|
+
uv run prek run --all-files
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
BSD-3-Clause. See [LICENSE.txt](https://github.com/mcllerena/pf-tool/blob/main/LICENSE.txt).
|
pf_tool-0.2.2/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
<h1 align="center">pf-tool</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center"><em>AC/DC power flow for the Brazilian Interconnected Power System (BIPS).</em></p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://github.com/mcllerena/pf-tool/actions/workflows/ci.yaml"><img src="https://github.com/mcllerena/pf-tool/actions/workflows/ci.yaml/badge.svg" alt="CI"></a>
|
|
7
|
+
<a href="https://pypi.org/project/pf-tool/"><img src="https://img.shields.io/pypi/v/pf-tool?label=PyPI&color=0079c2&logo=pypi" alt="PyPI"></a>
|
|
8
|
+
<a href="https://mcllerena.github.io/pf-tool/"><img src="https://img.shields.io/badge/docs-guides-0079c2?style=flat-square" alt="Docs"></a>
|
|
9
|
+
<a href="https://github.com/mcllerena/pf-tool/blob/main/pyproject.toml"><img src="https://img.shields.io/badge/Python-3.12+-3776ab?logo=python&logoColor=white" alt="Python 3.12+"></a>
|
|
10
|
+
<a href="https://docs.astral.sh/uv/"><img src="https://img.shields.io/badge/managed%20with-uv-6f42c1" alt="Managed with uv"></a>
|
|
11
|
+
<a href="https://github.com/mcllerena/pf-tool/blob/main/LICENSE.txt"><img src="https://img.shields.io/badge/license-BSD--3--Clause-blue.svg" alt="BSD 3-Clause"></a>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
`pf-tool` solves ANAREDE-style `.dat` cases of the BIPS, about 12,600 buses
|
|
15
|
+
each, with a sparse Newton-Raphson solver or an optimization-based AC power
|
|
16
|
+
flow (Pyomo NLP solved with Ipopt), and exports every solved component to an
|
|
17
|
+
Excel workbook.
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
### Install
|
|
22
|
+
|
|
23
|
+
Use Python 3.12 or newer:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
python -m pip install pf-tool
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Ipopt
|
|
30
|
+
|
|
31
|
+
`OptimizationPowerFlow` solves its NLP with
|
|
32
|
+
[Ipopt](https://coin-or.github.io/Ipopt/). Download a prebuilt binary from the
|
|
33
|
+
[Ipopt releases](https://github.com/coin-or/Ipopt/releases) (or run
|
|
34
|
+
`conda install -c conda-forge ipopt`), then either add its `bin` folder to `PATH`:
|
|
35
|
+
|
|
36
|
+
```powershell
|
|
37
|
+
# Windows (PowerShell), current session; use System Properties > Environment
|
|
38
|
+
# Variables to make it permanent
|
|
39
|
+
$env:Path += ";C:\ipopt\bin"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# Linux/macOS; add the line to ~/.bashrc or ~/.zshrc to make it permanent
|
|
44
|
+
export PATH="$PATH:/opt/ipopt/bin"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Check it with `ipopt --version`. Or skip `PATH` and pass the executable directly:
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
nlp = OptimizationPowerFlow(
|
|
51
|
+
"CASO01-FLOW.dat", ipopt_executable="path/to/solver", warm_start=True, print_iterations=True
|
|
52
|
+
).solve()
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`NewtonRaphsonPowerFlow` does not need Ipopt.
|
|
56
|
+
|
|
57
|
+
### Solve a case
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from pf_tool import ExportSolution, NewtonRaphsonPowerFlow, OptimizationPowerFlow
|
|
61
|
+
|
|
62
|
+
solver = NewtonRaphsonPowerFlow("CASO01-FLOW.dat")
|
|
63
|
+
result = solver.solve()
|
|
64
|
+
print(result.converged, result.iterations, result.max_mismatch)
|
|
65
|
+
|
|
66
|
+
ExportSolution(solver, output_path="results/CASO01-FLOW-nr.xlsx")
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The eleven sample cases are in
|
|
70
|
+
[`tests/data/`](https://github.com/mcllerena/pf-tool/tree/main/tests/data), and
|
|
71
|
+
runnable scripts are in
|
|
72
|
+
[`examples/`](https://github.com/mcllerena/pf-tool/tree/main/examples).
|
|
73
|
+
|
|
74
|
+
## Documentation
|
|
75
|
+
|
|
76
|
+
- [Getting started](https://mcllerena.github.io/pf-tool/getting-started/): installation and first solve.
|
|
77
|
+
- [Solution pipeline](https://mcllerena.github.io/pf-tool/pipeline/): parsing, reduction, solve, and write-back.
|
|
78
|
+
- [Data file](https://mcllerena.github.io/pf-tool/data/blocks/): every `.dat` block and column.
|
|
79
|
+
- [Components](https://mcllerena.github.io/pf-tool/components/buses/): how each power-system component is modeled.
|
|
80
|
+
- [Newton-Raphson](https://mcllerena.github.io/pf-tool/methods/newton-raphson/) and [optimization](https://mcllerena.github.io/pf-tool/methods/optimization/): full formulations.
|
|
81
|
+
- [Results and benchmarks](https://mcllerena.github.io/pf-tool/methods/results/): convergence on all eleven cases.
|
|
82
|
+
- [Exporting results](https://mcllerena.github.io/pf-tool/export/): the Excel workbook layout.
|
|
83
|
+
- [Changelog](https://github.com/mcllerena/pf-tool/blob/main/CHANGELOG.md): release history.
|
|
84
|
+
|
|
85
|
+
## Development
|
|
86
|
+
|
|
87
|
+
From the repository root, install the development dependencies with `uv`:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
uv sync --locked --all-groups
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Then run the tests and the formatting and lint hooks:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
uv run pytest
|
|
97
|
+
uv run prek run --all-files
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
BSD-3-Clause. See [LICENSE.txt](https://github.com/mcllerena/pf-tool/blob/main/LICENSE.txt).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pf-tool"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.2"
|
|
4
4
|
description = "AC/DC power flow for the Brazilian Interconnected Power System (BIPS): Newton-Raphson and optimization (Pyomo/Ipopt) solvers for ANAREDE .dat cases."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.12"
|
|
@@ -13,9 +13,8 @@ build-backend = "setuptools.build_meta"
|
|
|
13
13
|
[dependency-groups]
|
|
14
14
|
dev = ["prek>=0.2.0", "pytest>=8", "pytest-cov>=5"]
|
|
15
15
|
|
|
16
|
-
[tool.setuptools]
|
|
17
|
-
|
|
18
|
-
py-modules = ["exporter", "newton_raphson", "optimization"]
|
|
16
|
+
[tool.setuptools.packages.find]
|
|
17
|
+
where = ["src"]
|
|
19
18
|
|
|
20
19
|
[tool.ruff]
|
|
21
20
|
line-length = 100
|
|
@@ -26,17 +25,15 @@ extend-exclude = ["docs"]
|
|
|
26
25
|
select = ["E", "F", "I", "UP", "W"]
|
|
27
26
|
|
|
28
27
|
[tool.ruff.lint.isort]
|
|
29
|
-
known-first-party = [
|
|
30
|
-
"exporter",
|
|
31
|
-
"models",
|
|
32
|
-
"newton_raphson",
|
|
33
|
-
"optimization",
|
|
34
|
-
"utils",
|
|
35
|
-
]
|
|
28
|
+
known-first-party = ["pf_tool"]
|
|
36
29
|
|
|
37
30
|
[tool.typos.files]
|
|
38
|
-
extend-exclude = ["data/", "docs/package-lock.json"]
|
|
31
|
+
extend-exclude = ["tests/data/", "docs/package-lock.json"]
|
|
39
32
|
|
|
40
33
|
[tool.typos.default.extend-words]
|
|
41
34
|
# "Line-commutated converter" (LCC) is the HVDC term.
|
|
42
35
|
commutated = "commutated"
|
|
36
|
+
# ANAREDE option code and Portuguese block names used in the data-format docs.
|
|
37
|
+
STPO = "STPO"
|
|
38
|
+
Controle = "Controle"
|
|
39
|
+
Circuitos = "Circuitos"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""AC/DC power flow for the Brazilian Interconnected Power System (BIPS)."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
4
|
+
|
|
5
|
+
from pf_tool.exporter import ExportSolution
|
|
6
|
+
from pf_tool.newton_raphson import BusSolution, NewtonRaphsonPowerFlow, PowerFlowResult
|
|
7
|
+
from pf_tool.optimization import OptimizationPowerFlow
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
__version__ = version("pf-tool")
|
|
11
|
+
except PackageNotFoundError:
|
|
12
|
+
__version__ = "0.2.2"
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"BusSolution",
|
|
16
|
+
"ExportSolution",
|
|
17
|
+
"NewtonRaphsonPowerFlow",
|
|
18
|
+
"OptimizationPowerFlow",
|
|
19
|
+
"PowerFlowResult",
|
|
20
|
+
"__version__",
|
|
21
|
+
]
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Usage::
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
from pf_tool import ExportSolution, NewtonRaphsonPowerFlow
|
|
6
|
+
|
|
7
|
+
solver = NewtonRaphsonPowerFlow("CASO01-FLOW.dat")
|
|
6
8
|
solver.solve()
|
|
7
9
|
ExportSolution(solver, output_path="results/CASO01.xlsx")
|
|
8
10
|
|
|
@@ -23,12 +25,12 @@ import numpy as np
|
|
|
23
25
|
from openpyxl import Workbook
|
|
24
26
|
from openpyxl.styles import Font
|
|
25
27
|
|
|
26
|
-
from models.branch import Branch
|
|
27
|
-
from models.bus import BusType
|
|
28
|
-
from models.case import PowerFlowCase
|
|
29
|
-
from models.network_reduction import ZERO_IMPEDANCE_THRESHOLD_PU, ReducedCase
|
|
30
|
-
from models.transformer import TapControl, branch_stamps
|
|
31
|
-
from utils.network import build_ybus, calculate_power
|
|
28
|
+
from pf_tool.models.branch import Branch
|
|
29
|
+
from pf_tool.models.bus import BusType
|
|
30
|
+
from pf_tool.models.case import PowerFlowCase
|
|
31
|
+
from pf_tool.models.network_reduction import ZERO_IMPEDANCE_THRESHOLD_PU, ReducedCase
|
|
32
|
+
from pf_tool.models.transformer import TapControl, branch_stamps
|
|
33
|
+
from pf_tool.utils.network import build_ybus, calculate_power
|
|
32
34
|
|
|
33
35
|
_FLOW_HEADERS = (
|
|
34
36
|
"MW:From-To",
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""Power-system component models used by the AC power-flow solver."""
|
|
2
|
+
|
|
3
|
+
from pf_tool.models.branch import Branch
|
|
4
|
+
from pf_tool.models.bus import Bus, BusType
|
|
5
|
+
from pf_tool.models.case import PowerFlowCase
|
|
6
|
+
|
|
7
|
+
__all__ = ["Branch", "Bus", "BusType", "PowerFlowCase"]
|
|
@@ -7,12 +7,12 @@ from dataclasses import dataclass, field
|
|
|
7
7
|
import numpy as np
|
|
8
8
|
from scipy.sparse import csc_matrix
|
|
9
9
|
|
|
10
|
-
from models.branch import Branch
|
|
11
|
-
from models.bus import Bus, BusType
|
|
12
|
-
from models.hvdc_lcc import HVDCLink
|
|
13
|
-
from models.shunt import SwitchedShunt
|
|
14
|
-
from models.svc import SVC
|
|
15
|
-
from models.transformer import TapControl
|
|
10
|
+
from pf_tool.models.branch import Branch
|
|
11
|
+
from pf_tool.models.bus import Bus, BusType
|
|
12
|
+
from pf_tool.models.hvdc_lcc import HVDCLink
|
|
13
|
+
from pf_tool.models.shunt import SwitchedShunt
|
|
14
|
+
from pf_tool.models.svc import SVC
|
|
15
|
+
from pf_tool.models.transformer import TapControl
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
@dataclass(slots=True)
|
|
@@ -7,10 +7,10 @@ from dataclasses import dataclass, replace
|
|
|
7
7
|
import numpy as np
|
|
8
8
|
from scipy.sparse import coo_matrix, diags
|
|
9
9
|
|
|
10
|
-
from models.bus import Bus, BusType
|
|
11
|
-
from models.case import PowerFlowCase
|
|
12
|
-
from models.transformer import ControlledBranch, TapControl
|
|
13
|
-
from utils.network import build_ybus
|
|
10
|
+
from pf_tool.models.bus import Bus, BusType
|
|
11
|
+
from pf_tool.models.case import PowerFlowCase
|
|
12
|
+
from pf_tool.models.transformer import ControlledBranch, TapControl
|
|
13
|
+
from pf_tool.utils.network import build_ybus
|
|
14
14
|
|
|
15
15
|
# Branches with |r + jx| at or below this value (pu) are contracted.
|
|
16
16
|
ZERO_IMPEDANCE_THRESHOLD_PU = 2.000001e-4
|
|
@@ -7,10 +7,10 @@ from typing import TYPE_CHECKING
|
|
|
7
7
|
|
|
8
8
|
import numpy as np
|
|
9
9
|
|
|
10
|
-
from models.bus import BusType
|
|
10
|
+
from pf_tool.models.bus import BusType
|
|
11
11
|
|
|
12
12
|
if TYPE_CHECKING:
|
|
13
|
-
from models.case import PowerFlowCase
|
|
13
|
+
from pf_tool.models.case import PowerFlowCase
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
@dataclass(slots=True)
|
|
@@ -22,10 +22,10 @@ from typing import TYPE_CHECKING
|
|
|
22
22
|
|
|
23
23
|
import numpy as np
|
|
24
24
|
|
|
25
|
-
from models.branch import Branch
|
|
25
|
+
from pf_tool.models.branch import Branch
|
|
26
26
|
|
|
27
27
|
if TYPE_CHECKING:
|
|
28
|
-
from models.case import PowerFlowCase
|
|
28
|
+
from pf_tool.models.case import PowerFlowCase
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
@dataclass(slots=True)
|
|
@@ -291,8 +291,8 @@ def reconcile_tap_controls(case: PowerFlowCase, voltage: np.ndarray, sweeps: int
|
|
|
291
291
|
mismatches across low-impedance transformers). A correction is only
|
|
292
292
|
applied when it removes most of a significant terminal mismatch.
|
|
293
293
|
"""
|
|
294
|
-
from models.bus import BusType
|
|
295
|
-
from utils.network import build_ybus, calculate_power
|
|
294
|
+
from pf_tool.models.bus import BusType
|
|
295
|
+
from pf_tool.utils.network import build_ybus, calculate_power
|
|
296
296
|
|
|
297
297
|
if not case.tap_controls:
|
|
298
298
|
return False
|
|
@@ -11,20 +11,20 @@ from scipy.sparse import coo_matrix, csc_matrix, diags, hstack, vstack
|
|
|
11
11
|
from scipy.sparse.csgraph import connected_components
|
|
12
12
|
from scipy.sparse.linalg import MatrixRankWarning, spsolve
|
|
13
13
|
|
|
14
|
-
from models.bus import BusType
|
|
15
|
-
from models.hvdc_lcc import update_lcc_from_dc_solution
|
|
16
|
-
from models.network_reduction import reduce_low_impedance_branches
|
|
17
|
-
from models.shunt import adjust_controlled_shunts
|
|
18
|
-
from models.svc import (
|
|
14
|
+
from pf_tool.models.bus import BusType
|
|
15
|
+
from pf_tool.models.hvdc_lcc import update_lcc_from_dc_solution
|
|
16
|
+
from pf_tool.models.network_reduction import reduce_low_impedance_branches
|
|
17
|
+
from pf_tool.models.shunt import adjust_controlled_shunts
|
|
18
|
+
from pf_tool.models.svc import (
|
|
19
19
|
SVCState,
|
|
20
20
|
active_svc_states,
|
|
21
21
|
refresh_svc_limits,
|
|
22
22
|
store_svc_outputs,
|
|
23
23
|
)
|
|
24
|
-
from models.transformer import TapControl, branch_sensitivity, reconcile_tap_controls
|
|
25
|
-
from utils.dat_parser import parse_dat_file
|
|
26
|
-
from utils.network import build_ybus, calculate_power, freeze_branch_matrix
|
|
27
|
-
from utils.utils import build_power_flow_case
|
|
24
|
+
from pf_tool.models.transformer import TapControl, branch_sensitivity, reconcile_tap_controls
|
|
25
|
+
from pf_tool.utils.dat_parser import parse_dat_file
|
|
26
|
+
from pf_tool.utils.network import build_ybus, calculate_power, freeze_branch_matrix
|
|
27
|
+
from pf_tool.utils.utils import build_power_flow_case
|
|
28
28
|
|
|
29
29
|
# Largest tap-ratio / phase-angle (rad) move allowed in one Newton iteration.
|
|
30
30
|
_MAX_TAP_STEP = 0.05
|
|
@@ -76,9 +76,8 @@ class _Layout:
|
|
|
76
76
|
class NewtonRaphsonPowerFlow:
|
|
77
77
|
"""Solve an ANAREDE ``.dat`` case using sparse Newton-Raphson iterations.
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
format; by default it solves ``tests/data/CASO01-FLOW.dat``.
|
|
79
|
+
``data_file`` is an AMPL-style ANAREDE block export, such as the cases in
|
|
80
|
+
the repository's ``tests/data/`` folder.
|
|
82
81
|
|
|
83
82
|
Besides bus voltages, the Newton state includes SVC reactive outputs, LTC
|
|
84
83
|
tap shifts (DOPC ``CTAP``) and phase-shifter angles (DOPC ``CPHS``).
|
|
@@ -91,17 +90,13 @@ class NewtonRaphsonPowerFlow:
|
|
|
91
90
|
|
|
92
91
|
def __init__(
|
|
93
92
|
self,
|
|
94
|
-
data_file: str | Path
|
|
93
|
+
data_file: str | Path,
|
|
95
94
|
*,
|
|
96
95
|
tolerance: float | None = None,
|
|
97
96
|
max_iterations: int | None = None,
|
|
98
97
|
max_control_passes: int = 50,
|
|
99
98
|
) -> None:
|
|
100
|
-
self.data_file = (
|
|
101
|
-
Path(data_file)
|
|
102
|
-
if data_file is not None
|
|
103
|
-
else Path(__file__).resolve().parent / "data" / "CASO01-FLOW.dat"
|
|
104
|
-
)
|
|
99
|
+
self.data_file = Path(data_file)
|
|
105
100
|
tables = parse_dat_file(self.data_file)
|
|
106
101
|
self.case = build_power_flow_case(tables)
|
|
107
102
|
constants = {
|
|
@@ -33,21 +33,21 @@ from pyomo.opt import SolverFactory, TerminationCondition
|
|
|
33
33
|
from scipy.sparse import csc_matrix
|
|
34
34
|
from scipy.sparse.csgraph import connected_components
|
|
35
35
|
|
|
36
|
-
from models.bus import BusType
|
|
37
|
-
from models.case import PowerFlowCase
|
|
38
|
-
from models.hvdc_lcc import update_lcc_from_dc_solution
|
|
39
|
-
from models.network_reduction import reduce_low_impedance_branches
|
|
40
|
-
from models.shunt import adjust_controlled_shunts
|
|
41
|
-
from models.svc import active_svc_states, refresh_svc_limits
|
|
42
|
-
from models.transformer import reconcile_tap_controls
|
|
43
|
-
from newton_raphson import (
|
|
36
|
+
from pf_tool.models.bus import BusType
|
|
37
|
+
from pf_tool.models.case import PowerFlowCase
|
|
38
|
+
from pf_tool.models.hvdc_lcc import update_lcc_from_dc_solution
|
|
39
|
+
from pf_tool.models.network_reduction import reduce_low_impedance_branches
|
|
40
|
+
from pf_tool.models.shunt import adjust_controlled_shunts
|
|
41
|
+
from pf_tool.models.svc import active_svc_states, refresh_svc_limits
|
|
42
|
+
from pf_tool.models.transformer import reconcile_tap_controls
|
|
43
|
+
from pf_tool.newton_raphson import (
|
|
44
44
|
BusSolution,
|
|
45
45
|
NewtonRaphsonPowerFlow,
|
|
46
46
|
PowerFlowResult,
|
|
47
47
|
)
|
|
48
|
-
from utils.dat_parser import parse_dat_file
|
|
49
|
-
from utils.network import build_ybus, calculate_power, freeze_branch_matrix
|
|
50
|
-
from utils.utils import build_power_flow_case
|
|
48
|
+
from pf_tool.utils.dat_parser import parse_dat_file
|
|
49
|
+
from pf_tool.utils.network import build_ybus, calculate_power, freeze_branch_matrix
|
|
50
|
+
from pf_tool.utils.utils import build_power_flow_case
|
|
51
51
|
|
|
52
52
|
_IPOPT_ACCEPTED_TERMINATIONS = {
|
|
53
53
|
TerminationCondition.optimal,
|
|
@@ -458,12 +458,21 @@ def solve_optimization_model(
|
|
|
458
458
|
max_iterations: int = 200,
|
|
459
459
|
max_cpu_time: float = 900.0,
|
|
460
460
|
print_iterations: bool = False,
|
|
461
|
+
ipopt_executable: str | Path | None = None,
|
|
461
462
|
) -> tuple[Any, int | None]:
|
|
462
|
-
"""Solve ``model`` with Ipopt, raising a clear error if it is unavailable.
|
|
463
|
-
|
|
463
|
+
"""Solve ``model`` with Ipopt, raising a clear error if it is unavailable.
|
|
464
|
+
|
|
465
|
+
``ipopt_executable`` is the path to the Ipopt binary; ``None`` searches ``PATH``.
|
|
466
|
+
"""
|
|
467
|
+
if ipopt_executable is None:
|
|
468
|
+
solver = SolverFactory("ipopt")
|
|
469
|
+
else:
|
|
470
|
+
solver = SolverFactory("ipopt", executable=str(ipopt_executable))
|
|
464
471
|
if solver is None or not solver.available(exception_flag=False):
|
|
472
|
+
location = f"at {ipopt_executable}" if ipopt_executable is not None else "on PATH"
|
|
465
473
|
raise RuntimeError(
|
|
466
|
-
"Ipopt is not available. Install
|
|
474
|
+
f"Ipopt is not available {location}. Install Ipopt and add it to PATH, "
|
|
475
|
+
"or pass ipopt_executable='path/to/ipopt'."
|
|
467
476
|
)
|
|
468
477
|
solver.options["max_iter"] = int(max_iterations)
|
|
469
478
|
solver.options["max_cpu_time"] = float(max_cpu_time)
|
|
@@ -585,11 +594,14 @@ class OptimizationPowerFlow:
|
|
|
585
594
|
shunt steps, LTC taps, phase shifts, SVC outputs, LCC set-points). With
|
|
586
595
|
``warm_start=False`` the NLP starts from the voltages stored in the case,
|
|
587
596
|
after reconciling transformer settings with them.
|
|
597
|
+
|
|
598
|
+
Ipopt is looked up on ``PATH`` unless ``ipopt_executable`` gives the path to
|
|
599
|
+
the binary.
|
|
588
600
|
"""
|
|
589
601
|
|
|
590
602
|
def __init__(
|
|
591
603
|
self,
|
|
592
|
-
data_file: str | Path
|
|
604
|
+
data_file: str | Path,
|
|
593
605
|
*,
|
|
594
606
|
tolerance: float | None = None,
|
|
595
607
|
max_iterations: int | None = None,
|
|
@@ -597,12 +609,9 @@ class OptimizationPowerFlow:
|
|
|
597
609
|
max_control_passes: int = 20,
|
|
598
610
|
warm_start: bool = True,
|
|
599
611
|
print_iterations: bool = False,
|
|
612
|
+
ipopt_executable: str | Path | None = None,
|
|
600
613
|
) -> None:
|
|
601
|
-
self.data_file = (
|
|
602
|
-
Path(data_file)
|
|
603
|
-
if data_file is not None
|
|
604
|
-
else Path(__file__).resolve().parent / "data" / "CASO01-FLOW.dat"
|
|
605
|
-
)
|
|
614
|
+
self.data_file = Path(data_file)
|
|
606
615
|
tables = parse_dat_file(self.data_file)
|
|
607
616
|
self.case = build_power_flow_case(tables)
|
|
608
617
|
constants = {
|
|
@@ -626,6 +635,7 @@ class OptimizationPowerFlow:
|
|
|
626
635
|
self.max_control_passes = int(max_control_passes)
|
|
627
636
|
self.warm_start = bool(warm_start)
|
|
628
637
|
self.print_iterations = bool(print_iterations)
|
|
638
|
+
self.ipopt_executable = ipopt_executable
|
|
629
639
|
self.tap_voltage_band = float(constants.get("TLTC", 0.01))
|
|
630
640
|
self.warm_start_iterations = 0
|
|
631
641
|
self.warm_start_converged = False
|
|
@@ -693,6 +703,7 @@ class OptimizationPowerFlow:
|
|
|
693
703
|
max_iterations=self.max_iterations,
|
|
694
704
|
max_cpu_time=self.max_cpu_time,
|
|
695
705
|
print_iterations=self.print_iterations,
|
|
706
|
+
ipopt_executable=self.ipopt_executable,
|
|
696
707
|
)
|
|
697
708
|
self.nlp_solves += 1
|
|
698
709
|
ipopt_iterations += iterations or 0
|
|
@@ -5,8 +5,8 @@ from __future__ import annotations
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
from scipy.sparse import coo_matrix, csc_matrix, diags
|
|
7
7
|
|
|
8
|
-
from models.case import PowerFlowCase
|
|
9
|
-
from models.transformer import branch_stamps
|
|
8
|
+
from pf_tool.models.case import PowerFlowCase
|
|
9
|
+
from pf_tool.models.transformer import branch_stamps
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
def build_ybus(case: PowerFlowCase) -> csc_matrix:
|
|
@@ -4,15 +4,15 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import math
|
|
6
6
|
|
|
7
|
-
from models.branch import Branch
|
|
8
|
-
from models.bus import Bus, BusType
|
|
9
|
-
from models.case import PowerFlowCase
|
|
10
|
-
from models.csc import apply_csc_records
|
|
11
|
-
from models.generator import Generator
|
|
12
|
-
from models.hvdc_lcc import build_lcc_links
|
|
13
|
-
from models.shunt import build_shunt
|
|
14
|
-
from models.svc import SVC
|
|
15
|
-
from models.transformer import branch_from_dlin, build_tap_controls
|
|
7
|
+
from pf_tool.models.branch import Branch
|
|
8
|
+
from pf_tool.models.bus import Bus, BusType
|
|
9
|
+
from pf_tool.models.case import PowerFlowCase
|
|
10
|
+
from pf_tool.models.csc import apply_csc_records
|
|
11
|
+
from pf_tool.models.generator import Generator
|
|
12
|
+
from pf_tool.models.hvdc_lcc import build_lcc_links
|
|
13
|
+
from pf_tool.models.shunt import build_shunt
|
|
14
|
+
from pf_tool.models.svc import SVC
|
|
15
|
+
from pf_tool.models.transformer import branch_from_dlin, build_tap_controls
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
def build_power_flow_case(tables: dict[str, list[dict[str, str]]]) -> PowerFlowCase:
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pf-tool
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: AC/DC power flow for the Brazilian Interconnected Power System (BIPS): Newton-Raphson and optimization (Pyomo/Ipopt) solvers for ANAREDE .dat cases.
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE.txt
|
|
8
|
+
Requires-Dist: numpy>=1.24
|
|
9
|
+
Requires-Dist: openpyxl>=3.1
|
|
10
|
+
Requires-Dist: pyomo>=6.8
|
|
11
|
+
Requires-Dist: scipy>=1.10
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
<h1 align="center">pf-tool</h1>
|
|
15
|
+
|
|
16
|
+
<p align="center"><em>AC/DC power flow for the Brazilian Interconnected Power System (BIPS).</em></p>
|
|
17
|
+
|
|
18
|
+
<p align="center">
|
|
19
|
+
<a href="https://github.com/mcllerena/pf-tool/actions/workflows/ci.yaml"><img src="https://github.com/mcllerena/pf-tool/actions/workflows/ci.yaml/badge.svg" alt="CI"></a>
|
|
20
|
+
<a href="https://pypi.org/project/pf-tool/"><img src="https://img.shields.io/pypi/v/pf-tool?label=PyPI&color=0079c2&logo=pypi" alt="PyPI"></a>
|
|
21
|
+
<a href="https://mcllerena.github.io/pf-tool/"><img src="https://img.shields.io/badge/docs-guides-0079c2?style=flat-square" alt="Docs"></a>
|
|
22
|
+
<a href="https://github.com/mcllerena/pf-tool/blob/main/pyproject.toml"><img src="https://img.shields.io/badge/Python-3.12+-3776ab?logo=python&logoColor=white" alt="Python 3.12+"></a>
|
|
23
|
+
<a href="https://docs.astral.sh/uv/"><img src="https://img.shields.io/badge/managed%20with-uv-6f42c1" alt="Managed with uv"></a>
|
|
24
|
+
<a href="https://github.com/mcllerena/pf-tool/blob/main/LICENSE.txt"><img src="https://img.shields.io/badge/license-BSD--3--Clause-blue.svg" alt="BSD 3-Clause"></a>
|
|
25
|
+
</p>
|
|
26
|
+
|
|
27
|
+
`pf-tool` solves ANAREDE-style `.dat` cases of the BIPS, about 12,600 buses
|
|
28
|
+
each, with a sparse Newton-Raphson solver or an optimization-based AC power
|
|
29
|
+
flow (Pyomo NLP solved with Ipopt), and exports every solved component to an
|
|
30
|
+
Excel workbook.
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
### Install
|
|
35
|
+
|
|
36
|
+
Use Python 3.12 or newer:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
python -m pip install pf-tool
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Ipopt
|
|
43
|
+
|
|
44
|
+
`OptimizationPowerFlow` solves its NLP with
|
|
45
|
+
[Ipopt](https://coin-or.github.io/Ipopt/). Download a prebuilt binary from the
|
|
46
|
+
[Ipopt releases](https://github.com/coin-or/Ipopt/releases) (or run
|
|
47
|
+
`conda install -c conda-forge ipopt`), then either add its `bin` folder to `PATH`:
|
|
48
|
+
|
|
49
|
+
```powershell
|
|
50
|
+
# Windows (PowerShell), current session; use System Properties > Environment
|
|
51
|
+
# Variables to make it permanent
|
|
52
|
+
$env:Path += ";C:\ipopt\bin"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Linux/macOS; add the line to ~/.bashrc or ~/.zshrc to make it permanent
|
|
57
|
+
export PATH="$PATH:/opt/ipopt/bin"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Check it with `ipopt --version`. Or skip `PATH` and pass the executable directly:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
nlp = OptimizationPowerFlow(
|
|
64
|
+
"CASO01-FLOW.dat", ipopt_executable="path/to/solver", warm_start=True, print_iterations=True
|
|
65
|
+
).solve()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`NewtonRaphsonPowerFlow` does not need Ipopt.
|
|
69
|
+
|
|
70
|
+
### Solve a case
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from pf_tool import ExportSolution, NewtonRaphsonPowerFlow, OptimizationPowerFlow
|
|
74
|
+
|
|
75
|
+
solver = NewtonRaphsonPowerFlow("CASO01-FLOW.dat")
|
|
76
|
+
result = solver.solve()
|
|
77
|
+
print(result.converged, result.iterations, result.max_mismatch)
|
|
78
|
+
|
|
79
|
+
ExportSolution(solver, output_path="results/CASO01-FLOW-nr.xlsx")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The eleven sample cases are in
|
|
83
|
+
[`tests/data/`](https://github.com/mcllerena/pf-tool/tree/main/tests/data), and
|
|
84
|
+
runnable scripts are in
|
|
85
|
+
[`examples/`](https://github.com/mcllerena/pf-tool/tree/main/examples).
|
|
86
|
+
|
|
87
|
+
## Documentation
|
|
88
|
+
|
|
89
|
+
- [Getting started](https://mcllerena.github.io/pf-tool/getting-started/): installation and first solve.
|
|
90
|
+
- [Solution pipeline](https://mcllerena.github.io/pf-tool/pipeline/): parsing, reduction, solve, and write-back.
|
|
91
|
+
- [Data file](https://mcllerena.github.io/pf-tool/data/blocks/): every `.dat` block and column.
|
|
92
|
+
- [Components](https://mcllerena.github.io/pf-tool/components/buses/): how each power-system component is modeled.
|
|
93
|
+
- [Newton-Raphson](https://mcllerena.github.io/pf-tool/methods/newton-raphson/) and [optimization](https://mcllerena.github.io/pf-tool/methods/optimization/): full formulations.
|
|
94
|
+
- [Results and benchmarks](https://mcllerena.github.io/pf-tool/methods/results/): convergence on all eleven cases.
|
|
95
|
+
- [Exporting results](https://mcllerena.github.io/pf-tool/export/): the Excel workbook layout.
|
|
96
|
+
- [Changelog](https://github.com/mcllerena/pf-tool/blob/main/CHANGELOG.md): release history.
|
|
97
|
+
|
|
98
|
+
## Development
|
|
99
|
+
|
|
100
|
+
From the repository root, install the development dependencies with `uv`:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
uv sync --locked --all-groups
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Then run the tests and the formatting and lint hooks:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
uv run pytest
|
|
110
|
+
uv run prek run --all-files
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
BSD-3-Clause. See [LICENSE.txt](https://github.com/mcllerena/pf-tool/blob/main/LICENSE.txt).
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
LICENSE.txt
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/pf_tool/__init__.py
|
|
5
|
+
src/pf_tool/exporter.py
|
|
6
|
+
src/pf_tool/newton_raphson.py
|
|
7
|
+
src/pf_tool/optimization.py
|
|
8
|
+
src/pf_tool.egg-info/PKG-INFO
|
|
9
|
+
src/pf_tool.egg-info/SOURCES.txt
|
|
10
|
+
src/pf_tool.egg-info/dependency_links.txt
|
|
11
|
+
src/pf_tool.egg-info/requires.txt
|
|
12
|
+
src/pf_tool.egg-info/top_level.txt
|
|
13
|
+
src/pf_tool/models/__init__.py
|
|
14
|
+
src/pf_tool/models/branch.py
|
|
15
|
+
src/pf_tool/models/bus.py
|
|
16
|
+
src/pf_tool/models/case.py
|
|
17
|
+
src/pf_tool/models/csc.py
|
|
18
|
+
src/pf_tool/models/generator.py
|
|
19
|
+
src/pf_tool/models/hvdc_lcc.py
|
|
20
|
+
src/pf_tool/models/network_reduction.py
|
|
21
|
+
src/pf_tool/models/shunt.py
|
|
22
|
+
src/pf_tool/models/svc.py
|
|
23
|
+
src/pf_tool/models/transformer.py
|
|
24
|
+
src/pf_tool/utils/__init__.py
|
|
25
|
+
src/pf_tool/utils/dat_parser.py
|
|
26
|
+
src/pf_tool/utils/network.py
|
|
27
|
+
src/pf_tool/utils/utils.py
|
|
28
|
+
tests/test_exporter.py
|
|
29
|
+
tests/test_newton_raphson.py
|
|
30
|
+
tests/test_optimization.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pf_tool
|
|
@@ -6,11 +6,11 @@ from pathlib import Path
|
|
|
6
6
|
|
|
7
7
|
from openpyxl import load_workbook
|
|
8
8
|
|
|
9
|
-
from exporter import SHEET_HEADERS, ExportSolution
|
|
10
|
-
from models.branch import Branch
|
|
11
|
-
from models.bus import Bus, BusType
|
|
12
|
-
from models.case import PowerFlowCase
|
|
13
|
-
from newton_raphson import NewtonRaphsonPowerFlow
|
|
9
|
+
from pf_tool.exporter import SHEET_HEADERS, ExportSolution
|
|
10
|
+
from pf_tool.models.branch import Branch
|
|
11
|
+
from pf_tool.models.bus import Bus, BusType
|
|
12
|
+
from pf_tool.models.case import PowerFlowCase
|
|
13
|
+
from pf_tool.newton_raphson import NewtonRaphsonPowerFlow
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class ExportSolutionTests(unittest.TestCase):
|
|
@@ -4,13 +4,13 @@ import unittest
|
|
|
4
4
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
|
|
7
|
-
from models.branch import Branch
|
|
8
|
-
from models.bus import Bus, BusType
|
|
9
|
-
from models.case import PowerFlowCase
|
|
10
|
-
from models.hvdc_lcc import build_lcc_links, update_lcc_from_dc_solution
|
|
11
|
-
from models.svc import SVC, SVCState, refresh_svc_limits
|
|
12
|
-
from newton_raphson import NewtonRaphsonPowerFlow
|
|
13
|
-
from utils.dat_parser import parse_dat_text
|
|
7
|
+
from pf_tool.models.branch import Branch
|
|
8
|
+
from pf_tool.models.bus import Bus, BusType
|
|
9
|
+
from pf_tool.models.case import PowerFlowCase
|
|
10
|
+
from pf_tool.models.hvdc_lcc import build_lcc_links, update_lcc_from_dc_solution
|
|
11
|
+
from pf_tool.models.svc import SVC, SVCState, refresh_svc_limits
|
|
12
|
+
from pf_tool.newton_raphson import NewtonRaphsonPowerFlow
|
|
13
|
+
from pf_tool.utils.dat_parser import parse_dat_text
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class DatParserTests(unittest.TestCase):
|
|
@@ -363,7 +363,7 @@ def _dat_tables(dbsh: list[dict[str, str]], dcsc: list[dict[str, str]]) -> dict:
|
|
|
363
363
|
|
|
364
364
|
class CaseConstructionTests(unittest.TestCase):
|
|
365
365
|
def test_dcsc_records_are_series_branches_or_bypass_shorts(self) -> None:
|
|
366
|
-
from utils.utils import build_power_flow_case
|
|
366
|
+
from pf_tool.utils.utils import build_power_flow_case
|
|
367
367
|
|
|
368
368
|
csc = {"O": "A", "E": "L", "Nc": "1", "Xmin": "-5", "Xmax": "-5", "Cdcsc": "0"}
|
|
369
369
|
case = build_power_flow_case(
|
|
@@ -381,7 +381,7 @@ class CaseConstructionTests(unittest.TestCase):
|
|
|
381
381
|
self.assertLess(abs(reactances[(1, 3)]), 1e-5)
|
|
382
382
|
|
|
383
383
|
def test_line_shunt_sits_at_its_terminal_and_needs_its_line(self) -> None:
|
|
384
|
-
from utils.utils import build_power_flow_case
|
|
384
|
+
from pf_tool.utils.utils import build_power_flow_case
|
|
385
385
|
|
|
386
386
|
shunt = {
|
|
387
387
|
"O": "A",
|
|
@@ -418,7 +418,7 @@ class TransformerControlTests(unittest.TestCase):
|
|
|
418
418
|
return solver
|
|
419
419
|
|
|
420
420
|
def test_ltc_acts_only_outside_its_voltage_band(self) -> None:
|
|
421
|
-
from models.transformer import build_tap_controls
|
|
421
|
+
from pf_tool.models.transformer import build_tap_controls
|
|
422
422
|
|
|
423
423
|
branches = [
|
|
424
424
|
Branch(1, 2, 1, 0.0, 0.05, 0.0),
|
|
@@ -443,7 +443,7 @@ class TransformerControlTests(unittest.TestCase):
|
|
|
443
443
|
self.assertLess(case.branches[1].tap_ratio, 1.0)
|
|
444
444
|
|
|
445
445
|
def test_phase_shifter_holds_its_scheduled_flow(self) -> None:
|
|
446
|
-
from models.transformer import branch_stamps, build_tap_controls
|
|
446
|
+
from pf_tool.models.transformer import branch_stamps, build_tap_controls
|
|
447
447
|
|
|
448
448
|
branches = [
|
|
449
449
|
Branch(1, 2, 1, 0.0, 0.1, 0.0),
|
|
@@ -484,7 +484,7 @@ class TransformerControlTests(unittest.TestCase):
|
|
|
484
484
|
self.assertAlmostEqual(flow.real, 0.2, places=7)
|
|
485
485
|
|
|
486
486
|
def test_switched_shunt_freezes_instead_of_hunting(self) -> None:
|
|
487
|
-
from models.shunt import ShuntStage, SwitchedShunt, adjust_controlled_shunts
|
|
487
|
+
from pf_tool.models.shunt import ShuntStage, SwitchedShunt, adjust_controlled_shunts
|
|
488
488
|
|
|
489
489
|
case = PowerFlowCase(
|
|
490
490
|
base_mva=100.0,
|
|
@@ -2,11 +2,11 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import unittest
|
|
4
4
|
|
|
5
|
-
from models.branch import Branch
|
|
6
|
-
from models.bus import Bus, BusType
|
|
7
|
-
from models.case import PowerFlowCase
|
|
8
|
-
from models.svc import SVC
|
|
9
|
-
from optimization import (
|
|
5
|
+
from pf_tool.models.branch import Branch
|
|
6
|
+
from pf_tool.models.bus import Bus, BusType
|
|
7
|
+
from pf_tool.models.case import PowerFlowCase
|
|
8
|
+
from pf_tool.models.svc import SVC
|
|
9
|
+
from pf_tool.optimization import (
|
|
10
10
|
build_optimization_model,
|
|
11
11
|
solution_metrics,
|
|
12
12
|
solve_optimization_model,
|
|
@@ -14,6 +14,16 @@ from optimization import (
|
|
|
14
14
|
)
|
|
15
15
|
|
|
16
16
|
|
|
17
|
+
class IpoptExecutableTests(unittest.TestCase):
|
|
18
|
+
def test_missing_executable_path_raises_clear_error(self) -> None:
|
|
19
|
+
import pyomo.environ as pyo
|
|
20
|
+
|
|
21
|
+
with self.assertRaisesRegex(RuntimeError, "no-such-ipopt"):
|
|
22
|
+
solve_optimization_model(
|
|
23
|
+
pyo.ConcreteModel(), ipopt_executable="C:/no-such-dir/no-such-ipopt"
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
17
27
|
class OptimizationPowerFlowTests(unittest.TestCase):
|
|
18
28
|
def setUp(self) -> None:
|
|
19
29
|
from pyomo.environ import SolverFactory
|
pf_tool-0.2.1/PKG-INFO
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: pf-tool
|
|
3
|
-
Version: 0.2.1
|
|
4
|
-
Summary: AC/DC power flow for the Brazilian Interconnected Power System (BIPS): Newton-Raphson and optimization (Pyomo/Ipopt) solvers for ANAREDE .dat cases.
|
|
5
|
-
Requires-Python: >=3.12
|
|
6
|
-
Description-Content-Type: text/markdown
|
|
7
|
-
License-File: LICENSE.txt
|
|
8
|
-
Requires-Dist: numpy>=1.24
|
|
9
|
-
Requires-Dist: openpyxl>=3.1
|
|
10
|
-
Requires-Dist: pyomo>=6.8
|
|
11
|
-
Requires-Dist: scipy>=1.10
|
|
12
|
-
Dynamic: license-file
|
|
13
|
-
|
|
14
|
-
<h1 align="center">pf-tool</h1>
|
|
15
|
-
|
|
16
|
-
<p align="center">
|
|
17
|
-
<a href="https://mcllerena.github.io/pf-tool/"><img src="https://img.shields.io/badge/docs-guides-0079c2?style=flat-square" alt="Docs"></a>
|
|
18
|
-
<a href="https://github.com/mcllerena/pf-tool/blob/main/pyproject.toml"><img src="https://img.shields.io/badge/Python-3.12+-3776ab?logo=python&logoColor=white" alt="Python 3.12+"></a>
|
|
19
|
-
<a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff"></a>
|
|
20
|
-
<a href="https://github.com/mcllerena/pf-tool/blob/main/LICENSE.txt"><img src="https://img.shields.io/badge/license-BSD--3--Clause-blue.svg" alt="BSD 3-Clause"></a>
|
|
21
|
-
</p>
|
|
22
|
-
|
|
23
|
-
AC/DC power-flow solver for the Brazilian Interconnected Power System (BIPS). It
|
|
24
|
-
solves ANAREDE-style `.dat` cases, about 12,600 buses each, with two methods:
|
|
25
|
-
|
|
26
|
-
- `NewtonRaphsonPowerFlow`: a sparse polar Newton-Raphson solver.
|
|
27
|
-
- `OptimizationPowerFlow`: an optimization-based AC power flow (Pyomo NLP
|
|
28
|
-
solved with Ipopt).
|
|
29
|
-
|
|
30
|
-
The [documentation](https://mcllerena.github.io/pf-tool/) covers the data
|
|
31
|
-
format, component models, both formulations, and benchmark results.
|
|
32
|
-
|
|
33
|
-
## Installation
|
|
34
|
-
|
|
35
|
-
```
|
|
36
|
-
git clone https://github.com/mcllerena/pf-tool.git
|
|
37
|
-
cd pf-tool
|
|
38
|
-
uv sync
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
The optimization solver also needs an Ipopt executable on `PATH`.
|
|
42
|
-
|
|
43
|
-
## Usage
|
|
44
|
-
|
|
45
|
-
```python
|
|
46
|
-
from exporter import ExportSolution
|
|
47
|
-
from newton_raphson import NewtonRaphsonPowerFlow
|
|
48
|
-
from optimization import OptimizationPowerFlow
|
|
49
|
-
|
|
50
|
-
newton = NewtonRaphsonPowerFlow("tests/data/CASO01-FLOW.dat")
|
|
51
|
-
newton.solve()
|
|
52
|
-
ExportSolution(newton, output_path="results/CASO01-FLOW-nr.xlsx")
|
|
53
|
-
|
|
54
|
-
nlp = OptimizationPowerFlow("tests/data/CASO01-FLOW.dat", warm_start=True).solve()
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
Runnable scripts are in
|
|
58
|
-
[`examples/`](https://github.com/mcllerena/pf-tool/tree/main/examples).
|
|
59
|
-
|
|
60
|
-
## Development
|
|
61
|
-
|
|
62
|
-
```
|
|
63
|
-
uv run pytest # tests
|
|
64
|
-
uv run prek run --all-files # lint and format hooks
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## License
|
|
68
|
-
|
|
69
|
-
[BSD 3-Clause](https://github.com/mcllerena/pf-tool/blob/main/LICENSE.txt)
|
pf_tool-0.2.1/README.md
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
<h1 align="center">pf-tool</h1>
|
|
2
|
-
|
|
3
|
-
<p align="center">
|
|
4
|
-
<a href="https://mcllerena.github.io/pf-tool/"><img src="https://img.shields.io/badge/docs-guides-0079c2?style=flat-square" alt="Docs"></a>
|
|
5
|
-
<a href="https://github.com/mcllerena/pf-tool/blob/main/pyproject.toml"><img src="https://img.shields.io/badge/Python-3.12+-3776ab?logo=python&logoColor=white" alt="Python 3.12+"></a>
|
|
6
|
-
<a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff"></a>
|
|
7
|
-
<a href="https://github.com/mcllerena/pf-tool/blob/main/LICENSE.txt"><img src="https://img.shields.io/badge/license-BSD--3--Clause-blue.svg" alt="BSD 3-Clause"></a>
|
|
8
|
-
</p>
|
|
9
|
-
|
|
10
|
-
AC/DC power-flow solver for the Brazilian Interconnected Power System (BIPS). It
|
|
11
|
-
solves ANAREDE-style `.dat` cases, about 12,600 buses each, with two methods:
|
|
12
|
-
|
|
13
|
-
- `NewtonRaphsonPowerFlow`: a sparse polar Newton-Raphson solver.
|
|
14
|
-
- `OptimizationPowerFlow`: an optimization-based AC power flow (Pyomo NLP
|
|
15
|
-
solved with Ipopt).
|
|
16
|
-
|
|
17
|
-
The [documentation](https://mcllerena.github.io/pf-tool/) covers the data
|
|
18
|
-
format, component models, both formulations, and benchmark results.
|
|
19
|
-
|
|
20
|
-
## Installation
|
|
21
|
-
|
|
22
|
-
```
|
|
23
|
-
git clone https://github.com/mcllerena/pf-tool.git
|
|
24
|
-
cd pf-tool
|
|
25
|
-
uv sync
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
The optimization solver also needs an Ipopt executable on `PATH`.
|
|
29
|
-
|
|
30
|
-
## Usage
|
|
31
|
-
|
|
32
|
-
```python
|
|
33
|
-
from exporter import ExportSolution
|
|
34
|
-
from newton_raphson import NewtonRaphsonPowerFlow
|
|
35
|
-
from optimization import OptimizationPowerFlow
|
|
36
|
-
|
|
37
|
-
newton = NewtonRaphsonPowerFlow("tests/data/CASO01-FLOW.dat")
|
|
38
|
-
newton.solve()
|
|
39
|
-
ExportSolution(newton, output_path="results/CASO01-FLOW-nr.xlsx")
|
|
40
|
-
|
|
41
|
-
nlp = OptimizationPowerFlow("tests/data/CASO01-FLOW.dat", warm_start=True).solve()
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
Runnable scripts are in
|
|
45
|
-
[`examples/`](https://github.com/mcllerena/pf-tool/tree/main/examples).
|
|
46
|
-
|
|
47
|
-
## Development
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
uv run pytest # tests
|
|
51
|
-
uv run prek run --all-files # lint and format hooks
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## License
|
|
55
|
-
|
|
56
|
-
[BSD 3-Clause](https://github.com/mcllerena/pf-tool/blob/main/LICENSE.txt)
|
pf_tool-0.2.1/models/__init__.py
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: pf-tool
|
|
3
|
-
Version: 0.2.1
|
|
4
|
-
Summary: AC/DC power flow for the Brazilian Interconnected Power System (BIPS): Newton-Raphson and optimization (Pyomo/Ipopt) solvers for ANAREDE .dat cases.
|
|
5
|
-
Requires-Python: >=3.12
|
|
6
|
-
Description-Content-Type: text/markdown
|
|
7
|
-
License-File: LICENSE.txt
|
|
8
|
-
Requires-Dist: numpy>=1.24
|
|
9
|
-
Requires-Dist: openpyxl>=3.1
|
|
10
|
-
Requires-Dist: pyomo>=6.8
|
|
11
|
-
Requires-Dist: scipy>=1.10
|
|
12
|
-
Dynamic: license-file
|
|
13
|
-
|
|
14
|
-
<h1 align="center">pf-tool</h1>
|
|
15
|
-
|
|
16
|
-
<p align="center">
|
|
17
|
-
<a href="https://mcllerena.github.io/pf-tool/"><img src="https://img.shields.io/badge/docs-guides-0079c2?style=flat-square" alt="Docs"></a>
|
|
18
|
-
<a href="https://github.com/mcllerena/pf-tool/blob/main/pyproject.toml"><img src="https://img.shields.io/badge/Python-3.12+-3776ab?logo=python&logoColor=white" alt="Python 3.12+"></a>
|
|
19
|
-
<a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff"></a>
|
|
20
|
-
<a href="https://github.com/mcllerena/pf-tool/blob/main/LICENSE.txt"><img src="https://img.shields.io/badge/license-BSD--3--Clause-blue.svg" alt="BSD 3-Clause"></a>
|
|
21
|
-
</p>
|
|
22
|
-
|
|
23
|
-
AC/DC power-flow solver for the Brazilian Interconnected Power System (BIPS). It
|
|
24
|
-
solves ANAREDE-style `.dat` cases, about 12,600 buses each, with two methods:
|
|
25
|
-
|
|
26
|
-
- `NewtonRaphsonPowerFlow`: a sparse polar Newton-Raphson solver.
|
|
27
|
-
- `OptimizationPowerFlow`: an optimization-based AC power flow (Pyomo NLP
|
|
28
|
-
solved with Ipopt).
|
|
29
|
-
|
|
30
|
-
The [documentation](https://mcllerena.github.io/pf-tool/) covers the data
|
|
31
|
-
format, component models, both formulations, and benchmark results.
|
|
32
|
-
|
|
33
|
-
## Installation
|
|
34
|
-
|
|
35
|
-
```
|
|
36
|
-
git clone https://github.com/mcllerena/pf-tool.git
|
|
37
|
-
cd pf-tool
|
|
38
|
-
uv sync
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
The optimization solver also needs an Ipopt executable on `PATH`.
|
|
42
|
-
|
|
43
|
-
## Usage
|
|
44
|
-
|
|
45
|
-
```python
|
|
46
|
-
from exporter import ExportSolution
|
|
47
|
-
from newton_raphson import NewtonRaphsonPowerFlow
|
|
48
|
-
from optimization import OptimizationPowerFlow
|
|
49
|
-
|
|
50
|
-
newton = NewtonRaphsonPowerFlow("tests/data/CASO01-FLOW.dat")
|
|
51
|
-
newton.solve()
|
|
52
|
-
ExportSolution(newton, output_path="results/CASO01-FLOW-nr.xlsx")
|
|
53
|
-
|
|
54
|
-
nlp = OptimizationPowerFlow("tests/data/CASO01-FLOW.dat", warm_start=True).solve()
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
Runnable scripts are in
|
|
58
|
-
[`examples/`](https://github.com/mcllerena/pf-tool/tree/main/examples).
|
|
59
|
-
|
|
60
|
-
## Development
|
|
61
|
-
|
|
62
|
-
```
|
|
63
|
-
uv run pytest # tests
|
|
64
|
-
uv run prek run --all-files # lint and format hooks
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## License
|
|
68
|
-
|
|
69
|
-
[BSD 3-Clause](https://github.com/mcllerena/pf-tool/blob/main/LICENSE.txt)
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
LICENSE.txt
|
|
2
|
-
README.md
|
|
3
|
-
exporter.py
|
|
4
|
-
newton_raphson.py
|
|
5
|
-
optimization.py
|
|
6
|
-
pyproject.toml
|
|
7
|
-
models/__init__.py
|
|
8
|
-
models/branch.py
|
|
9
|
-
models/bus.py
|
|
10
|
-
models/case.py
|
|
11
|
-
models/csc.py
|
|
12
|
-
models/generator.py
|
|
13
|
-
models/hvdc_lcc.py
|
|
14
|
-
models/network_reduction.py
|
|
15
|
-
models/shunt.py
|
|
16
|
-
models/svc.py
|
|
17
|
-
models/transformer.py
|
|
18
|
-
pf_tool.egg-info/PKG-INFO
|
|
19
|
-
pf_tool.egg-info/SOURCES.txt
|
|
20
|
-
pf_tool.egg-info/dependency_links.txt
|
|
21
|
-
pf_tool.egg-info/requires.txt
|
|
22
|
-
pf_tool.egg-info/top_level.txt
|
|
23
|
-
tests/test_exporter.py
|
|
24
|
-
tests/test_newton_raphson.py
|
|
25
|
-
tests/test_optimization.py
|
|
26
|
-
utils/__init__.py
|
|
27
|
-
utils/dat_parser.py
|
|
28
|
-
utils/network.py
|
|
29
|
-
utils/utils.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|