ltbams 0.9.9__py3-none-any.whl → 1.0.2__py3-none-any.whl

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 (191) hide show
  1. ams/__init__.py +4 -11
  2. ams/_version.py +3 -3
  3. ams/cases/5bus/pjm5bus_demo.xlsx +0 -0
  4. ams/cases/5bus/pjm5bus_jumper.xlsx +0 -0
  5. ams/cases/5bus/pjm5bus_uced.json +1062 -0
  6. ams/cases/5bus/pjm5bus_uced.xlsx +0 -0
  7. ams/cases/5bus/pjm5bus_uced_esd1.xlsx +0 -0
  8. ams/cases/5bus/pjm5bus_uced_ev.xlsx +0 -0
  9. ams/cases/ieee123/ieee123.xlsx +0 -0
  10. ams/cases/ieee123/ieee123_regcv1.xlsx +0 -0
  11. ams/cases/ieee14/ieee14.json +1166 -0
  12. ams/cases/ieee14/ieee14.raw +92 -0
  13. ams/cases/ieee14/ieee14_conn.xlsx +0 -0
  14. ams/cases/ieee14/ieee14_uced.xlsx +0 -0
  15. ams/cases/ieee39/ieee39.xlsx +0 -0
  16. ams/cases/ieee39/ieee39_uced.xlsx +0 -0
  17. ams/cases/ieee39/ieee39_uced_esd1.xlsx +0 -0
  18. ams/cases/ieee39/ieee39_uced_pvd1.xlsx +0 -0
  19. ams/cases/ieee39/ieee39_uced_vis.xlsx +0 -0
  20. ams/cases/matpower/benchmark.json +1594 -0
  21. ams/cases/matpower/case118.m +787 -0
  22. ams/cases/matpower/case14.m +129 -0
  23. ams/cases/matpower/case300.m +1315 -0
  24. ams/cases/matpower/case39.m +205 -0
  25. ams/cases/matpower/case5.m +62 -0
  26. ams/cases/matpower/case_ACTIVSg2000.m +9460 -0
  27. ams/cases/npcc/npcc.m +644 -0
  28. ams/cases/npcc/npcc_uced.xlsx +0 -0
  29. ams/cases/pglib/pglib_opf_case39_epri__api.m +243 -0
  30. ams/cases/wecc/wecc.m +714 -0
  31. ams/cases/wecc/wecc_uced.xlsx +0 -0
  32. ams/cli.py +6 -0
  33. ams/core/__init__.py +2 -0
  34. ams/core/documenter.py +652 -0
  35. ams/core/matprocessor.py +782 -0
  36. ams/core/model.py +330 -0
  37. ams/core/param.py +322 -0
  38. ams/core/service.py +918 -0
  39. ams/core/symprocessor.py +224 -0
  40. ams/core/var.py +59 -0
  41. ams/extension/__init__.py +5 -0
  42. ams/extension/eva.py +401 -0
  43. ams/interface.py +1085 -0
  44. ams/io/__init__.py +133 -0
  45. ams/io/json.py +82 -0
  46. ams/io/matpower.py +406 -0
  47. ams/io/psse.py +6 -0
  48. ams/io/pypower.py +103 -0
  49. ams/io/xlsx.py +80 -0
  50. ams/main.py +81 -4
  51. ams/models/__init__.py +24 -0
  52. ams/models/area.py +40 -0
  53. ams/models/bus.py +52 -0
  54. ams/models/cost.py +169 -0
  55. ams/models/distributed/__init__.py +3 -0
  56. ams/models/distributed/esd1.py +71 -0
  57. ams/models/distributed/ev.py +60 -0
  58. ams/models/distributed/pvd1.py +67 -0
  59. ams/models/group.py +231 -0
  60. ams/models/info.py +26 -0
  61. ams/models/line.py +238 -0
  62. ams/models/renewable/__init__.py +5 -0
  63. ams/models/renewable/regc.py +119 -0
  64. ams/models/reserve.py +94 -0
  65. ams/models/shunt.py +14 -0
  66. ams/models/static/__init__.py +2 -0
  67. ams/models/static/gen.py +165 -0
  68. ams/models/static/pq.py +61 -0
  69. ams/models/timeslot.py +69 -0
  70. ams/models/zone.py +49 -0
  71. ams/opt/__init__.py +12 -0
  72. ams/opt/constraint.py +175 -0
  73. ams/opt/exprcalc.py +127 -0
  74. ams/opt/expression.py +188 -0
  75. ams/opt/objective.py +174 -0
  76. ams/opt/omodel.py +432 -0
  77. ams/opt/optzbase.py +192 -0
  78. ams/opt/param.py +156 -0
  79. ams/opt/var.py +233 -0
  80. ams/pypower/__init__.py +8 -0
  81. ams/pypower/_compat.py +9 -0
  82. ams/pypower/core/__init__.py +8 -0
  83. ams/pypower/core/pips.py +894 -0
  84. ams/pypower/core/ppoption.py +244 -0
  85. ams/pypower/core/ppver.py +18 -0
  86. ams/pypower/core/solver.py +2451 -0
  87. ams/pypower/eps.py +6 -0
  88. ams/pypower/idx.py +174 -0
  89. ams/pypower/io.py +604 -0
  90. ams/pypower/make/__init__.py +11 -0
  91. ams/pypower/make/matrices.py +665 -0
  92. ams/pypower/make/pdv.py +506 -0
  93. ams/pypower/routines/__init__.py +7 -0
  94. ams/pypower/routines/cpf.py +513 -0
  95. ams/pypower/routines/cpf_callbacks.py +114 -0
  96. ams/pypower/routines/opf.py +1803 -0
  97. ams/pypower/routines/opffcns.py +1946 -0
  98. ams/pypower/routines/pflow.py +852 -0
  99. ams/pypower/toggle.py +1098 -0
  100. ams/pypower/utils.py +293 -0
  101. ams/report.py +212 -50
  102. ams/routines/__init__.py +23 -0
  103. ams/routines/acopf.py +117 -0
  104. ams/routines/cpf.py +65 -0
  105. ams/routines/dcopf.py +241 -0
  106. ams/routines/dcpf.py +209 -0
  107. ams/routines/dcpf0.py +196 -0
  108. ams/routines/dopf.py +150 -0
  109. ams/routines/ed.py +312 -0
  110. ams/routines/pflow.py +255 -0
  111. ams/routines/pflow0.py +113 -0
  112. ams/routines/routine.py +1033 -0
  113. ams/routines/rted.py +519 -0
  114. ams/routines/type.py +160 -0
  115. ams/routines/uc.py +376 -0
  116. ams/shared.py +63 -9
  117. ams/system.py +61 -22
  118. ams/utils/__init__.py +3 -0
  119. ams/utils/misc.py +77 -0
  120. ams/utils/paths.py +257 -0
  121. docs/Makefile +21 -0
  122. docs/make.bat +35 -0
  123. docs/source/_templates/autosummary/base.rst +5 -0
  124. docs/source/_templates/autosummary/class.rst +35 -0
  125. docs/source/_templates/autosummary/module.rst +65 -0
  126. docs/source/_templates/autosummary/module_toctree.rst +66 -0
  127. docs/source/api.rst +102 -0
  128. docs/source/conf.py +206 -0
  129. docs/source/examples/index.rst +34 -0
  130. docs/source/genmodelref.py +61 -0
  131. docs/source/genroutineref.py +47 -0
  132. docs/source/getting_started/copyright.rst +20 -0
  133. docs/source/getting_started/formats/index.rst +20 -0
  134. docs/source/getting_started/formats/matpower.rst +183 -0
  135. docs/source/getting_started/formats/psse.rst +46 -0
  136. docs/source/getting_started/formats/pypower.rst +223 -0
  137. docs/source/getting_started/formats/xlsx.png +0 -0
  138. docs/source/getting_started/formats/xlsx.rst +23 -0
  139. docs/source/getting_started/index.rst +76 -0
  140. docs/source/getting_started/install.rst +231 -0
  141. docs/source/getting_started/overview.rst +26 -0
  142. docs/source/getting_started/testcase.rst +45 -0
  143. docs/source/getting_started/verification.rst +13 -0
  144. docs/source/images/curent.ico +0 -0
  145. docs/source/images/dcopf_time.png +0 -0
  146. docs/source/images/sponsors/CURENT_Logo_NameOnTrans.png +0 -0
  147. docs/source/images/sponsors/CURENT_Logo_Transparent.png +0 -0
  148. docs/source/images/sponsors/CURENT_Logo_Transparent_Name.png +0 -0
  149. docs/source/images/sponsors/doe.png +0 -0
  150. docs/source/index.rst +108 -0
  151. docs/source/modeling/example.rst +159 -0
  152. docs/source/modeling/index.rst +17 -0
  153. docs/source/modeling/model.rst +210 -0
  154. docs/source/modeling/routine.rst +122 -0
  155. docs/source/modeling/system.rst +51 -0
  156. docs/source/release-notes.rst +398 -0
  157. ltbams-1.0.2.dist-info/METADATA +215 -0
  158. ltbams-1.0.2.dist-info/RECORD +188 -0
  159. {ltbams-0.9.9.dist-info → ltbams-1.0.2.dist-info}/WHEEL +1 -1
  160. ltbams-1.0.2.dist-info/top_level.txt +3 -0
  161. tests/__init__.py +0 -0
  162. tests/test_1st_system.py +33 -0
  163. tests/test_addressing.py +40 -0
  164. tests/test_andes_mats.py +61 -0
  165. tests/test_case.py +266 -0
  166. tests/test_cli.py +34 -0
  167. tests/test_export_csv.py +89 -0
  168. tests/test_group.py +83 -0
  169. tests/test_interface.py +216 -0
  170. tests/test_io.py +32 -0
  171. tests/test_jumper.py +27 -0
  172. tests/test_known_good.py +267 -0
  173. tests/test_matp.py +437 -0
  174. tests/test_model.py +54 -0
  175. tests/test_omodel.py +119 -0
  176. tests/test_paths.py +22 -0
  177. tests/test_report.py +251 -0
  178. tests/test_repr.py +21 -0
  179. tests/test_routine.py +178 -0
  180. tests/test_rtn_dcopf.py +101 -0
  181. tests/test_rtn_dcpf.py +77 -0
  182. tests/test_rtn_ed.py +279 -0
  183. tests/test_rtn_pflow.py +219 -0
  184. tests/test_rtn_rted.py +273 -0
  185. tests/test_rtn_uc.py +248 -0
  186. tests/test_service.py +73 -0
  187. ltbams-0.9.9.dist-info/LICENSE +0 -692
  188. ltbams-0.9.9.dist-info/METADATA +0 -859
  189. ltbams-0.9.9.dist-info/RECORD +0 -14
  190. ltbams-0.9.9.dist-info/top_level.txt +0 -1
  191. {ltbams-0.9.9.dist-info → ltbams-1.0.2.dist-info}/entry_points.txt +0 -0
