ltbams 1.0.12__py3-none-any.whl → 1.0.14__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.
- ams/_version.py +3 -3
- ams/cli.py +2 -7
- ams/core/common.py +7 -3
- ams/core/documenter.py +2 -1
- ams/core/matprocessor.py +174 -108
- ams/core/model.py +14 -6
- ams/core/param.py +5 -3
- ams/core/symprocessor.py +8 -2
- ams/core/var.py +1 -1
- ams/extension/eva.py +11 -7
- ams/interface.py +7 -7
- ams/io/json.py +20 -16
- ams/io/matpower.py +10 -6
- ams/io/psse.py +4 -1
- ams/io/xlsx.py +21 -16
- ams/main.py +53 -45
- ams/models/distributed/esd1.py +4 -7
- ams/models/distributed/ev.py +10 -6
- ams/models/distributed/pvd1.py +4 -7
- ams/models/group.py +17 -18
- ams/models/renewable/regc.py +14 -22
- ams/models/timeslot.py +30 -0
- ams/models/zone.py +2 -4
- ams/opt/exprcalc.py +11 -0
- ams/opt/optzbase.py +4 -3
- ams/report.py +2 -7
- ams/routines/dcopf.py +7 -4
- ams/routines/dcopf2.py +14 -4
- ams/routines/dopf.py +2 -2
- ams/routines/ed.py +5 -5
- ams/routines/grbopt.py +2 -0
- ams/routines/pflow.py +1 -1
- ams/routines/pypower.py +8 -0
- ams/routines/routine.py +125 -1
- ams/routines/rted.py +5 -5
- ams/routines/uc.py +2 -2
- ams/shared.py +99 -2
- ams/system.py +103 -18
- ams/utils/paths.py +6 -10
- docs/source/genroutineref.py +12 -0
- docs/source/index.rst +4 -3
- docs/source/release-notes.rst +14 -0
- {ltbams-1.0.12.dist-info → ltbams-1.0.14.dist-info}/METADATA +21 -23
- {ltbams-1.0.12.dist-info → ltbams-1.0.14.dist-info}/RECORD +47 -75
- {ltbams-1.0.12.dist-info → ltbams-1.0.14.dist-info}/top_level.txt +0 -1
- tests/__init__.py +0 -0
- tests/test_1st_system.py +0 -64
- tests/test_addressing.py +0 -40
- tests/test_case.py +0 -301
- tests/test_cli.py +0 -34
- tests/test_export_csv.py +0 -89
- tests/test_group.py +0 -83
- tests/test_interface.py +0 -238
- tests/test_io.py +0 -190
- tests/test_jumper.py +0 -27
- tests/test_known_good.py +0 -267
- tests/test_matp.py +0 -437
- tests/test_model.py +0 -54
- tests/test_omodel.py +0 -119
- tests/test_paths.py +0 -89
- tests/test_report.py +0 -251
- tests/test_repr.py +0 -21
- tests/test_routine.py +0 -178
- tests/test_rtn_acopf.py +0 -75
- tests/test_rtn_dcopf.py +0 -121
- tests/test_rtn_dcopf2.py +0 -103
- tests/test_rtn_ed.py +0 -279
- tests/test_rtn_opf.py +0 -142
- tests/test_rtn_pflow.py +0 -147
- tests/test_rtn_pypower.py +0 -315
- tests/test_rtn_rted.py +0 -273
- tests/test_rtn_uc.py +0 -248
- tests/test_service.py +0 -73
- {ltbams-1.0.12.dist-info → ltbams-1.0.14.dist-info}/WHEEL +0 -0
- {ltbams-1.0.12.dist-info → ltbams-1.0.14.dist-info}/entry_points.txt +0 -0
tests/test_rtn_ed.py
DELETED
@@ -1,279 +0,0 @@
|
|
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.json"),
|
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.json"),
|
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_demo.json"),
|
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(solver='SCIP')
|
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(solver='SCIP')
|
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='Line_3', value=0)
|
249
|
-
self.ss.EDES.run(solver='SCIP')
|
250
|
-
self.assertTrue(self.ss.EDES.converged, "EDES did not converge!")
|
251
|
-
plf_l3 = self.ss.EDES.get(src='plf', attr='v', idx='Line_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='Line_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(solver='SCIP')
|
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(solver='SCIP')
|
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(solver='SCIP')
|
278
|
-
pgs_pqt2 = self.ss.EDES.pg.v.sum()
|
279
|
-
self.assertLess(pgs_pqt2, pgs_pqt, "Load trip does not take effect!")
|
tests/test_rtn_opf.py
DELETED
@@ -1,142 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Test wrapper routines of gurobi_optimodes.
|
3
|
-
"""
|
4
|
-
import unittest
|
5
|
-
|
6
|
-
import ams
|
7
|
-
from ams.shared import skip_unittest_without_gurobi_optimods
|
8
|
-
|
9
|
-
|
10
|
-
class TestOPF(unittest.TestCase):
|
11
|
-
"""
|
12
|
-
Test routine `OPF` in DC.
|
13
|
-
"""
|
14
|
-
|
15
|
-
def setUp(self) -> None:
|
16
|
-
self.ss = ams.load(ams.get_case("5bus/pjm5bus_demo.json"),
|
17
|
-
setup=True, default_config=True, no_output=True)
|
18
|
-
# decrease load first
|
19
|
-
self.ss.PQ.set(src='p0', attr='v', idx=['PQ_1', 'PQ_2'], value=[0.3, 0.3])
|
20
|
-
|
21
|
-
def test_init(self):
|
22
|
-
"""
|
23
|
-
Test initialization.
|
24
|
-
"""
|
25
|
-
self.ss.OPF.init()
|
26
|
-
self.assertTrue(self.ss.OPF.initialized, "OPF initialization failed!")
|
27
|
-
|
28
|
-
@skip_unittest_without_gurobi_optimods
|
29
|
-
def test_trip_gen(self):
|
30
|
-
"""
|
31
|
-
Test generator tripping.
|
32
|
-
"""
|
33
|
-
stg = 'PV_1'
|
34
|
-
self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=0)
|
35
|
-
|
36
|
-
self.ss.OPF.update()
|
37
|
-
self.ss.OPF.run(opftype='DC')
|
38
|
-
self.assertTrue(self.ss.OPF.converged, "OPF in DC did not converge under generator trip!")
|
39
|
-
self.assertAlmostEqual(self.ss.OPF.get(src='pg', attr='v', idx=stg),
|
40
|
-
0, places=6,
|
41
|
-
msg="Generator trip does not take effect!")
|
42
|
-
|
43
|
-
self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=1) # reset
|
44
|
-
|
45
|
-
@skip_unittest_without_gurobi_optimods
|
46
|
-
def test_trip_gen_ac(self):
|
47
|
-
"""
|
48
|
-
Test generator tripping.
|
49
|
-
"""
|
50
|
-
stg = 'PV_1'
|
51
|
-
self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=0)
|
52
|
-
|
53
|
-
self.ss.OPF.update()
|
54
|
-
self.ss.OPF.run(opftype='AC')
|
55
|
-
self.assertTrue(self.ss.OPF.converged, "OPF in AC did not converge under generator trip!")
|
56
|
-
self.assertAlmostEqual(self.ss.OPF.get(src='pg', attr='v', idx=stg),
|
57
|
-
0, places=6,
|
58
|
-
msg="Generator trip does not take effect!")
|
59
|
-
|
60
|
-
self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=1) # reset
|
61
|
-
|
62
|
-
@skip_unittest_without_gurobi_optimods
|
63
|
-
def test_trip_line(self):
|
64
|
-
"""
|
65
|
-
Test line tripping.
|
66
|
-
"""
|
67
|
-
self.ss.Line.set(src='u', attr='v', idx='Line_3', value=0)
|
68
|
-
|
69
|
-
self.ss.OPF.update()
|
70
|
-
self.ss.OPF.run(opftype='DC')
|
71
|
-
self.assertTrue(self.ss.OPF.converged, "OPF in DC did not converge under line trip!")
|
72
|
-
self.assertAlmostEqual(self.ss.OPF.get(src='plf', attr='v', idx='Line_3'),
|
73
|
-
0, places=6,
|
74
|
-
msg="Line trip does not take effect!")
|
75
|
-
|
76
|
-
self.ss.Line.alter(src='u', idx='Line_3', value=1) # reset
|
77
|
-
|
78
|
-
@skip_unittest_without_gurobi_optimods
|
79
|
-
def test_trip_line_ac(self):
|
80
|
-
"""
|
81
|
-
Test line tripping.
|
82
|
-
"""
|
83
|
-
self.ss.Line.set(src='u', attr='v', idx='Line_3', value=0)
|
84
|
-
|
85
|
-
self.ss.OPF.update()
|
86
|
-
self.ss.OPF.run(opftype='AC')
|
87
|
-
self.assertTrue(self.ss.OPF.converged, "OPF in AC did not converge under line trip!")
|
88
|
-
self.assertAlmostEqual(self.ss.OPF.get(src='plf', attr='v', idx='Line_3'),
|
89
|
-
0, places=6,
|
90
|
-
msg="Line trip does not take effect!")
|
91
|
-
|
92
|
-
self.ss.Line.alter(src='u', idx='Line_3', value=1) # reset
|
93
|
-
|
94
|
-
@skip_unittest_without_gurobi_optimods
|
95
|
-
def test_set_load(self):
|
96
|
-
"""
|
97
|
-
Test setting and tripping load.
|
98
|
-
"""
|
99
|
-
# --- run OPF ---
|
100
|
-
self.ss.OPF.run(opftype='DC')
|
101
|
-
pgs = self.ss.OPF.pg.v.sum()
|
102
|
-
|
103
|
-
# --- set load ---
|
104
|
-
self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0.1)
|
105
|
-
self.ss.OPF.update()
|
106
|
-
|
107
|
-
self.ss.OPF.run(opftype='DC')
|
108
|
-
pgs_pqt = self.ss.OPF.pg.v.sum()
|
109
|
-
self.assertLess(pgs_pqt, pgs, "Load set does not take effect!")
|
110
|
-
|
111
|
-
# --- trip load ---
|
112
|
-
self.ss.PQ.set(src='u', attr='v', idx='PQ_2', value=0)
|
113
|
-
self.ss.OPF.update()
|
114
|
-
|
115
|
-
self.ss.OPF.run(opftype='DC')
|
116
|
-
pgs_pqt2 = self.ss.OPF.pg.v.sum()
|
117
|
-
self.assertLess(pgs_pqt2, pgs_pqt, "Load trip does not take effect!")
|
118
|
-
|
119
|
-
@skip_unittest_without_gurobi_optimods
|
120
|
-
def test_set_load_ac(self):
|
121
|
-
"""
|
122
|
-
Test setting and tripping load.
|
123
|
-
"""
|
124
|
-
# --- run OPF ---
|
125
|
-
self.ss.OPF.run(opftype='AC')
|
126
|
-
pgs = self.ss.OPF.pg.v.sum()
|
127
|
-
|
128
|
-
# --- set load ---
|
129
|
-
self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0.1)
|
130
|
-
self.ss.OPF.update()
|
131
|
-
|
132
|
-
self.ss.OPF.run(opftype='AC')
|
133
|
-
pgs_pqt = self.ss.OPF.pg.v.sum()
|
134
|
-
self.assertLess(pgs_pqt, pgs, "Load set does not take effect!")
|
135
|
-
|
136
|
-
# --- trip load ---
|
137
|
-
self.ss.PQ.set(src='u', attr='v', idx='PQ_2', value=0)
|
138
|
-
self.ss.OPF.update()
|
139
|
-
|
140
|
-
self.ss.OPF.run(opftype='AC')
|
141
|
-
pgs_pqt2 = self.ss.OPF.pg.v.sum()
|
142
|
-
self.assertLess(pgs_pqt2, pgs_pqt, "Load trip does not take effect!")
|
tests/test_rtn_pflow.py
DELETED
@@ -1,147 +0,0 @@
|
|
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!")
|