fpowerkit 0.5.0__tar.gz → 0.5.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 (37) hide show
  1. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/PKG-INFO +2 -2
  2. fpowerkit-0.5.2/bench_parameter_reuse.py +42 -0
  3. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/bus.py +183 -183
  4. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/gen.py +2 -0
  5. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/grid.py +576 -562
  6. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/lpwrapper.py +396 -375
  7. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/solbase.py +3 -2
  8. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/solcmb.py +1 -1
  9. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/soldcopf.py +1 -0
  10. fpowerkit-0.5.2/fpowerkit/soldist.py +823 -0
  11. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/solldf.py +216 -178
  12. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/solldf2.py +190 -165
  13. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/pyproject.toml +1 -1
  14. fpowerkit-0.5.0/fpowerkit/fpowerkit.md +0 -5211
  15. fpowerkit-0.5.0/fpowerkit/soldist.py +0 -325
  16. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/.gitignore +0 -0
  17. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/LICENSE +0 -0
  18. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/README.md +0 -0
  19. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/desc.md +0 -0
  20. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/__init__.py +0 -0
  21. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/cases.py +0 -0
  22. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/comb.py +0 -0
  23. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/ess.py +0 -0
  24. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/island.py +0 -0
  25. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/line.py +0 -0
  26. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/pvwind.py +0 -0
  27. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/solcvx.py +0 -0
  28. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/soldc.py +0 -0
  29. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/soldss.py +0 -0
  30. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/solnt.py +0 -0
  31. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/solpq.py +0 -0
  32. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/solsw.py +0 -0
  33. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/fpowerkit/utils.py +0 -0
  34. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/main.py +0 -0
  35. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/test.py +0 -0
  36. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/test314t.py +0 -0
  37. {fpowerkit-0.5.0 → fpowerkit-0.5.2}/test_cmb.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: fpowerkit
3
- Version: 0.5.0
3
+ Version: 0.5.2
4
4
  Summary: A PDN solver with multiple solutions.
5
5
  Author: fmy-xfk
6
6
  License-Expression: BSD-3-Clause
