-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest_3_scopflow.py
218 lines (188 loc) · 6.39 KB
/
test_3_scopflow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
from check_preconditions import check_preconditions
import tempfile
import os
import shutil
import pytest
import mpi4py.rc
mpi4py.rc.threads = False
from mpi4py import MPI # noqa
check_preconditions()
import exago # noqa
exago_ignore = -1000000
@pytest.mark.nocomm
@pytest.mark.MPI
def test_creating_scopflow():
'''Testing creation of scopflow object'''
opf = exago.SCOPFLOW()
@pytest.mark.nocomm
@pytest.mark.MPI
def test_set_initialization_ints():
'''Testing setting initialization type via integers'''
scopf = exago.SCOPFLOW()
opf = exago.OPFLOW()
types = opf.get_initialization_types()
del opf
# List of possible enum values (object list)
print(types)
for i in range(0, len(types)):
scopf.set_initialization_type(types[i])
@pytest.mark.nocomm
@pytest.mark.MPI
def test_set_initialization_strings():
'''Testing setting initialization type via strings'''
scopf = exago.SCOPFLOW()
types = list(exago.OPFLOWInitializationType.__members__.items())
# List of tuple pairs of stringy values and corresponding enum value
print(types)
for i in range(0, len(types)):
scopf.set_initialization_type(types[i][0])
@pytest.mark.nocomm
@pytest.mark.MPI
def test_set_genbusvoltage_ints():
'''Testing setting gen bus voltage type via ints'''
scopf = exago.SCOPFLOW()
opf = exago.OPFLOW()
types = opf.get_gen_bus_voltage_types()
del opf
# List of possible enum values (object list)
print(types)
for i in range(0, len(types)):
scopf.set_gen_bus_voltage_type(types[i])
@pytest.mark.nocomm
@pytest.mark.MPI
def test_set_genbusvoltage_strings():
'''Testing setting gen bus voltage type via strings'''
scopf = exago.SCOPFLOW()
types = list(exago.OPFLOWGenBusVoltageType.__members__.items())
# List of tuple pairs of stringy values and corresponding enum value
print(types)
for i in range(0, len(types)):
scopf.set_gen_bus_voltage_type(types[i][0])
@pytest.mark.nocomm
@pytest.mark.MPI
def test_tolerance_scopflow():
'''Testing setting tolerance in scopflow object'''
scopf = exago.SCOPFLOW()
scopf.set_tolerance(1e-6)
tol = scopf.get_tolerance()
assert isinstance(tol, float)
assert tol == 1e-6
scopf.set_tolerance(1e-5)
tol = scopf.get_tolerance()
assert isinstance(tol, float)
assert tol == 1e-5
@pytest.mark.nocomm
@pytest.mark.MPI
def test_set_time_step_and_duration():
'''Testing setting time step, duration, and both'''
scopf = exago.SCOPFLOW()
# No getters available
scopf.set_time_step(1.0E-04)
scopf.set_duration(10.0)
scopf.set_time_step_and_duration(1.0E-04, 10.0)
@pytest.mark.nocomm
@pytest.mark.MPI
def test_set_network():
'''Test reading network data'''
scopf = exago.SCOPFLOW()
path = exago.prefix()
scopf.set_network_data(
os.path.join(path, 'share', 'exago',
'datafiles', 'case9', 'case9mod.m'))
@pytest.mark.nocomm
@pytest.mark.MPI
def test_set_contingency_data():
'''Test reading contingency data'''
scopf = exago.SCOPFLOW()
path = exago.prefix()
scopf.set_network_data(
os.path.join(path, 'share', 'exago',
'datafiles', 'case9', 'case9mod.m'))
scopf.set_contingency_data(
os.path.join(path, 'share', 'exago',
'datafiles', 'case9', 'case9.cont'),
exago.ContingencyFileInputFormat.NATIVE
)
@pytest.mark.nocomm
@pytest.mark.MPI
def test_set_load_data():
'''Test reading load data'''
scopf = exago.SCOPFLOW()
path = exago.prefix()
scopf.set_network_data(
os.path.join(path, 'share', 'exago',
'datafiles', 'case9', 'case9mod.m'))
scopf.set_contingency_data(
os.path.join(path, 'share', 'exago',
'datafiles', 'case9', 'case9.cont'),
exago.ContingencyFileInputFormat.NATIVE
)
scopf.set_pload_data(
os.path.join(path, 'share', 'exago',
'datafiles', 'case9', 'load_P.csv')
)
scopf.set_qload_data(
os.path.join(path, 'share', 'exago',
'datafiles', 'case9', 'load_Q.csv')
)
@pytest.mark.nocomm
@pytest.mark.MPI
def test_set_load_profiles():
'''Test reading load profiles'''
scopf = exago.SCOPFLOW()
path = exago.prefix()
scopf.set_network_data(
os.path.join(path, 'share', 'exago',
'datafiles', 'case9', 'case9mod.m'))
scopf.set_contingency_data(
os.path.join(path, 'share', 'exago',
'datafiles', 'case9', 'case9.cont'),
exago.ContingencyFileInputFormat.NATIVE
)
scopf.set_load_profiles(
os.path.join(path, 'share', 'exago',
'datafiles', 'case9', 'load_P.csv'),
os.path.join(path, 'share', 'exago',
'datafiles', 'case9', 'load_Q.csv')
)
@pytest.mark.nocomm
@pytest.mark.MPI
def test_complete_scopflow_solve():
'''Testing scopflow solve'''
scopf = exago.SCOPFLOW()
path = exago.prefix()
scopf.set_network_data(os.path.join(
path, 'share', 'exago', 'datafiles', 'case9', 'case9mod.m'))
scopf.set_contingency_data(os.path.join(
path, 'share', 'exago', 'datafiles', 'case9', 'case9.cont'),
exago.ContingencyFileInputFormat.NATIVE
)
scopf.set_tolerance(1.0E-03)
scopf.set_solver('IPOPT')
scopf.set_model('GENRAMP')
scopf.set_initialization_type(
exago.OPFLOWInitializationType.OPFLOWINIT_ACPF
)
scopf.set_num_contingencies(-1)
scopf.set_subproblem_model('POWER_BALANCE_POLAR')
scopf.set_subproblem_solver('IPOPT')
scopf.set_gen_bus_voltage_type('VARIABLE_WITHIN_BOUNDS')
scopf.enable_multi_period(False)
scopf.enable_power_imbalance_variables(True)
scopf.set_verbosity_level(3)
scopf.set_mode(0)
scopf.set_up()
scopf.solve()
scopf.print_solution(0)
oname = os.path.join(tempfile.gettempdir(), "scopflow_test_solution.csv")
scopf.save_solution(0, exago.OutputFormat.CSV, oname)
assert os.path.exists(oname)
os.unlink(oname)
oname = os.path.join(tempfile.gettempdir(), "scopflow_test_solution.m")
scopf.save_solution(0, exago.OutputFormat.MATPOWER, oname)
assert os.path.exists(oname)
os.unlink(oname)
oname = os.path.join(tempfile.gettempdir(), "scopflow_test_solution_dir")
scopf.save_solution_all(exago.OutputFormat.MATPOWER, oname)
assert os.path.exists(oname)
shutil.rmtree(oname)