tests/test_rtn_rted.py ADDED
@@ -0,0 +1,273 @@
1
+ import unittest
2
+ import numpy as np
3
+
4
+ import ams
5
+ from ams.shared import skip_unittest_without_MISOCP
6
+
7
+
8
+ class TestRTED(unittest.TestCase):
9
+ """
10
+ Test methods of `RTED`.
11
+ """
12
+
13
+ def setUp(self) -> None:
14
+ self.ss = ams.load(ams.get_case("5bus/pjm5bus_demo.xlsx"),
15
+ setup=True, default_config=True, no_output=True)
16
+ # decrease load first
17
+ self.ss.PQ.set(src='p0', attr='v', idx=['PQ_1', 'PQ_2'], value=[0.3, 0.3])
18
+
19
+ def test_init(self):
20
+ """
21
+ Test `RTED.init()` method.
22
+ """
23
+ self.ss.RTED.init()
24
+ self.assertTrue(self.ss.RTED.initialized, "RTED initialization failed!")
25
+
26
+ def test_trip_gen(self):
27
+ """
28
+ Test generator tripping.
29
+ """
30
+ stg = 'PV_1'
31
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=0)
32
+
33
+ self.ss.RTED.update()
34
+ self.ss.RTED.run(solver='CLARABEL')
35
+ self.assertTrue(self.ss.RTED.converged, "RTED did not converge under generator trip!")
36
+ self.assertAlmostEqual(self.ss.RTED.get(src='pg', attr='v', idx=stg),
37
+ 0, places=6,
38
+ msg="Generator trip does not take effect!")
39
+
40
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=1) # reset
41
+
42
+ def test_trip_line(self):
43
+ """
44
+ Test line tripping.
45
+ """
46
+ self.ss.Line.set(src='u', attr='v', idx='Line_3', value=0)
47
+
48
+ self.ss.RTED.update()
49
+ self.ss.RTED.run(solver='CLARABEL')
50
+ self.assertTrue(self.ss.RTED.converged, "RTED did not converge under line trip!")
51
+ self.assertAlmostEqual(self.ss.RTED.get(src='plf', attr='v', idx='Line_3'),
52
+ 0, places=6,
53
+ msg="Line trip does not take effect!")
54
+
55
+ self.ss.Line.alter(src='u', idx='Line_3', value=1)
56
+
57
+ def test_set_load(self):
58
+ """
59
+ Test setting and tripping load.
60
+ """
61
+ self.ss.RTED.run(solver='CLARABEL')
62
+ pgs = self.ss.RTED.pg.v.sum()
63
+
64
+ # --- set load ---
65
+ self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0.1)
66
+ self.ss.RTED.update()
67
+
68
+ self.ss.RTED.run(solver='CLARABEL')
69
+ pgs_pqt = self.ss.RTED.pg.v.sum()
70
+ self.assertLess(pgs_pqt, pgs, "Load set does not take effect!")
71
+
72
+ # --- trip load ---
73
+ self.ss.PQ.set(src='u', attr='v', idx='PQ_2', value=0)
74
+ self.ss.RTED.update()
75
+
76
+ self.ss.RTED.run(solver='CLARABEL')
77
+ pgs_pqt2 = self.ss.RTED.pg.v.sum()
78
+ self.assertLess(pgs_pqt2, pgs_pqt, "Load trip does not take effect!")
79
+
80
+ def test_dc2ac(self):
81
+ """
82
+ Test `RTED.dc2ac()` method.
83
+ """
84
+ self.ss.RTED.run(solver='CLARABEL')
85
+ self.ss.RTED.dc2ac()
86
+ self.assertTrue(self.ss.RTED.converted, "AC conversion failed!")
87
+ self.assertTrue(self.ss.RTED.exec_time > 0, "Execution time is not greater than 0.")
88
+
89
+ stg_idx = self.ss.StaticGen.get_all_idxes()
90
+ pg_rted = self.ss.RTED.get(src='pg', attr='v', idx=stg_idx)
91
+ pg_acopf = self.ss.ACOPF.get(src='pg', attr='v', idx=stg_idx)
92
+ np.testing.assert_almost_equal(pg_rted, pg_acopf, decimal=3)
93
+
94
+ bus_idx = self.ss.Bus.get_all_idxes()
95
+ v_rted = self.ss.RTED.get(src='vBus', attr='v', idx=bus_idx)
96
+ v_acopf = self.ss.ACOPF.get(src='vBus', attr='v', idx=bus_idx)
97
+ np.testing.assert_almost_equal(v_rted, v_acopf, decimal=3)
98
+
99
+ a_rted = self.ss.RTED.get(src='aBus', attr='v', idx=bus_idx)
100
+ a_acopf = self.ss.ACOPF.get(src='aBus', attr='v', idx=bus_idx)
101
+ np.testing.assert_almost_equal(a_rted, a_acopf, decimal=3)
102
+
103
+
104
+ class TestRTEDDG(unittest.TestCase):
105
+ """
106
+ Test routine `RTEDDG`.
107
+ """
108
+
109
+ def setUp(self) -> None:
110
+ self.ss = ams.load(ams.get_case("5bus/pjm5bus_demo.xlsx"),
111
+ setup=True, default_config=True, no_output=True)
112
+ # decrease load first
113
+ self.ss.PQ.set(src='p0', attr='v', idx=['PQ_1', 'PQ_2'], value=[0.3, 0.3])
114
+
115
+ def test_init(self):
116
+ """
117
+ Test initialization.
118
+ """
119
+ self.ss.RTEDDG.init()
120
+ self.assertTrue(self.ss.RTEDDG.initialized, "RTEDDG initialization failed!")
121
+
122
+ def test_trip_gen(self):
123
+ """
124
+ Test generator tripping.
125
+ """
126
+ stg = 'PV_1'
127
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=0)
128
+
129
+ self.ss.RTEDDG.update()
130
+ self.ss.RTEDDG.run(solver='CLARABEL')
131
+ self.assertTrue(self.ss.RTEDDG.converged, "RTEDDG did not converge under generator trip!")
132
+ self.assertAlmostEqual(self.ss.RTEDDG.get(src='pg', attr='v', idx=stg),
133
+ 0, places=6,
134
+ msg="Generator trip does not take effect!")
135
+
136
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=1)
137
+
138
+ def test_trip_line(self):
139
+ """
140
+ Test line tripping.
141
+ """
142
+ self.ss.Line.set(src='u', attr='v', idx='Line_3', value=0)
143
+
144
+ self.ss.RTEDDG.update()
145
+ self.ss.RTEDDG.run(solver='CLARABEL')
146
+ self.assertTrue(self.ss.RTEDDG.converged, "RTEDDG did not converge under line trip!")
147
+ self.assertAlmostEqual(self.ss.RTEDDG.get(src='plf', attr='v', idx='Line_3'),
148
+ 0, places=6,
149
+ msg="Line trip does not take effect!")
150
+
151
+ self.ss.Line.alter(src='u', idx='Line_3', value=1)
152
+
153
+ def test_set_load(self):
154
+ """
155
+ Test setting and tripping load.
156
+ """
157
+ self.ss.RTEDDG.run(solver='CLARABEL')
158
+ pgs = self.ss.RTEDDG.pg.v.sum()
159
+
160
+ # --- set load ---
161
+ self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0.1)
162
+ self.ss.RTEDDG.update()
163
+
164
+ self.ss.RTEDDG.run(solver='CLARABEL')
165
+ pgs_pqt = self.ss.RTEDDG.pg.v.sum()
166
+ self.assertLess(pgs_pqt, pgs, "Load set does not take effect!")
167
+
168
+ # --- trip load ---
169
+ self.ss.PQ.set(src='u', attr='v', idx='PQ_2', value=0)
170
+ self.ss.RTEDDG.update()
171
+
172
+ self.ss.RTEDDG.run(solver='CLARABEL')
173
+ pgs_pqt2 = self.ss.RTEDDG.pg.v.sum()
174
+ self.assertLess(pgs_pqt2, pgs_pqt, "Load trip does not take effect!")
175
+
176
+ def test_dc2ac(self):
177
+ """
178
+ Test `RTEDDG.dc2ac()` method.
179
+ """
180
+ self.ss.RTEDDG.run(solver='CLARABEL')
181
+ self.ss.RTEDDG.dc2ac()
182
+ self.assertTrue(self.ss.RTEDDG.converted, "AC conversion failed!")
183
+ self.assertTrue(self.ss.RTEDDG.exec_time > 0, "Execution time is not greater than 0.")
184
+
185
+ stg_idx = self.ss.StaticGen.get_all_idxes()
186
+ pg_rted = self.ss.RTEDDG.get(src='pg', attr='v', idx=stg_idx)
187
+ pg_acopf = self.ss.ACOPF.get(src='pg', attr='v', idx=stg_idx)
188
+ np.testing.assert_almost_equal(pg_rted, pg_acopf, decimal=3)
189
+
190
+ bus_idx = self.ss.Bus.get_all_idxes()
191
+ v_rted = self.ss.RTEDDG.get(src='vBus', attr='v', idx=bus_idx)
192
+ v_acopf = self.ss.ACOPF.get(src='vBus', attr='v', idx=bus_idx)
193
+ np.testing.assert_almost_equal(v_rted, v_acopf, decimal=3)
194
+
195
+ a_rted = self.ss.RTEDDG.get(src='aBus', attr='v', idx=bus_idx)
196
+ a_acopf = self.ss.ACOPF.get(src='aBus', attr='v', idx=bus_idx)
197
+ np.testing.assert_almost_equal(a_rted, a_acopf, decimal=3)
198
+
199
+
200
+ class TestRTEDES(unittest.TestCase):
201
+ """
202
+ Test routine `RTEDES`.
203
+ """
204
+
205
+ def setUp(self) -> None:
206
+ self.ss = ams.load(ams.get_case("5bus/pjm5bus_uced_esd1.xlsx"),
207
+ setup=True, default_config=True, no_output=True)
208
+ # decrease load first
209
+ self.ss.PQ.set(src='p0', attr='v', idx=['PQ_1', 'PQ_2'], value=[0.3, 0.3])
210
+
211
+ def test_init(self):
212
+ """
213
+ Test initialization.
214
+ """
215
+ self.ss.RTEDES.init()
216
+ self.assertTrue(self.ss.RTEDES.initialized, "RTEDES initialization failed!")
217
+
218
+ @skip_unittest_without_MISOCP
219
+ def test_trip_gen(self):
220
+ """
221
+ Test generator tripping.
222
+ """
223
+ stg = 'PV_1'
224
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=0)
225
+
226
+ self.ss.RTEDES.update()
227
+ self.ss.RTEDES.run()
228
+ self.assertTrue(self.ss.RTEDES.converged, "RTEDES did not converge under generator trip!")
229
+ self.assertAlmostEqual(self.ss.RTEDES.get(src='pg', attr='v', idx=stg),
230
+ 0, places=6,
231
+ msg="Generator trip does not take effect!")
232
+
233
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=1)
234
+
235
+ @skip_unittest_without_MISOCP
236
+ def test_trip_line(self):
237
+ """
238
+ Test line tripping.
239
+ """
240
+ self.ss.Line.set(src='u', attr='v', idx=3, value=0)
241
+
242
+ self.ss.RTEDES.update()
243
+ self.ss.RTEDES.run()
244
+ self.assertTrue(self.ss.RTEDES.converged, "RTEDES did not converge under line trip!")
245
+ self.assertAlmostEqual(self.ss.RTEDES.get(src='plf', attr='v', idx=3),
246
+ 0, places=6,
247
+ msg="Line trip does not take effect!")
248
+
249
+ self.ss.Line.alter(src='u', idx=3, value=1)
250
+
251
+ @skip_unittest_without_MISOCP
252
+ def test_set_load(self):
253
+ """
254
+ Test setting and tripping load.
255
+ """
256
+ self.ss.RTEDES.run()
257
+ pgs = self.ss.RTEDES.pg.v.sum()
258
+
259
+ # --- set load ---
260
+ self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0.05)
261
+ self.ss.RTEDES.update()
262
+
263
+ self.ss.RTEDES.run()
264
+ pgs_pqt = self.ss.RTEDES.pg.v.sum()
265
+ self.assertLess(pgs_pqt, pgs, "Load set does not take effect!")
266
+
267
+ # --- trip load ---
268
+ self.ss.PQ.set(src='u', attr='v', idx='PQ_2', value=0)
269
+ self.ss.RTEDES.update()
270
+
271
+ self.ss.RTEDES.run()
272
+ pgs_pqt2 = self.ss.RTEDES.pg.v.sum()
273
+ self.assertLess(pgs_pqt2, pgs_pqt, "Load trip does not take effect!")
tests/test_rtn_uc.py ADDED
@@ -0,0 +1,248 @@
1
+ import unittest
2
+ import numpy as np
3
+
4
+ import ams
5
+ from ams.shared import skip_unittest_without_MISOCP
6
+
7
+
8
+ class TestUC(unittest.TestCase):
9
+ """
10
+ Test routine `UC`.
11
+ """
12
+
13
+ def setUp(self) -> None:
14
+ self.ss = ams.load(ams.get_case("5bus/pjm5bus_demo.xlsx"),
15
+ setup=True, default_config=True, no_output=True)
16
+ # decrease load first
17
+ self.ss.PQ.set(src='p0', attr='v', idx=['PQ_1', 'PQ_2'], value=[0.3, 0.3])
18
+ # run UC._initial_guess()
19
+ self.off_gen = self.ss.UC._initial_guess()
20
+
21
+ def test_initial_guess(self):
22
+ """
23
+ Test initial guess.
24
+ """
25
+ u_off_gen = self.ss.StaticGen.get(src='u', idx=self.off_gen)
26
+ np.testing.assert_equal(u_off_gen, np.zeros_like(u_off_gen),
27
+ err_msg="UC._initial_guess() failed!")
28
+
29
+ def test_init(self):
30
+ """
31
+ Test initialization.
32
+ """
33
+ self.ss.UC.init()
34
+ self.assertTrue(self.ss.UC.initialized, "UC initialization failed!")
35
+
36
+ @skip_unittest_without_MISOCP
37
+ def test_trip_gen(self):
38
+ """
39
+ Test generator tripping.
40
+ """
41
+ self.ss.UC.run()
42
+ self.assertTrue(self.ss.UC.converged, "UC did not converge!")
43
+ pg_off_gen = self.ss.UC.get(src='pg', attr='v', idx=self.off_gen)
44
+ np.testing.assert_almost_equal(np.zeros_like(pg_off_gen),
45
+ pg_off_gen, decimal=6,
46
+ err_msg="Off generators are not turned off!")
47
+
48
+ @skip_unittest_without_MISOCP
49
+ def test_set_load(self):
50
+ """
51
+ Test setting and tripping load.
52
+ """
53
+ self.ss.UC.run()
54
+ pgs = self.ss.UC.pg.v.sum()
55
+
56
+ # --- set load ---
57
+ self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0.1)
58
+ self.ss.UC.update()
59
+
60
+ self.ss.UC.run()
61
+ pgs_pqt = self.ss.UC.pg.v.sum()
62
+ self.assertLess(pgs_pqt, pgs, "Load set does not take effect!")
63
+
64
+ # --- trip load ---
65
+ self.ss.PQ.alter(src='u', idx='PQ_2', value=0)
66
+ self.ss.UC.update()
67
+
68
+ self.ss.UC.run()
69
+ pgs_pqt2 = self.ss.UC.pg.v.sum()
70
+ self.assertLess(pgs_pqt2, pgs_pqt, "Load trip does not take effect!")
71
+
72
+ @skip_unittest_without_MISOCP
73
+ def test_trip_line(self):
74
+ """
75
+ Test line tripping.
76
+ """
77
+ self.ss.Line.set(src='u', attr='v', idx='Line_3', value=0)
78
+ self.ss.UC.update()
79
+
80
+ self.ss.UC.run()
81
+ self.assertTrue(self.ss.UC.converged, "UC did not converge under line trip!")
82
+ plf_l3 = self.ss.UC.get(src='plf', attr='v', idx='Line_3')
83
+ np.testing.assert_almost_equal(np.zeros_like(plf_l3),
84
+ plf_l3, decimal=6)
85
+
86
+ self.ss.Line.alter(src='u', idx='Line_3', value=1)
87
+
88
+
89
+ class TestUCDG(unittest.TestCase):
90
+ """
91
+ Test routine `UCDG`.
92
+ """
93
+
94
+ def setUp(self) -> None:
95
+ self.ss = ams.load(ams.get_case("5bus/pjm5bus_demo.xlsx"),
96
+ setup=True, default_config=True, no_output=True)
97
+ # decrease load first
98
+ self.ss.PQ.set(src='p0', attr='v', idx=['PQ_1', 'PQ_2'], value=[0.3, 0.3])
99
+ # run `_initial_guess()`
100
+ self.off_gen = self.ss.UCDG._initial_guess()
101
+
102
+ def test_initial_guess(self):
103
+ """
104
+ Test initial guess.
105
+ """
106
+ u_off_gen = self.ss.StaticGen.get(src='u', idx=self.off_gen)
107
+ np.testing.assert_equal(u_off_gen, np.zeros_like(u_off_gen),
108
+ err_msg="UCDG._initial_guess() failed!")
109
+
110
+ def test_init(self):
111
+ """
112
+ Test initialization.
113
+ """
114
+ self.ss.UCDG.init()
115
+ self.assertTrue(self.ss.UCDG.initialized, "UCDG initialization failed!")
116
+
117
+ @skip_unittest_without_MISOCP
118
+ def test_trip_gen(self):
119
+ """
120
+ Test generator tripping.
121
+ """
122
+ self.ss.UCDG.run()
123
+ self.assertTrue(self.ss.UCDG.converged, "UCDG did not converge!")
124
+ pg_off_gen = self.ss.UCDG.get(src='pg', attr='v', idx=self.off_gen)
125
+ np.testing.assert_almost_equal(np.zeros_like(pg_off_gen),
126
+ pg_off_gen, decimal=6,
127
+ err_msg="Off generators are not turned off!")
128
+
129
+ @skip_unittest_without_MISOCP
130
+ def test_set_load(self):
131
+ """
132
+ Test setting and tripping load.
133
+ """
134
+ self.ss.UCDG.run()
135
+ pgs = self.ss.UCDG.pg.v.sum()
136
+
137
+ # --- set load ---
138
+ self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0.1)
139
+ self.ss.UCDG.update()
140
+
141
+ self.ss.UCDG.run()
142
+ pgs_pqt = self.ss.UCDG.pg.v.sum()
143
+ self.assertLess(pgs_pqt, pgs, "Load set does not take effect!")
144
+
145
+ # --- trip load ---
146
+ self.ss.PQ.alter(src='u', idx='PQ_2', value=0)
147
+ self.ss.UCDG.update()
148
+
149
+ self.ss.UCDG.run()
150
+ pgs_pqt2 = self.ss.UCDG.pg.v.sum()
151
+ self.assertLess(pgs_pqt2, pgs_pqt, "Load trip does not take effect!")
152
+
153
+ @skip_unittest_without_MISOCP
154
+ def test_trip_line(self):
155
+ """
156
+ Test line tripping.
157
+ """
158
+ self.ss.Line.set(src='u', attr='v', idx='Line_3', value=0)
159
+ self.ss.UCDG.update()
160
+
161
+ self.ss.UCDG.run()
162
+ self.assertTrue(self.ss.UCDG.converged, "UCDG did not converge under line trip!")
163
+ plf_l3 = self.ss.UCDG.get(src='plf', attr='v', idx='Line_3')
164
+ np.testing.assert_almost_equal(np.zeros_like(plf_l3),
165
+ plf_l3, decimal=6)
166
+
167
+ self.ss.Line.alter(src='u', idx='Line_3', value=1)
168
+
169
+
170
+ class TestUCES(unittest.TestCase):
171
+ """
172
+ Test routine `UCES`.
173
+ """
174
+
175
+ def setUp(self) -> None:
176
+ self.ss = ams.load(ams.get_case("5bus/pjm5bus_uced_esd1.xlsx"),
177
+ setup=True, default_config=True, no_output=True)
178
+ # decrease load first
179
+ self.ss.PQ.set(src='p0', attr='v', idx=['PQ_1', 'PQ_2'], value=[0.3, 0.3])
180
+ # run `_initial_guess()`
181
+ self.off_gen = self.ss.UCES._initial_guess()
182
+
183
+ def test_initial_guess(self):
184
+ """
185
+ Test initial guess.
186
+ """
187
+ u_off_gen = self.ss.StaticGen.get(src='u', idx=self.off_gen)
188
+ np.testing.assert_equal(u_off_gen, np.zeros_like(u_off_gen),
189
+ err_msg="UCES._initial_guess() failed!")
190
+
191
+ def test_init(self):
192
+ """
193
+ Test initialization.
194
+ """
195
+ self.ss.UCES.init()
196
+ self.assertTrue(self.ss.UCES.initialized, "UCES initialization failed!")
197
+
198
+ @skip_unittest_without_MISOCP
199
+ def test_trip_gen(self):
200
+ """
201
+ Test generator tripping.
202
+ """
203
+ self.ss.UCES.run()
204
+ self.assertTrue(self.ss.UCES.converged, "UCES did not converge!")
205
+ pg_off_gen = self.ss.UCES.get(src='pg', attr='v', idx=self.off_gen)
206
+ np.testing.assert_almost_equal(np.zeros_like(pg_off_gen),
207
+ pg_off_gen, decimal=6,
208
+ err_msg="Off generators are not turned off!")
209
+
210
+ @skip_unittest_without_MISOCP
211
+ def test_set_load(self):
212
+ """
213
+ Test setting and tripping load.
214
+ """
215
+ self.ss.UCES.run()
216
+ pgs = self.ss.UCES.pg.v.sum()
217
+
218
+ # --- set load ---
219
+ self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0.1)
220
+ self.ss.UCES.update()
221
+
222
+ self.ss.UCES.run()
223
+ pgs_pqt = self.ss.UCES.pg.v.sum()
224
+ self.assertLess(pgs_pqt, pgs, "Load set does not take effect!")
225
+
226
+ # --- trip load ---
227
+ self.ss.PQ.alter(src='u', idx='PQ_2', value=0)
228
+ self.ss.UCES.update()
229
+
230
+ self.ss.UCES.run()
231
+ pgs_pqt2 = self.ss.UCES.pg.v.sum()
232
+ self.assertLess(pgs_pqt2, pgs_pqt, "Load trip does not take effect!")
233
+
234
+ @skip_unittest_without_MISOCP
235
+ def test_trip_line(self):
236
+ """
237
+ Test line tripping.
238
+ """
239
+ self.ss.Line.set(src='u', attr='v', idx=3, value=0)
240
+ self.ss.UCES.update()
241
+
242
+ self.ss.UCES.run()
243
+ self.assertTrue(self.ss.UCES.converged, "UCES did not converge under line trip!")
244
+ plf_l3 = self.ss.UCES.get(src='plf', attr='v', idx=3)
245
+ np.testing.assert_almost_equal(np.zeros_like(plf_l3),
246
+ plf_l3, decimal=6)
247
+
248
+ self.ss.Line.alter(src='u', idx=3, value=1)
tests/test_service.py ADDED
@@ -0,0 +1,73 @@
1
+ import unittest
2
+ import numpy as np
3
+
4
+ import ams
5
+ from ams.core.matprocessor import MParam
6
+ from ams.core.service import NumOp, NumOpDual, ZonalSum
7
+
8
+
9
+ class TestService(unittest.TestCase):
10
+ """
11
+ Test functionality of Services.
12
+ """
13
+
14
+ def setUp(self) -> None:
15
+ self.ss = ams.load(ams.get_case("ieee39/ieee39_uced_esd1.xlsx"),
16
+ default_config=True,
17
+ no_output=True,)
18
+ self.nR = self.ss.Zone.n
19
+ self.nB = self.ss.Bus.n
20
+ self.nL = self.ss.Line.n
21
+ self.nD = self.ss.StaticLoad.n # number of static loads
22
+
23
+ def test_NumOp_norfun(self):
24
+ """
25
+ Test `NumOp` without return function.
26
+ """
27
+ CftT = NumOp(u=self.ss.mats.Cft, fun=np.transpose)
28
+ np.testing.assert_array_equal(CftT.v.transpose(), self.ss.mats.Cft.v)
29
+
30
+ def test_NumOp_rfun(self):
31
+ """
32
+ Test `NumOp` with return function.
33
+ """
34
+ CftTT = NumOp(u=self.ss.mats.Cft, fun=np.transpose, rfun=np.transpose)
35
+ np.testing.assert_array_equal(CftTT.v, self.ss.mats.Cft.v)
36
+
37
+ def test_NumOp_ArrayOut(self):
38
+ """
39
+ Test `NumOp` non-array output.
40
+ """
41
+ M = NumOp(u=self.ss.PV.pmax,
42
+ fun=np.max,
43
+ rfun=np.dot, rargs=dict(b=10),
44
+ array_out=True,)
45
+ M2 = NumOp(u=self.ss.PV.pmax,
46
+ fun=np.max,
47
+ rfun=np.dot, rargs=dict(b=10),
48
+ array_out=False,)
49
+ self.assertIsInstance(M.v, np.ndarray)
50
+ self.assertIsInstance(M2.v, (int, float))
51
+
52
+ def test_NumOpDual(self):
53
+ """
54
+ Test `NumOpDual`.
55
+ """
56
+ p_vec = MParam(v=self.ss.DCOPF.pd.v)
57
+ one_vec = MParam(v=np.ones(self.ss.StaticLoad.n))
58
+ p_sum = NumOpDual(u=p_vec, u2=one_vec,
59
+ fun=np.multiply, rfun=np.sum)
60
+ self.assertEqual(p_sum.v, self.ss.PQ.p0.v.sum())
61
+
62
+ def test_ZonalSum(self):
63
+ """
64
+ Test `ZonalSum`.
65
+ """
66
+ ds = ZonalSum(u=self.ss.RTED.zd, zone="Zone",
67
+ name="ds", tex_name=r"S_{d}",
68
+ info="Sum pl vector in shape of zone",)
69
+ ds.rtn = self.ss.RTED
70
+ # check if the shape is correct
71
+ np.testing.assert_array_equal(ds.v.shape, (self.nR, self.nD))
72
+ # check if the values are correct
73
+ self.assertTrue(np.all(ds.v.sum(axis=1) <= np.array([self.nB, self.nB])))