@@ -0,0 +1,42 @@
1
+ """Small smoke benchmark for the parameterized fpowerkit package.
2
+
3
+ Run from the directory containing the modified `fpowerkit` package, e.g.:
4
+ python bench_parameter_reuse.py --solver ECOS --n 20
5
+ """
6
+ from __future__ import annotations
7
+
8
+ import argparse
9
+ import statistics
10
+ import time
11
+
12
+ from fpowerkit import PDNCases, DistFlowSolver
13
+
14
+
15
+ def main() -> None:
16
+ ap = argparse.ArgumentParser()
17
+ ap.add_argument("--solver", default="ECOS")
18
+ ap.add_argument("--n", type=int, default=20)
19
+ args = ap.parse_args()
20
+
21
+ grid = PDNCases.IEEE33(changeable_load=True)
22
+ solver = DistFlowSolver(grid, solver=args.solver)
23
+
24
+ times = []
25
+ for k in range(args.n):
26
+ t = (k * 900) % 86400
27
+ tic = time.perf_counter()
28
+ status, obj = solver.solve(t)
29
+ dt = time.perf_counter() - tic
30
+ times.append(dt)
31
+ print(f"k={k:02d} t={t:5d} status={status!s:>12} obj={obj:12.6g} "
32
+ f"wall={dt:.6f}s builds={solver.CVXBuildCount}")
33
+
34
+ if len(times) > 1:
35
+ print("\nfirst solve: ", times[0])
36
+ print("median later: ", statistics.median(times[1:]))
37
+ print("mean later: ", statistics.mean(times[1:]))
38
+ print("CVX build count: ", solver.CVXBuildCount)
39
+
40
+
41
+ if __name__ == "__main__":
42
+ main()
@@ -1,184 +1,184 @@
1
- import math
2
- from typing import Optional, Any, Tuple
3
- from xml.etree.ElementTree import Element
4
- from feasytools import TimeFunc
5
- from .utils import *
6
-
7
-
8
- class Bus(PositionBase):
9
- Pd: TimeFunc # pu
10
- Qd: TimeFunc # pu
11
- ShadowPrice: FloatVar # Shadow price of generators on this bus,$/pu power
12
-
13
- def __init__(self, id: str, pd_pu: FloatLike, qd_pu: FloatLike, x: float, y: float, proj:Optional[Any] = None,
14
- v_pu: NFloat = None, min_v_pu: float = 0.0, max_v_pu: float = float('inf'), theta: NFloat = None):
15
- '''
16
- Initialize
17
- id: Bus ID
18
- pd_pu: Active power demand, pu
19
- qd_pu: Reactive power demand, pu
20
- x: X coordinate (for plotting)
21
- y: Y coordinate (for plotting)
22
- v_pu: Voltage, pu. None for unfixed voltage
23
- min_v_pu: Minimal voltage, pu
24
- max_v_pu: Maximal voltage, pu
25
- '''
26
- super().__init__(x, y, proj)
27
- self._id = id
28
- self._v = v_pu
29
- self._fixed_v = v_pu is not None
30
- self._minv = min_v_pu
31
- self._maxv = max_v_pu
32
- self.Pd = Float2Func(pd_pu)
33
- self.Qd = Float2Func(qd_pu)
34
- self.ShadowPrice = None
35
- self._t = theta
36
- self._fixed_t = self._t is not None
37
-
38
- def V_var(self, bank: VarBank):
39
- if self.FixedV:
40
- raise ValueError("Voltage is fixed, cannot create a variable for it.")
41
- return bank.fvar(f"{self.ID}_V", self, "_v", self.V, nonneg=True, lb=self.MinV, ub=self.MaxV)
42
-
43
- def V2_var(self, bank: VarBank):
44
- if self.FixedV:
45
- raise ValueError("Voltage is fixed, cannot create a variable for it.")
46
- v = self.V if self.V is not None else 1.0
47
- return bank.fvar(f"{self.ID}_V2", self, "_v", v**2, nonneg=True,
48
- lb=self.MinV**2, ub=self.MaxV**2, reflect=lambda x: math.sqrt(x))
49
-
50
- def theta_var(self, bank: VarBank):
51
- if self.FixedTheta:
52
- raise ValueError("Voltage angle is fixed, cannot create a variable for it.")
53
- return bank.fvar(f"{self.ID}_theta", self, "_theta", self._t)
54
-
55
- @property
56
- def V(self) -> FloatVar:
57
- '''Voltage, pu'''
58
- return self._v
59
- @V.setter
60
- def V(self, v: float):
61
- self._v = v
62
-
63
- @property
64
- def theta(self) -> float:
65
- '''Voltage angle, rad'''
66
- return self._t if self._t is not None else 0.0
67
- @theta.setter
68
- def theta(self, t: float):
69
- self._t = t
70
-
71
- @property
72
- def V_cpx(self) -> Optional[complex]:
73
- if self._v is None or self._t is None: return None
74
- return self._v * math.cos(self._t) + 1j * self._v * math.sin(self._t)
75
-
76
- @property
77
- def FixedV(self) -> bool:
78
- '''Whether the voltage is fixed'''
79
- return self._fixed_v
80
-
81
- def fixV(self, v: float):
82
- '''Fix the voltage'''
83
- self._v = v
84
- self._fixed_v = True
85
-
86
- def unfixV(self):
87
- self._v = None
88
- self._fixed_v = False
89
-
90
- @property
91
- def FixedTheta(self) -> bool:
92
- '''Whether the voltage angle is fixed'''
93
- return self._fixed_t
94
-
95
- def fixTheta(self, theta: float):
96
- '''Fix the voltage angle'''
97
- self._t = theta
98
- self._fixed_t = True
99
-
100
- def unfixTheta(self):
101
- '''Unfix the voltage angle'''
102
- self._t = None
103
- self._fixed_t = False
104
-
105
- @property
106
- def ID(self) -> str:
107
- '''Name of the bus'''
108
- return self._id
109
-
110
- @property
111
- def MinV(self) -> float:
112
- '''Minimal voltage, pu'''
113
- return self._minv
114
- @MinV.setter
115
- def MinV(self, v: float):
116
- assert v >= 0 and v <= self._maxv, "MinV should be in [0, MaxV]"
117
- self._minv = v
118
-
119
- @property
120
- def MaxV(self) -> float:
121
- '''Maximal voltage, pu'''
122
- return self._maxv
123
- @MaxV.setter
124
- def MaxV(self, v: float):
125
- assert v >= self._minv, "MaxV should be no less than MinV"
126
- self._maxv = v
127
-
128
- def setVRange(self, min_v: float, max_v: float):
129
- assert 0 <= min_v <= max_v, "MinV should be in [0, MaxV]"
130
- self._minv = min_v
131
- self._maxv = max_v
132
-
133
- def __repr__(self):
134
- return f"Bus(id='{self.ID}', v_pu={self.V}, pd_pu={self.Pd}, qd_pu={self.Qd}, " + \
135
- f"x={self.x}, y={self.y}, min_v_pu={self.MinV}, max_v_pu={self.MaxV})"
136
-
137
- def __str__(self):
138
- return repr(self)
139
-
140
- def str_t(self, _t: int, /):
141
- return f"Bus(id='{self.ID}', v_pu={FVstr(self.V)}, pd_pu={self.Pd(_t)}, qd_pu={self.Qd(_t)}, " + \
142
- f"x={self.x}, y={self.y}, min_v_pu={self.MinV}, max_v_pu={self.MaxV})"
143
-
144
- @staticmethod
145
- def fromXML(node: Element, Sb_MVA: float, Ub_kV: float, proj:Optional[Any] = None) -> 'Bus':
146
- id = node.attrib["ID"]
147
- p = ReadFloatLike(node.find("Pd"), Sb_MVA, Ub_kV)
148
- q = ReadFloatLike(node.find("Qd"), Sb_MVA, Ub_kV)
149
- x, y = PositionBase.load_pos_from_xml(node, proj)
150
- if "V" in node.attrib:
151
- v = ReadConst(node.attrib["V"], Sb_MVA, Ub_kV)
152
- minv = maxv = v
153
- else:
154
- minv = ReadConst(node.attrib.get("MinV",'0.8pu'), Sb_MVA, Ub_kV)
155
- maxv = ReadConst(node.attrib.get("MaxV",'1.2pu'), Sb_MVA, Ub_kV)
156
- v = None
157
- return Bus(id, p, q, x, y, proj, v, minv, maxv)
158
-
159
- def toXMLNode(self, Ub_kV:Optional[float] = None,
160
- Sb_MVA:Optional[float] = None, Sb_kVA:Optional[float] = None) -> 'Element':
161
- e = Element("bus", {"ID": self.ID})
162
- if self.x is not None: e.attrib["x"] = f"{self.x:.6f}"
163
- if self.y is not None: e.attrib["y"] = f"{self.y:.6f}"
164
- if self.V is not None and self.FixedV:
165
- e.attrib["V"] = str(self.V * Ub_kV)+"kV" if Ub_kV else str(self.V)
166
- else:
167
- e.attrib["MinV"] = str(self.MinV * Ub_kV)+"kV" if Ub_kV else str(self.MinV)
168
- e.attrib["MaxV"] = str(self.MaxV * Ub_kV)+"kV" if Ub_kV else str(self.MaxV)
169
- if Sb_MVA is not None and Sb_kVA is not None:
170
- raise ValueError("Provide only ONE of Sb_MVA or Sb_kVA.")
171
- if Sb_MVA is not None:
172
- mul = Sb_MVA
173
- unit = ["MW", "Mvar"]
174
- elif Sb_kVA is not None:
175
- mul = Sb_kVA
176
- unit = ["kW", "kvar"]
177
- else:
178
- mul = 1
179
- unit = ["pu", "pu"]
180
- e.append(Func2Elem(self.Pd, "Pd", mul, unit[0]))
181
- e.append(Func2Elem(self.Qd, "Qd", mul, unit[1]))
182
- return e
183
-
1
+ import math
2
+ from typing import Optional, Any, Tuple
3
+ from xml.etree.ElementTree import Element
4
+ from feasytools import TimeFunc
5
+ from .utils import *
6
+
7
+
8
+ class Bus(PositionBase):
9
+ Pd: TimeFunc # pu
10
+ Qd: TimeFunc # pu
11
+ ShadowPrice: FloatVar # Marginal objective cost of +1 pu active demand at this bus, $/(pu power*h)
12
+
13
+ def __init__(self, id: str, pd_pu: FloatLike, qd_pu: FloatLike, x: float, y: float, proj:Optional[Any] = None,
14
+ v_pu: NFloat = None, min_v_pu: float = 0.0, max_v_pu: float = float('inf'), theta: NFloat = None):
15
+ '''
16
+ Initialize
17
+ id: Bus ID
18
+ pd_pu: Active power demand, pu
19
+ qd_pu: Reactive power demand, pu
20
+ x: X coordinate (for plotting)
21
+ y: Y coordinate (for plotting)
22
+ v_pu: Voltage, pu. None for unfixed voltage
23
+ min_v_pu: Minimal voltage, pu
24
+ max_v_pu: Maximal voltage, pu
25
+ '''
26
+ super().__init__(x, y, proj)
27
+ self._id = id
28
+ self._v = v_pu
29
+ self._fixed_v = v_pu is not None
30
+ self._minv = min_v_pu
31
+ self._maxv = max_v_pu
32
+ self.Pd = Float2Func(pd_pu)
33
+ self.Qd = Float2Func(qd_pu)
34
+ self.ShadowPrice = None
35
+ self._t = theta
36
+ self._fixed_t = self._t is not None
37
+
38
+ def V_var(self, bank: VarBank):
39
+ if self.FixedV:
40
+ raise ValueError("Voltage is fixed, cannot create a variable for it.")
41
+ return bank.fvar(f"{self.ID}_V", self, "_v", self.V, nonneg=True, lb=self.MinV, ub=self.MaxV)
42
+
43
+ def V2_var(self, bank: VarBank):
44
+ if self.FixedV:
45
+ raise ValueError("Voltage is fixed, cannot create a variable for it.")
46
+ v = self.V if self.V is not None else 1.0
47
+ return bank.fvar(f"{self.ID}_V2", self, "_v", v**2, nonneg=True,
48
+ lb=self.MinV**2, ub=self.MaxV**2, reflect=lambda x: math.sqrt(x))
49
+
50
+ def theta_var(self, bank: VarBank):
51
+ if self.FixedTheta:
52
+ raise ValueError("Voltage angle is fixed, cannot create a variable for it.")
53
+ return bank.fvar(f"{self.ID}_theta", self, "_theta", self._t)
54
+
55
+ @property
56
+ def V(self) -> FloatVar:
57
+ '''Voltage, pu'''
58
+ return self._v
59
+ @V.setter
60
+ def V(self, v: float):
61
+ self._v = v
62
+
63
+ @property
64
+ def theta(self) -> float:
65
+ '''Voltage angle, rad'''
66
+ return self._t if self._t is not None else 0.0
67
+ @theta.setter
68
+ def theta(self, t: float):
69
+ self._t = t
70
+
71
+ @property
72
+ def V_cpx(self) -> Optional[complex]:
73
+ if self._v is None or self._t is None: return None
74
+ return self._v * math.cos(self._t) + 1j * self._v * math.sin(self._t)
75
+
76
+ @property
77
+ def FixedV(self) -> bool:
78
+ '''Whether the voltage is fixed'''
79
+ return self._fixed_v
80
+
81
+ def fixV(self, v: float):
82
+ '''Fix the voltage'''
83
+ self._v = v
84
+ self._fixed_v = True
85
+
86
+ def unfixV(self):
87
+ self._v = None
88
+ self._fixed_v = False
89
+
90
+ @property
91
+ def FixedTheta(self) -> bool:
92
+ '''Whether the voltage angle is fixed'''
93
+ return self._fixed_t
94
+
95
+ def fixTheta(self, theta: float):
96
+ '''Fix the voltage angle'''
97
+ self._t = theta
98
+ self._fixed_t = True
99
+
100
+ def unfixTheta(self):
101
+ '''Unfix the voltage angle'''
102
+ self._t = None
103
+ self._fixed_t = False
104
+
105
+ @property
106
+ def ID(self) -> str:
107
+ '''Name of the bus'''
108
+ return self._id
109
+
110
+ @property
111
+ def MinV(self) -> float:
112
+ '''Minimal voltage, pu'''
113
+ return self._minv
114
+ @MinV.setter
115
+ def MinV(self, v: float):
116
+ assert v >= 0 and v <= self._maxv, "MinV should be in [0, MaxV]"
117
+ self._minv = v
118
+
119
+ @property
120
+ def MaxV(self) -> float:
121
+ '''Maximal voltage, pu'''
122
+ return self._maxv
123
+ @MaxV.setter
124
+ def MaxV(self, v: float):
125
+ assert v >= self._minv, "MaxV should be no less than MinV"
126
+ self._maxv = v
127
+
128
+ def setVRange(self, min_v: float, max_v: float):
129
+ assert 0 <= min_v <= max_v, "MinV should be in [0, MaxV]"
130
+ self._minv = min_v
131
+ self._maxv = max_v
132
+
133
+ def __repr__(self):
134
+ return f"Bus(id='{self.ID}', v_pu={self.V}, pd_pu={self.Pd}, qd_pu={self.Qd}, " + \
135
+ f"x={self.x}, y={self.y}, min_v_pu={self.MinV}, max_v_pu={self.MaxV})"
136
+
137
+ def __str__(self):
138
+ return repr(self)
139
+
140
+ def str_t(self, _t: int, /):
141
+ return f"Bus(id='{self.ID}', v_pu={FVstr(self.V)}, pd_pu={self.Pd(_t)}, qd_pu={self.Qd(_t)}, " + \
142
+ f"x={self.x}, y={self.y}, min_v_pu={self.MinV}, max_v_pu={self.MaxV})"
143
+
144
+ @staticmethod
145
+ def fromXML(node: Element, Sb_MVA: float, Ub_kV: float, proj:Optional[Any] = None) -> 'Bus':
146
+ id = node.attrib["ID"]
147
+ p = ReadFloatLike(node.find("Pd"), Sb_MVA, Ub_kV)
148
+ q = ReadFloatLike(node.find("Qd"), Sb_MVA, Ub_kV)
149
+ x, y = PositionBase.load_pos_from_xml(node, proj)
150
+ if "V" in node.attrib:
151
+ v = ReadConst(node.attrib["V"], Sb_MVA, Ub_kV)
152
+ minv = maxv = v
153
+ else:
154
+ minv = ReadConst(node.attrib.get("MinV",'0.8pu'), Sb_MVA, Ub_kV)
155
+ maxv = ReadConst(node.attrib.get("MaxV",'1.2pu'), Sb_MVA, Ub_kV)
156
+ v = None
157
+ return Bus(id, p, q, x, y, proj, v, minv, maxv)
158
+
159
+ def toXMLNode(self, Ub_kV:Optional[float] = None,
160
+ Sb_MVA:Optional[float] = None, Sb_kVA:Optional[float] = None) -> 'Element':
161
+ e = Element("bus", {"ID": self.ID})
162
+ if self.x is not None: e.attrib["x"] = f"{self.x:.6f}"
163
+ if self.y is not None: e.attrib["y"] = f"{self.y:.6f}"
164
+ if self.V is not None and self.FixedV:
165
+ e.attrib["V"] = str(self.V * Ub_kV)+"kV" if Ub_kV else str(self.V)
166
+ else:
167
+ e.attrib["MinV"] = str(self.MinV * Ub_kV)+"kV" if Ub_kV else str(self.MinV)
168
+ e.attrib["MaxV"] = str(self.MaxV * Ub_kV)+"kV" if Ub_kV else str(self.MaxV)
169
+ if Sb_MVA is not None and Sb_kVA is not None:
170
+ raise ValueError("Provide only ONE of Sb_MVA or Sb_kVA.")
171
+ if Sb_MVA is not None:
172
+ mul = Sb_MVA
173
+ unit = ["MW", "Mvar"]
174
+ elif Sb_kVA is not None:
175
+ mul = Sb_kVA
176
+ unit = ["kW", "kvar"]
177
+ else:
178
+ mul = 1
179
+ unit = ["pu", "pu"]
180
+ e.append(Func2Elem(self.Pd, "Pd", mul, unit[0]))
181
+ e.append(Func2Elem(self.Qd, "Qd", mul, unit[1]))
182
+ return e
183
+
184
184
  __all__ = ["Bus"]
@@ -14,6 +14,7 @@ class Generator(PositionBase):
14
14
  CostA: TimeFunc #$/(pu Power·h)**2
15
15
  CostB: TimeFunc #$/pu Power·h
16
16
  CostC: TimeFunc #$
17
+ QtoPRatio: Optional[float]
17
18
 
18
19
  def __init__(self, id: str, busid: str,
19
20
  costA: FloatLike, costB: FloatLike, costC: FloatLike,
@@ -74,6 +75,7 @@ class Generator(PositionBase):
74
75
  self.CostC = Float2Func(costC)
75
76
  self.CostShadow = None
76
77
  self.active = active
78
+ self.QtoPRatio = None
77
79
 
78
80
  def P_var(self, bank: VarBank, t:int = 0):
79
81
  '''Return a variable for the active power output'''