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
@@ -0,0 +1,101 @@
1
+ import unittest
2
+ import numpy as np
3
+
4
+ import ams
5
+
6
+
7
+ class TestDCOPF(unittest.TestCase):
8
+ """
9
+ Test routine `DCOPF`.
10
+ """
11
+
12
+ def setUp(self) -> None:
13
+ self.ss = ams.load(ams.get_case("5bus/pjm5bus_demo.xlsx"),
14
+ setup=True, default_config=True, no_output=True)
15
+ # decrease load first
16
+ self.ss.PQ.set(src='p0', attr='v', idx=['PQ_1', 'PQ_2'], value=[0.3, 0.3])
17
+
18
+ def test_init(self):
19
+ """
20
+ Test initialization.
21
+ """
22
+ self.ss.DCOPF.init()
23
+ self.assertTrue(self.ss.DCOPF.initialized, "DCOPF initialization failed!")
24
+
25
+ def test_trip_gen(self):
26
+ """
27
+ Test generator tripping.
28
+ """
29
+ stg = 'PV_1'
30
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=0)
31
+
32
+ self.ss.DCOPF.update()
33
+ self.ss.DCOPF.run(solver='CLARABEL')
34
+ self.assertTrue(self.ss.DCOPF.converged, "DCOPF did not converge under generator trip!")
35
+ self.assertAlmostEqual(self.ss.DCOPF.get(src='pg', attr='v', idx=stg),
36
+ 0, places=6,
37
+ msg="Generator trip does not take effect!")
38
+
39
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=1) # reset
40
+
41
+ def test_trip_line(self):
42
+ """
43
+ Test line tripping.
44
+ """
45
+ self.ss.Line.set(src='u', attr='v', idx='Line_3', value=0)
46
+
47
+ self.ss.DCOPF.update()
48
+ self.ss.DCOPF.run(solver='CLARABEL')
49
+ self.assertTrue(self.ss.DCOPF.converged, "DCOPF did not converge under line trip!")
50
+ self.assertAlmostEqual(self.ss.DCOPF.get(src='plf', attr='v', idx='Line_3'),
51
+ 0, places=6,
52
+ msg="Line trip does not take effect!")
53
+
54
+ self.ss.Line.alter(src='u', idx='Line_3', value=1) # reset
55
+
56
+ def test_set_load(self):
57
+ """
58
+ Test setting and tripping load.
59
+ """
60
+ # --- run DCOPF ---
61
+ self.ss.DCOPF.run(solver='CLARABEL')
62
+ pgs = self.ss.DCOPF.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.DCOPF.update()
67
+
68
+ self.ss.DCOPF.run(solver='CLARABEL')
69
+ pgs_pqt = self.ss.DCOPF.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.DCOPF.update()
75
+
76
+ self.ss.DCOPF.run(solver='CLARABEL')
77
+ pgs_pqt2 = self.ss.DCOPF.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 `DCOPF.dc2ac()` method.
83
+ """
84
+ self.ss.DCOPF.run(solver='CLARABEL')
85
+ self.ss.DCOPF.dc2ac()
86
+ self.assertTrue(self.ss.DCOPF.converted, "AC conversion failed!")
87
+ self.assertTrue(self.ss.DCOPF.exec_time > 0, "Execution time is not greater than 0.")
88
+
89
+ stg_idx = self.ss.StaticGen.get_all_idxes()
90
+ pg_dcopf = self.ss.DCOPF.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_dcopf, pg_acopf, decimal=3)
93
+
94
+ bus_idx = self.ss.Bus.get_all_idxes()
95
+ v_dcopf = self.ss.DCOPF.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_dcopf, v_acopf, decimal=3)
98
+
99
+ a_dcopf = self.ss.DCOPF.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_dcopf, a_acopf, decimal=3)
tests/test_rtn_dcpf.py ADDED
@@ -0,0 +1,77 @@
1
+ import unittest
2
+
3
+ import ams
4
+
5
+
6
+ class TestDCPF(unittest.TestCase):
7
+ """
8
+ Test routine `DCPF`.
9
+ """
10
+
11
+ def setUp(self) -> None:
12
+ self.ss = ams.load(ams.get_case("5bus/pjm5bus_demo.xlsx"),
13
+ setup=True, default_config=True, no_output=True)
14
+ # decrease load first
15
+ self.ss.PQ.set(src='p0', attr='v', idx=['PQ_1', 'PQ_2'], value=[0.3, 0.3])
16
+
17
+ def test_init(self):
18
+ """
19
+ Test initialization.
20
+ """
21
+ self.ss.DCPF.init()
22
+ self.assertTrue(self.ss.DCPF.initialized, "DCPF initialization failed!")
23
+
24
+ def test_trip_gen(self):
25
+ """
26
+ Test generator tripping.
27
+ """
28
+ stg = 'PV_1'
29
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=0)
30
+
31
+ self.ss.DCPF.update()
32
+ self.ss.DCPF.run(solver='CLARABEL')
33
+ self.assertTrue(self.ss.DCPF.converged, "DCPF did not converge under generator trip!")
34
+ self.assertAlmostEqual(self.ss.DCPF.get(src='pg', attr='v', idx=stg),
35
+ 0, places=6,
36
+ msg="Generator trip does not take effect!")
37
+
38
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=1) # reset
39
+
40
+ def test_trip_line(self):
41
+ """
42
+ Test line tripping.
43
+ """
44
+ self.ss.Line.set(src='u', attr='v', idx='Line_3', value=0)
45
+
46
+ self.ss.DCPF.update()
47
+ self.ss.DCPF.run(solver='CLARABEL')
48
+ self.assertTrue(self.ss.DCPF.converged, "DCPF did not converge under line trip!")
49
+ self.assertAlmostEqual(self.ss.DCPF.get(src='plf', attr='v', idx='Line_3'),
50
+ 0, places=6,
51
+ msg="Line trip does not take effect!")
52
+
53
+ self.ss.Line.alter(src='u', idx='Line_3', value=1) # reset
54
+
55
+ def test_set_load(self):
56
+ """
57
+ Test setting and tripping load.
58
+ """
59
+ # --- run DCPF ---
60
+ self.ss.DCPF.run(solver='CLARABEL')
61
+ pgs = self.ss.DCPF.pg.v.sum()
62
+
63
+ # --- set load ---
64
+ self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0.1)
65
+ self.ss.DCPF.update()
66
+
67
+ self.ss.DCPF.run(solver='CLARABEL')
68
+ pgs_pqt = self.ss.DCPF.pg.v.sum()
69
+ self.assertLess(pgs_pqt, pgs, "Load set does not take effect!")
70
+
71
+ # --- trip load ---
72
+ self.ss.PQ.set(src='u', attr='v', idx='PQ_2', value=0)
73
+ self.ss.DCPF.update()
74
+
75
+ self.ss.DCPF.run(solver='CLARABEL')
76
+ pgs_pqt2 = self.ss.DCPF.pg.v.sum()
77
+ self.assertLess(pgs_pqt2, pgs_pqt, "Load trip does not take effect!")
tests/test_rtn_ed.py ADDED
@@ -0,0 +1,279 @@
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 TestED(unittest.TestCase):
9
+ """
10
+ Test routine `ED`.
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 initialization.
22
+ """
23
+ self.ss.ED.init()
24
+ self.assertTrue(self.ss.ED.initialized, "ED initialization failed!")
25
+
26
+ def test_trip_gen(self):
27
+ """
28
+ Test generator tripping.
29
+ """
30
+ # a) ensure EDTSlot.ug takes effect
31
+ # NOTE: manually chang ug.v for testing purpose
32
+ stg = 'PV_1'
33
+ stg_uid = self.ss.ED.pg.get_all_idxes().index(stg)
34
+ loc_offtime = np.array([0, 2, 4])
35
+ self.ss.EDTSlot.ug.v[loc_offtime, stg_uid] = 0
36
+
37
+ self.ss.ED.run(solver='CLARABEL')
38
+ self.assertTrue(self.ss.ED.converged, "ED did not converge under generator trip!")
39
+ pg_pv1 = self.ss.ED.get(src='pg', attr='v', idx=stg)
40
+ np.testing.assert_almost_equal(np.zeros_like(loc_offtime),
41
+ pg_pv1[loc_offtime],
42
+ decimal=6,
43
+ err_msg="Generator trip does not take effect!")
44
+
45
+ self.ss.EDTSlot.ug.v[...] = 1 # reset
46
+
47
+ # b) ensure StaticGen.u does not take effect
48
+ # NOTE: in ED, `EDTSlot.ug` is used instead of `StaticGen.u`
49
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=0)
50
+ self.ss.ED.update()
51
+
52
+ self.ss.ED.run(solver='CLARABEL')
53
+ self.assertTrue(self.ss.ED.converged, "ED did not converge under generator trip!")
54
+ pg_pv1 = self.ss.ED.get(src='pg', attr='v', idx=stg)
55
+ np.testing.assert_array_less(np.zeros_like(pg_pv1), pg_pv1,
56
+ err_msg="Generator trip take effect, which is unexpected!")
57
+
58
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=1) # reset
59
+
60
+ def test_trip_line(self):
61
+ """
62
+ Test line tripping.
63
+ """
64
+ self.ss.Line.set(src='u', attr='v', idx='Line_3', value=0)
65
+ self.ss.ED.update()
66
+
67
+ self.ss.ED.run(solver='CLARABEL')
68
+ self.assertTrue(self.ss.ED.converged, "ED did not converge under line trip!")
69
+ plf_l3 = self.ss.ED.get(src='plf', attr='v', idx='Line_3')
70
+ np.testing.assert_almost_equal(np.zeros_like(plf_l3),
71
+ plf_l3, decimal=6)
72
+
73
+ self.ss.Line.alter(src='u', idx='Line_3', value=1) # reset
74
+
75
+ def test_set_load(self):
76
+ """
77
+ Test setting and tripping load.
78
+ """
79
+ self.ss.ED.run(solver='CLARABEL')
80
+ pgs = self.ss.ED.pg.v.sum()
81
+
82
+ # --- set load ---
83
+ self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0.1)
84
+ self.ss.ED.update()
85
+
86
+ self.ss.ED.run(solver='CLARABEL')
87
+ pgs_pqt = self.ss.ED.pg.v.sum()
88
+ self.assertLess(pgs_pqt, pgs, "Load set does not take effect!")
89
+
90
+ # --- trip load ---
91
+ self.ss.PQ.alter(src='u', idx='PQ_2', value=0)
92
+ self.ss.ED.update()
93
+
94
+ self.ss.ED.run(solver='CLARABEL')
95
+ pgs_pqt2 = self.ss.ED.pg.v.sum()
96
+ self.assertLess(pgs_pqt2, pgs_pqt, "Load trip does not take effect!")
97
+
98
+
99
+ class TestEDDG(unittest.TestCase):
100
+ """
101
+ Test routine `EDDG`.
102
+ """
103
+
104
+ def setUp(self) -> None:
105
+ self.ss = ams.load(ams.get_case("5bus/pjm5bus_demo.xlsx"),
106
+ setup=True, default_config=True, no_output=True)
107
+ # decrease load first
108
+ self.ss.PQ.set(src='p0', attr='v', idx=['PQ_1', 'PQ_2'], value=[0.3, 0.3])
109
+
110
+ def test_init(self):
111
+ """
112
+ Test initialization.
113
+ """
114
+ self.ss.EDDG.init()
115
+ self.assertTrue(self.ss.EDDG.initialized, "EDDG initialization failed!")
116
+
117
+ def test_trip_gen(self):
118
+ """
119
+ Test generator tripping.
120
+ """
121
+ # a) ensure EDTSlot.ug takes effect
122
+ # NOTE: manually chang ug.v for testing purpose
123
+ stg = 'PV_1'
124
+ stg_uid = self.ss.EDDG.pg.get_all_idxes().index(stg)
125
+ loc_offtime = np.array([0, 2, 4])
126
+ self.ss.EDTSlot.ug.v[loc_offtime, stg_uid] = 0
127
+
128
+ self.ss.EDDG.run(solver='CLARABEL')
129
+ self.assertTrue(self.ss.EDDG.converged, "ED did not converge under generator trip!")
130
+ pg_pv1 = self.ss.EDDG.get(src='pg', attr='v', idx=stg)
131
+ np.testing.assert_almost_equal(np.zeros_like(loc_offtime),
132
+ pg_pv1[loc_offtime],
133
+ decimal=6,
134
+ err_msg="Generator trip does not take effect!")
135
+
136
+ self.ss.EDTSlot.ug.v[...] = 1
137
+
138
+ # b) ensure StaticGen.u does not take effect
139
+ # NOTE: in EDDG, `EDTSlot.ug` is used instead of `StaticGen.u`
140
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=0)
141
+ self.ss.EDDG.update()
142
+
143
+ self.ss.EDDG.run(solver='CLARABEL')
144
+ self.assertTrue(self.ss.EDDG.converged, "ED did not converge under generator trip!")
145
+ pg_pv1 = self.ss.EDDG.get(src='pg', attr='v', idx=stg)
146
+ np.testing.assert_array_less(np.zeros_like(pg_pv1), pg_pv1,
147
+ err_msg="Generator trip take effect, which is unexpected!")
148
+
149
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=1) # reset
150
+
151
+ def test_trip_line(self):
152
+ """
153
+ Test line tripping.
154
+ """
155
+ self.ss.Line.set(src='u', attr='v', idx='Line_3', value=0)
156
+ self.ss.EDDG.update()
157
+
158
+ self.ss.EDDG.run(solver='CLARABEL')
159
+ self.assertTrue(self.ss.EDDG.converged, "ED did not converge under line trip!")
160
+ plf_l3 = self.ss.EDDG.get(src='plf', attr='v', idx='Line_3')
161
+ np.testing.assert_almost_equal(np.zeros_like(plf_l3),
162
+ plf_l3, decimal=6)
163
+
164
+ self.ss.Line.alter(src='u', idx='Line_3', value=1)
165
+
166
+ def test_set_load(self):
167
+ """
168
+ Test setting and tripping load.
169
+ """
170
+ self.ss.EDDG.run(solver='CLARABEL')
171
+ pgs = self.ss.EDDG.pg.v.sum()
172
+
173
+ # --- set load ---
174
+ self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0.1)
175
+ self.ss.EDDG.update()
176
+
177
+ self.ss.EDDG.run(solver='CLARABEL')
178
+ pgs_pqt = self.ss.EDDG.pg.v.sum()
179
+ self.assertLess(pgs_pqt, pgs, "Load set does not take effect!")
180
+
181
+ # --- trip load ---
182
+ self.ss.PQ.alter(src='u', idx='PQ_2', value=0)
183
+ self.ss.EDDG.update()
184
+
185
+ self.ss.EDDG.run(solver='CLARABEL')
186
+ pgs_pqt2 = self.ss.EDDG.pg.v.sum()
187
+ self.assertLess(pgs_pqt2, pgs_pqt, "Load trip does not take effect!")
188
+
189
+
190
+ class TestEDES(unittest.TestCase):
191
+ """
192
+ Test routine `EDES`.
193
+ """
194
+
195
+ def setUp(self) -> None:
196
+ self.ss = ams.load(ams.get_case("5bus/pjm5bus_uced_esd1.xlsx"),
197
+ setup=True, default_config=True, no_output=True)
198
+ # decrease load first
199
+ self.ss.PQ.set(src='p0', attr='v', idx=['PQ_1', 'PQ_2'], value=[0.3, 0.3])
200
+
201
+ def test_init(self):
202
+ """
203
+ Test initialization.
204
+ """
205
+ self.ss.EDES.init()
206
+ self.assertTrue(self.ss.EDES.initialized, "EDES initialization failed!")
207
+
208
+ @skip_unittest_without_MISOCP
209
+ def test_trip_gen(self):
210
+ """
211
+ Test generator tripping.
212
+ """
213
+ # a) ensure EDTSlot.ug takes effect
214
+ # NOTE: manually chang ug.v for testing purpose
215
+ stg = 'PV_1'
216
+ stg_uid = self.ss.EDES.pg.get_all_idxes().index(stg)
217
+ loc_offtime = np.array([0, 2])
218
+ self.ss.EDTSlot.ug.v[loc_offtime, stg_uid] = 0
219
+
220
+ self.ss.EDES.run()
221
+ self.assertTrue(self.ss.EDES.converged, "ED did not converge under generator trip!")
222
+ pg_pv1 = self.ss.EDES.get(src='pg', attr='v', idx=stg)
223
+ np.testing.assert_almost_equal(np.zeros_like(loc_offtime),
224
+ pg_pv1[loc_offtime],
225
+ decimal=6,
226
+ err_msg="Generator trip does not take effect!")
227
+
228
+ self.ss.EDTSlot.ug.v[...] = 1 # reset
229
+
230
+ # b) ensure StaticGen.u does not take effect
231
+ # NOTE: in ED, `EDTSlot.ug` is used instead of `StaticGen.u`
232
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=0)
233
+ self.ss.EDES.update()
234
+
235
+ self.ss.EDES.run()
236
+ self.assertTrue(self.ss.EDES.converged, "ED did not converge under generator trip!")
237
+ pg_pv1 = self.ss.EDES.get(src='pg', attr='v', idx=stg)
238
+ np.testing.assert_array_less(np.zeros_like(pg_pv1), pg_pv1,
239
+ err_msg="Generator trip take effect, which is unexpected!")
240
+
241
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=1) # reset
242
+
243
+ @skip_unittest_without_MISOCP
244
+ def test_line_trip(self):
245
+ """
246
+ Test line tripping.
247
+ """
248
+ self.ss.Line.set(src='u', attr='v', idx=3, value=0)
249
+ self.ss.EDES.run()
250
+ self.assertTrue(self.ss.EDES.converged, "EDES did not converge!")
251
+ plf_l3 = self.ss.EDES.get(src='plf', attr='v', idx=3)
252
+ np.testing.assert_almost_equal(np.zeros_like(plf_l3),
253
+ plf_l3, decimal=6)
254
+
255
+ self.ss.Line.alter(src='u', idx=3, value=1)
256
+
257
+ @skip_unittest_without_MISOCP
258
+ def test_set_load(self):
259
+ """
260
+ Test setting and tripping load.
261
+ """
262
+ self.ss.EDES.run()
263
+ pgs = self.ss.EDES.pg.v.sum()
264
+
265
+ # --- set load ---
266
+ self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0.1)
267
+ self.ss.EDES.update()
268
+
269
+ self.ss.EDES.run()
270
+ pgs_pqt = self.ss.EDES.pg.v.sum()
271
+ self.assertLess(pgs_pqt, pgs, "Load set does not take effect!")
272
+
273
+ # --- trip load ---
274
+ self.ss.PQ.alter(src='u', idx='PQ_2', value=0)
275
+ self.ss.EDES.update()
276
+
277
+ self.ss.EDES.run()
278
+ pgs_pqt2 = self.ss.EDES.pg.v.sum()
279
+ self.assertLess(pgs_pqt2, pgs_pqt, "Load trip does not take effect!")
@@ -0,0 +1,219 @@
1
+ import unittest
2
+
3
+ import ams
4
+
5
+
6
+ class TestDCPF(unittest.TestCase):
7
+ """
8
+ Test routine `DCPF`.
9
+ """
10
+
11
+ def setUp(self) -> None:
12
+ self.ss = ams.load(ams.get_case('matpower/case14.m'),
13
+ setup=True, no_output=True, default_config=True)
14
+
15
+ def test_init(self):
16
+ """
17
+ Test initialization.
18
+ """
19
+ self.ss.DCPF.init()
20
+ self.assertTrue(self.ss.DCPF.initialized, "DCPF initialization failed!")
21
+
22
+ def test_trip_gen(self):
23
+ """
24
+ Test generator tripping.
25
+ """
26
+ stg = 2
27
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=0)
28
+
29
+ self.ss.DCPF.update()
30
+ self.ss.DCPF.run()
31
+ self.assertTrue(self.ss.DCPF.converged, "DCPF did not converge under generator trip!")
32
+ self.assertAlmostEqual(self.ss.DCPF.get(src='pg', attr='v', idx=stg),
33
+ 0, places=6,
34
+ msg="Generator trip does not take effect!")
35
+
36
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=1) # reset
37
+
38
+ def test_trip_line(self):
39
+ """
40
+ Test line tripping.
41
+ """
42
+ self.ss.Line.set(src='u', attr='v', idx='Line_3', value=0)
43
+
44
+ self.ss.DCPF.update()
45
+ self.ss.DCPF.run()
46
+ self.assertTrue(self.ss.DCPF.converged, "DCPF did not converge under line trip!")
47
+ self.assertAlmostEqual(self.ss.DCPF.get(src='plf', attr='v', idx='Line_3'),
48
+ 0, places=6,
49
+ msg="Line trip does not take effect!")
50
+
51
+ self.ss.Line.alter(src='u', idx='Line_3', value=1)
52
+
53
+ def test_set_load(self):
54
+ """
55
+ Test setting and tripping load.
56
+ """
57
+ # --- run DCPF ---
58
+ self.ss.DCPF.run()
59
+ pgs = self.ss.DCPF.pg.v.sum()
60
+
61
+ # --- set load ---
62
+ self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0.1)
63
+ self.ss.DCPF.update()
64
+
65
+ self.ss.DCPF.run()
66
+ pgs_pqt = self.ss.DCPF.pg.v.sum()
67
+ self.assertLess(pgs_pqt, pgs, "Load set does not take effect!")
68
+
69
+ # --- trip load ---
70
+ self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0)
71
+ self.ss.DCPF.update()
72
+
73
+ self.ss.DCPF.run()
74
+ pgs_pqt2 = self.ss.DCPF.pg.v.sum()
75
+ self.assertLess(pgs_pqt2, pgs_pqt, "Load trip does not take effect!")
76
+
77
+
78
+ class TestPFlow(unittest.TestCase):
79
+ """
80
+ Test routine `DCPF`.
81
+ """
82
+
83
+ def setUp(self) -> None:
84
+ self.ss = ams.load(ams.get_case('matpower/case14.m'),
85
+ setup=True, no_output=True, default_config=True)
86
+
87
+ def test_init(self):
88
+ """
89
+ Test initialization.
90
+ """
91
+ self.ss.PFlow.init()
92
+ self.assertTrue(self.ss.PFlow.initialized, "PFlow initialization failed!")
93
+
94
+ def test_trip_gen(self):
95
+ """
96
+ Test generator tripping.
97
+ """
98
+ stg = 2
99
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=0)
100
+
101
+ self.ss.PFlow.update()
102
+ self.ss.PFlow.run()
103
+ self.assertTrue(self.ss.PFlow.converged, "PFlow did not converge under generator trip!")
104
+ self.assertAlmostEqual(self.ss.PFlow.get(src='pg', attr='v', idx=stg),
105
+ 0, places=6,
106
+ msg="Generator trip does not take effect!")
107
+
108
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=1)
109
+
110
+ def test_trip_line(self):
111
+ """
112
+ Test line tripping.
113
+ """
114
+ self.ss.Line.set(src='u', attr='v', idx='Line_3', value=0)
115
+
116
+ self.ss.PFlow.update()
117
+ self.ss.PFlow.run()
118
+ self.assertTrue(self.ss.PFlow.converged, "PFlow did not converge under line trip!")
119
+ self.assertAlmostEqual(self.ss.PFlow.get(src='plf', attr='v', idx='Line_3'),
120
+ 0, places=6,
121
+ msg="Line trip does not take effect!")
122
+
123
+ self.ss.Line.alter(src='u', idx='Line_3', value=1)
124
+
125
+ def test_set_load(self):
126
+ """
127
+ Test setting and tripping load.
128
+ """
129
+ # --- run PFlow ---
130
+ self.ss.PFlow.run()
131
+ pgs = self.ss.PFlow.pg.v.sum()
132
+
133
+ # --- set load ---
134
+ self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0.1)
135
+ self.ss.PFlow.update()
136
+
137
+ self.ss.PFlow.run()
138
+ pgs_pqt = self.ss.PFlow.pg.v.sum()
139
+ self.assertLess(pgs_pqt, pgs, "Load set does not take effect!")
140
+
141
+ # --- trip load ---
142
+ self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0)
143
+ self.ss.PFlow.update()
144
+
145
+ self.ss.PFlow.run()
146
+ pgs_pqt2 = self.ss.PFlow.pg.v.sum()
147
+ self.assertLess(pgs_pqt2, pgs_pqt, "Load trip does not take effect!")
148
+
149
+
150
+ class TestACOPF(unittest.TestCase):
151
+ """
152
+ Test routine `ACOPF`.
153
+ """
154
+
155
+ def setUp(self) -> None:
156
+ self.ss = ams.load(ams.get_case('matpower/case14.m'),
157
+ setup=True, no_output=True, default_config=True)
158
+
159
+ def test_init(self):
160
+ """
161
+ Test initialization.
162
+ """
163
+ self.ss.ACOPF.init()
164
+ self.assertTrue(self.ss.ACOPF.initialized, "ACOPF initialization failed!")
165
+
166
+ def test_trip_gen(self):
167
+ """
168
+ Test generator tripping.
169
+ """
170
+ stg = 2
171
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=0)
172
+
173
+ self.ss.ACOPF.update()
174
+ self.ss.ACOPF.run()
175
+ self.assertTrue(self.ss.ACOPF.converged, "ACOPF did not converge under generator trip!")
176
+ self.assertAlmostEqual(self.ss.ACOPF.get(src='pg', attr='v', idx=stg),
177
+ 0, places=6,
178
+ msg="Generator trip does not take effect!")
179
+
180
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=1)
181
+
182
+ def test_trip_line(self):
183
+ """
184
+ Test line tripping.
185
+ """
186
+ self.ss.Line.set(src='u', attr='v', idx='Line_3', value=0)
187
+
188
+ self.ss.ACOPF.update()
189
+ self.ss.ACOPF.run()
190
+ self.assertTrue(self.ss.ACOPF.converged, "ACOPF did not converge under line trip!")
191
+ self.assertAlmostEqual(self.ss.ACOPF.get(src='plf', attr='v', idx='Line_3'),
192
+ 0, places=6,
193
+ msg="Line trip does not take effect!")
194
+
195
+ self.ss.Line.alter(src='u', idx='Line_3', value=1)
196
+
197
+ def test_set_load(self):
198
+ """
199
+ Test setting and tripping load.
200
+ """
201
+ # --- run ACOPF ---
202
+ self.ss.ACOPF.run()
203
+ pgs = self.ss.ACOPF.pg.v.sum()
204
+
205
+ # --- set load ---
206
+ self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0.1)
207
+ self.ss.ACOPF.update()
208
+
209
+ self.ss.ACOPF.run()
210
+ pgs_pqt = self.ss.ACOPF.pg.v.sum()
211
+ self.assertLess(pgs_pqt, pgs, "Load set does not take effect!")
212
+
213
+ # --- trip load ---
214
+ self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0)
215
+ self.ss.ACOPF.update()
216
+
217
+ self.ss.ACOPF.run()
218
+ pgs_pqt2 = self.ss.ACOPF.pg.v.sum()
219
+ self.assertLess(pgs_pqt2, pgs_pqt, "Load trip does not take effect!")