pf-tool 0.2.0__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.
Files changed (38) hide show
  1. pf_tool-0.2.2/PKG-INFO +115 -0
  2. pf_tool-0.2.2/README.md +102 -0
  3. {pf_tool-0.2.0 → pf_tool-0.2.2}/pyproject.toml +9 -12
  4. pf_tool-0.2.2/src/pf_tool/__init__.py +21 -0
  5. {pf_tool-0.2.0 → pf_tool-0.2.2/src/pf_tool}/exporter.py +9 -7
  6. pf_tool-0.2.2/src/pf_tool/models/__init__.py +7 -0
  7. {pf_tool-0.2.0 → pf_tool-0.2.2/src/pf_tool}/models/case.py +6 -6
  8. {pf_tool-0.2.0 → pf_tool-0.2.2/src/pf_tool}/models/csc.py +1 -1
  9. {pf_tool-0.2.0 → pf_tool-0.2.2/src/pf_tool}/models/hvdc_lcc.py +1 -1
  10. {pf_tool-0.2.0 → pf_tool-0.2.2/src/pf_tool}/models/network_reduction.py +4 -4
  11. {pf_tool-0.2.0 → pf_tool-0.2.2/src/pf_tool}/models/shunt.py +1 -1
  12. {pf_tool-0.2.0 → pf_tool-0.2.2/src/pf_tool}/models/svc.py +2 -2
  13. {pf_tool-0.2.0 → pf_tool-0.2.2/src/pf_tool}/models/transformer.py +4 -4
  14. {pf_tool-0.2.0 → pf_tool-0.2.2/src/pf_tool}/newton_raphson.py +13 -18
  15. {pf_tool-0.2.0 → pf_tool-0.2.2/src/pf_tool}/optimization.py +31 -20
  16. {pf_tool-0.2.0 → pf_tool-0.2.2/src/pf_tool}/utils/network.py +2 -2
  17. {pf_tool-0.2.0 → pf_tool-0.2.2/src/pf_tool}/utils/utils.py +9 -9
  18. pf_tool-0.2.2/src/pf_tool.egg-info/PKG-INFO +115 -0
  19. pf_tool-0.2.2/src/pf_tool.egg-info/SOURCES.txt +30 -0
  20. pf_tool-0.2.2/src/pf_tool.egg-info/top_level.txt +1 -0
  21. {pf_tool-0.2.0 → pf_tool-0.2.2}/tests/test_exporter.py +5 -5
  22. {pf_tool-0.2.0 → pf_tool-0.2.2}/tests/test_newton_raphson.py +12 -12
  23. {pf_tool-0.2.0 → pf_tool-0.2.2}/tests/test_optimization.py +15 -5
  24. pf_tool-0.2.0/PKG-INFO +0 -304
  25. pf_tool-0.2.0/README.md +0 -291
  26. pf_tool-0.2.0/models/__init__.py +0 -7
  27. pf_tool-0.2.0/pf_tool.egg-info/PKG-INFO +0 -304
  28. pf_tool-0.2.0/pf_tool.egg-info/SOURCES.txt +0 -29
  29. pf_tool-0.2.0/pf_tool.egg-info/top_level.txt +0 -5
  30. {pf_tool-0.2.0 → pf_tool-0.2.2}/LICENSE.txt +0 -0
  31. {pf_tool-0.2.0 → pf_tool-0.2.2}/setup.cfg +0 -0
  32. {pf_tool-0.2.0 → pf_tool-0.2.2/src/pf_tool}/models/branch.py +0 -0
  33. {pf_tool-0.2.0 → pf_tool-0.2.2/src/pf_tool}/models/bus.py +0 -0
  34. {pf_tool-0.2.0 → pf_tool-0.2.2/src/pf_tool}/models/generator.py +0 -0
  35. {pf_tool-0.2.0 → pf_tool-0.2.2/src/pf_tool}/utils/__init__.py +0 -0
  36. {pf_tool-0.2.0 → pf_tool-0.2.2/src/pf_tool}/utils/dat_parser.py +0 -0
  37. {pf_tool-0.2.0 → pf_tool-0.2.2/src}/pf_tool.egg-info/dependency_links.txt +0 -0
  38. {pf_tool-0.2.0 → 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).
@@ -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.0"
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
- packages = ["models", "utils"]
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
- solver = NewtonRaphsonPowerFlow("tests/data/CASO01-FLOW.dat")
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)
@@ -2,7 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from models.branch import Branch
5
+ from pf_tool.models.branch import Branch
6
6
 
7
7
  # Series reactance (pu) used for a bypassed compensator; network reduction
8
8
  # contracts it into a single electrical node.
@@ -10,7 +10,7 @@ from typing import TYPE_CHECKING
10
10
  import numpy as np
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)
@@ -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
@@ -6,7 +6,7 @@ from dataclasses import dataclass, field
6
6
  from typing import TYPE_CHECKING
7
7
 
8
8
  if TYPE_CHECKING:
9
- from models.case import PowerFlowCase
9
+ from pf_tool.models.case import PowerFlowCase
10
10
 
11
11
 
12
12
  @dataclass(slots=True)
@@ -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
- The input is the AMPL-style block export used by ``tests/data/*.dat``. The
80
- constructor accepts an alternate case path for other exports in the same
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 | None = None,
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
- solver = SolverFactory("ipopt")
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 an Ipopt executable and ensure it is on PATH."
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 | None = None,
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: