fpowerkit 0.2.2__tar.gz → 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/PKG-INFO +2 -2
  2. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/README.md +22 -38
  3. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit/cases.py +1 -1
  4. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit/ess.py +1 -1
  5. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit/grid.py +4 -3
  6. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit/line.py +4 -0
  7. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit/solbase.py +11 -0
  8. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit/soldist.py +11 -11
  9. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit/soldss.py +12 -12
  10. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit/solgcal.py +1 -9
  11. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit/solnt.py +7 -13
  12. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit/utils.py +1 -2
  13. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit.egg-info/PKG-INFO +2 -2
  14. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit.egg-info/requires.txt +1 -1
  15. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/setup.py +2 -2
  16. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/LICENSE +0 -0
  17. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit/__init__.py +0 -0
  18. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit/bus.py +0 -0
  19. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit/gen.py +0 -0
  20. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit/pvwind.py +0 -0
  21. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit/solcmb.py +0 -0
  22. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit.egg-info/SOURCES.txt +0 -0
  23. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit.egg-info/dependency_links.txt +0 -0
  24. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/fpowerkit.egg-info/top_level.txt +0 -0
  25. {fpowerkit-0.2.2 → fpowerkit-0.2.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: fpowerkit
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: A Distflow PDN solver based on Gurobi.
5
5
  Author: fmy_xfk
6
6
  Classifier: Programming Language :: Python :: 3
@@ -10,7 +10,7 @@ Requires-Python: >=3.8
10
10
  Description-Content-Type: text/markdown
11
11
  License-File: LICENSE
12
12
  Requires-Dist: feasytools>=0.0.21
13
- Requires-Dist: numpy>=1.20.0
13
+ Requires-Dist: numpy>=1.19.0
14
14
  Dynamic: author
15
15
  Dynamic: classifier
16
16
  Dynamic: description
@@ -1,6 +1,28 @@
1
1
  # FPowerKit 配电网运算组件
2
2
  **本仓库已上线PyPI**,您可以通过`pip install fpowerkit`直接以Python包的形式安装使用本仓库的代码!
3
3
 
4
+ ## 简介
5
+ - FPowerKit是一个配电网求解组件,它包含电网的描述(含母线、发电机、线路、光伏、风机和储能等)和多种内置和外部求解方案:
6
+ + (内置) 改进DistFlow配电网最优潮流
7
+ + (内置) Newton-Raphson潮流计算
8
+ + (外接) OpenDSS配电网潮流计算
9
+ + (外接) GridCal潮流计算(仅限较高版本的Python)
10
+ + 最优潮流+潮流计算核验的混合方案
11
+ - 对于最优潮流模型,优化目标为“发电成本最小”。发电成本模型为二次函数$f(x)=ax^2+bx+c$或者一次函数$f(x)=bx+c$。
12
+ - 依赖于feasytools和numpy: `pip install feasytools numpy`
13
+ - 内含IEEE 33节点配电网和IEEE 69节点配电网,可通过以下方式快速创建:
14
+ ```py
15
+ from fpowerkit import PDNCases
16
+ grid_obj33 = PDNCases.IEEE33()
17
+ grid_obj69 = PDNCases.IEEE69()
18
+ ```
19
+
20
+ ## 重要信息目录
21
+ + [FPowerKit文件格式](docs/xml_file.md)
22
+ + [在命令行中使用](docs/cmd.md)
23
+ + [从代码创建和求解电网](docs/develop.md)
24
+
25
+ ## 引用说明
4
26
  这个项目是[V2Sim](https://gitee.com/fmy_xfk/v2sim)的附属项目。V2Sim的论文请见如下链接
5
27
 
6
28
  - 正式版:https://ieeexplore.ieee.org/document/10970754
@@ -22,41 +44,3 @@
22
44
  ```
23
45
 
24
46
  IEEE33和IEEE69节点的配网数据从公开渠道收集。除配网数据以外,本仓库代码均遵循LGPL3.0协议使用。
25
-
26
- ## 简介
27
- - 依赖于feasytools和numpy: `pip install feasytools numpy`(请自行安装Gurobi并申请许可证)
28
- - 包含电网的描述(含母线、发电机、线路、光伏、风机和储能等)和改进配电网DistFlow模型求解。
29
- - 优化目标为“发电成本最小”。发电成本模型为二次函数$f(x)=ax^2+bx+c$或者一次函数$f(x)=bx+c$。
30
- - 内含IEEE 33节点配电网和IEEE 69节点配电网,可通过以下方式快速创建:
31
- ```py
32
- from fpowerkit import PDNCases
33
- grid_obj33 = PDNCases.IEEE33()
34
- grid_obj69 = PDNCases.IEEE69()
35
- ```
36
-
37
- ## 使用
38
-
39
- 克隆本仓库,并输入以下命令开始求解:
40
-
41
- ```bash
42
- python main.py -g cases/33base.xml
43
- ```
44
-
45
- 请注意上述命令不适用于pip安装的版本。
46
-
47
- `33base`描述了IEEE 33节点配电网模型。换成`3nodes`则是一个极简版3节点辐射形配电网模型,结构如下:
48
-
49
- ```
50
- G0 G1
51
- | |
52
- B0->B1->B2
53
- | |
54
- L1 L2
55
- ```
56
-
57
- 您也换成自己的配电网文件来求解,例如`python main.py -g path/to/your_case.xml`
58
-
59
- ## 配电网文件格式
60
- [XML格式](docs/xml_file.md)
61
-
62
- ZIP格式已经不再支持。
@@ -1,5 +1,5 @@
1
1
  from feasytools import SegFunc, ConstFunc
2
- from .grid import GeneratorModel, Grid, Bus, Line, Generator
2
+ from .grid import GeneratorModel, Grid, Bus, Line
3
3
 
4
4
  # IEEE33 kVA
5
5
  _IEEE33_LOAD = [
@@ -76,7 +76,7 @@ class ESS:
76
76
  '''Calculate reactive power'''
77
77
  return P * math.sqrt(1 - self._pf**2)
78
78
 
79
- def GetLoad(self, t: int, cprice:float, dprice:float) -> tuple[float, float]:
79
+ def GetLoad(self, t: int, cprice:float, dprice:float) -> 'tuple[float, float]':
80
80
  '''
81
81
  Get the power of the ESS. Return p+jq.
82
82
  p > 0 means the ESS is charging, and thus the ESS is treated as a load.
@@ -2,8 +2,7 @@ from enum import IntEnum
2
2
  import gzip
3
3
  from xml.etree.ElementTree import ElementTree
4
4
  import zipfile
5
- from io import BytesIO, TextIOWrapper
6
- from typing import Any, Iterable
5
+ from typing import Iterable
7
6
 
8
7
  import numpy as np
9
8
  from .bus import *
@@ -52,7 +51,7 @@ class Grid:
52
51
  return self.Sb / (self.Ub * (3 ** 0.5))
53
52
 
54
53
  def __init__(self, Sb_MVA: float, Ub_kV: float, buses: 'Iterable[Bus]', lines: 'Iterable[Line]',
55
- gens: 'Iterable[Generator]', pvws: 'Iterable[PVWind]', esss: 'Iterable[ESS]',
54
+ gens: 'Iterable[Generator]', pvws: 'Optional[Iterable[PVWind]]' = None, esss: 'Optional[Iterable[ESS]]' = None,
56
55
  cprice: FloatLike = 0, dprice: FloatLike = 0, holdShadowPrice: bool = False):
57
56
  '''
58
57
  Initialize
@@ -73,7 +72,9 @@ class Grid:
73
72
  self._buses = {bus.ID: bus for bus in self._busl}
74
73
  self._lines = {line.ID: line for line in lines}
75
74
  self._gens = {gen.ID: gen for gen in gens}
75
+ if pvws is None: pvws = []
76
76
  self._pvws = {pvw.ID: pvw for pvw in pvws}
77
+ if esss is None: esss = []
77
78
  self._esss = {ess.ID: ess for ess in esss}
78
79
  self._cp = Float2Func(cprice)
79
80
  self._dp = Float2Func(dprice)
@@ -81,8 +81,12 @@ class Line:
81
81
  t = node.attrib["To"]
82
82
  r, ru = ReadVal(node.attrib["R"])
83
83
  if ru.lower() == "ohm": r = float(r) / Zb_Ohm
84
+ elif ru.lower() in ["pu",""]: r = float(r)
85
+ else: raise ValueError(f"Unknown unit '{ru}' for R, only 'ohm','pu', and non-unit (treated as pu) are supported")
84
86
  x, xu = ReadVal(node.attrib["X"])
85
87
  if xu.lower() == "ohm": x = float(x) / Zb_Ohm
88
+ elif xu.lower() in ["pu",""]: x = float(x)
89
+ else: raise ValueError(f"Unknown unit '{xu}' for X, only 'ohm','pu', and non-unit (treated as pu) are supported")
86
90
  max_I = float(node.attrib.get("MaxIkA", math.inf))
87
91
  l = float(node.attrib.get("Length_km", -1))
88
92
  return Line(id, f, t, r, x, max_I_kA=max_I, length_km=l)
@@ -25,6 +25,17 @@ class SolverBase(ABC):
25
25
  self.saveto = path
26
26
  Path(path).mkdir(parents=True, exist_ok = True)
27
27
 
28
+ def _calc_line_params(self):
29
+ for l in self.grid.Lines:
30
+ vi = self.grid.Bus(l.fBus).V_cpx
31
+ vj = self.grid.Bus(l.tBus).V_cpx
32
+ assert vi is not None and vj is not None
33
+ i = (vi-vj)/l.Z
34
+ l.I = abs(i)
35
+ s = vi*i.conjugate()
36
+ l.P = s.real
37
+ l.Q = s.imag
38
+
28
39
  @abstractmethod
29
40
  def solve(self, grid:Grid, _t:int, /, **kwargs):
30
41
  raise NotImplementedError
@@ -16,13 +16,13 @@ class LoadReduceModule:
16
16
  Reduction: FloatVar = None
17
17
 
18
18
  class _Island:
19
- def __init__(self, g: Grid, buses: Iterable[BusID], cutlines: set[LineID]):
19
+ def __init__(self, g: Grid, buses: Iterable[BusID], cutlines: 'set[LineID]'):
20
20
  self.grid = g
21
- self.Buses: set[str] = set()
22
- self.Gens: set[str] = set()
23
- self.Lines: set[str] = set()
24
- self.PVWs: set[str] = set()
25
- self.ESSs: set[str] = set()
21
+ self.Buses: 'set[str]' = set()
22
+ self.Gens: 'set[str]' = set()
23
+ self.Lines: 'set[str]' = set()
24
+ self.PVWs: 'set[str]' = set()
25
+ self.ESSs: 'set[str]' = set()
26
26
  for b in buses:
27
27
  self.Buses.add(b)
28
28
  self.Gens.update(gen.ID for gen in g._gatb[b])
@@ -103,13 +103,13 @@ class DistFlowSolver(SolverBase):
103
103
 
104
104
  def __detect_islands(self, cutofl: bool):
105
105
  '''Detect islands'''
106
- q: deque[BusID] = deque()
107
- visited: set[BusID] = set()
108
- islands: list[set[BusID]] = []
106
+ q: 'deque[BusID]' = deque()
107
+ visited: 'set[BusID]' = set()
108
+ islands: 'list[set[BusID]]' = []
109
109
  for bus in self.grid.BusNames:
110
110
  if bus in visited: continue
111
111
  q.append(bus)
112
- island: set[BusID] = set()
112
+ island: 'set[BusID]' = set()
113
113
  while len(q) > 0:
114
114
  b = q.popleft()
115
115
  if b in visited: continue
@@ -217,7 +217,7 @@ class DistFlowSolver(SolverBase):
217
217
  from cvxpy import Variable as Var
218
218
  except ImportError:
219
219
  raise ImportError("cvxpy or ecos is not installed. Please install them using 'pip install cvxpy ecos'")
220
- cons:list[cp.Constraint] = []
220
+ cons: 'list[cp.Constraint]' = []
221
221
  # Create GEN vars
222
222
  pg0: 'dict[str, VF]' = {}
223
223
  qg0: 'dict[str, VF]' = {}
@@ -10,7 +10,10 @@ class OpenDSSSolver(SolverBase):
10
10
  raise ImportError("py_dss_interface or OpenDSS is not installed. Please install OpenDSS first and then py_dss_interface using 'pip install py_dss_interface'")
11
11
  self._g = grid
12
12
  t = init_t
13
- d = DSS()
13
+ try:
14
+ d = DSS()
15
+ except:
16
+ d = DSS.DSSDLL()
14
17
  d.text("clear")
15
18
  cir = f"new circuit.my_circuit basekv={grid.Ub} pu=1 MVASC3=5000000 5000000 bus1={source_bus}"
16
19
  self.source_bus = source_bus
@@ -82,8 +85,12 @@ class OpenDSSSolver(SolverBase):
82
85
  self.dss.text(f"set Voltagebases=[{self.grid.Ub}]")
83
86
  self.dss.text("calcv")
84
87
  self.dss.text("solve maxcontrol=10000")
85
- bnames = self.dss.circuit.buses_names
86
- bvolt = np.array(self.dss.circuit.buses_volts).reshape(-1, 3, 2)
88
+ if hasattr(self.dss, "circuit"):
89
+ bnames = self.dss.circuit.buses_names
90
+ bvolt = np.array(self.dss.circuit.buses_volts).reshape(-1, 3, 2)
91
+ else:
92
+ bnames = self.dss.circuit_all_bus_names()
93
+ bvolt = np.array(self.dss.circuit_all_bus_volts()).reshape(-1, 3, 2)
87
94
  sb_theta = 0
88
95
  for i, bn in enumerate(bnames):
89
96
  v1 = bvolt[i,0][0] + 1j * bvolt[i,0][1]
@@ -98,13 +105,6 @@ class OpenDSSSolver(SolverBase):
98
105
  for i, bn in enumerate(bnames):
99
106
  self.grid.Bus(bn).theta -= sb_theta
100
107
 
101
- for l in self.grid.Lines:
102
- vi = self.grid.Bus(l.fBus).V_cpx
103
- vj = self.grid.Bus(l.tBus).V_cpx
104
- assert vi is not None and vj is not None
105
- i = (vi-vj)/l.Z
106
- l.I = abs(i)
107
- s = vi*i.conjugate()
108
- l.P = s.real
109
- l.Q = s.imag
108
+ self._calc_line_params()
109
+
110
110
  return GridSolveResult.OK, 0.0
@@ -119,14 +119,6 @@ class GridCalSolver(SolverBase):
119
119
  assert isinstance(angle, (float, np.floating)), f"Bus {bn} angle is not a float: {type(angle)}"
120
120
  b.theta = float(angle) / 180 * math.pi
121
121
 
122
- for l in self.grid.Lines:
123
- vi = self.grid.Bus(l.fBus).V_cpx
124
- vj = self.grid.Bus(l.tBus).V_cpx
125
- assert vi is not None and vj is not None
126
- i = (vi-vj)/l.Z
127
- l.I = abs(i)
128
- s = vi*i.conjugate()
129
- l.P = s.real
130
- l.Q = s.imag
122
+ self._calc_line_params()
131
123
 
132
124
  return GridSolveResult.OK, 0.0
@@ -16,10 +16,10 @@ class NewtonSolver(SolverBase):
16
16
 
17
17
  def CheckBusType(self, _t:int):
18
18
  '''Check the bus type'''
19
- busType:dict[BusID, BusType] = {}
19
+ busType: 'dict[BusID, BusType]' = {}
20
20
  slack_cnt = 0
21
- eq_P:list[int] = []
22
- eq_Q:list[int] = []
21
+ eq_P: 'list[int]' = []
22
+ eq_Q: 'list[int]' = []
23
23
  self.Ps = []
24
24
  self.Qs = []
25
25
  for i, bus in enumerate(self.grid._busl):
@@ -107,7 +107,7 @@ class NewtonSolver(SolverBase):
107
107
 
108
108
  def _solve(self) -> int:
109
109
  cnt = 0
110
- while cnt<self.max_iter:
110
+ while cnt < self.max_iter:
111
111
  y = np.zeros(self.n, dtype=np.float64)
112
112
  for i, b in enumerate(self.eqs):
113
113
  y[i] = self.Ps[b] - self.P(b) if i < self.n_P else self.Qs[b] - self.Q(b)
@@ -144,13 +144,7 @@ class NewtonSolver(SolverBase):
144
144
  self._solve()
145
145
  except ValueError:
146
146
  return GridSolveResult.Failed, -1
147
- for l in self.grid.Lines:
148
- vi = self.grid.Bus(l.fBus).V_cpx
149
- vj = self.grid.Bus(l.tBus).V_cpx
150
- assert vi is not None and vj is not None
151
- i = (vi-vj)/l.Z
152
- l.I = abs(i)
153
- s = vi*i.conjugate()
154
- l.P = s.real
155
- l.Q = s.imag
147
+
148
+ self._calc_line_params()
149
+
156
150
  return GridSolveResult.OK, 0
@@ -1,7 +1,6 @@
1
1
  from typing import Optional, Union
2
- from feasytools import TimeFunc, SegFunc, ConstFunc, makeFunc
2
+ from feasytools import TimeFunc, SegFunc, ConstFunc
3
3
  from xml.etree.ElementTree import Element
4
- from typing import TextIO
5
4
 
6
5
 
7
6
  FloatVar = Optional[float]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: fpowerkit
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: A Distflow PDN solver based on Gurobi.
5
5
  Author: fmy_xfk
6
6
  Classifier: Programming Language :: Python :: 3
@@ -10,7 +10,7 @@ Requires-Python: >=3.8
10
10
  Description-Content-Type: text/markdown
11
11
  License-File: LICENSE
12
12
  Requires-Dist: feasytools>=0.0.21
13
- Requires-Dist: numpy>=1.20.0
13
+ Requires-Dist: numpy>=1.19.0
14
14
  Dynamic: author
15
15
  Dynamic: classifier
16
16
  Dynamic: description
@@ -1,2 +1,2 @@
1
1
  feasytools>=0.0.21
2
- numpy>=1.20.0
2
+ numpy>=1.19.0
@@ -5,7 +5,7 @@ with open("desc.md", "r", encoding="utf8") as f:
5
5
 
6
6
  setup(
7
7
  name="fpowerkit",
8
- version="0.2.2",
8
+ version="0.2.3",
9
9
  author="fmy_xfk",
10
10
  packages=find_packages(),
11
11
  description="A Distflow PDN solver based on Gurobi.",
@@ -17,5 +17,5 @@ setup(
17
17
  "Operating System :: OS Independent",
18
18
  ],
19
19
  python_requires=">=3.8",
20
- install_requires=["feasytools>=0.0.21", "numpy>=1.20.0"],
20
+ install_requires=["feasytools>=0.0.21", "numpy>=1.19.0"],
21
21
  )
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes