-
Notifications
You must be signed in to change notification settings - Fork 439
/
test_ac_dc_lopf.py
93 lines (77 loc) · 1.98 KB
/
test_ac_dc_lopf.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
import pypsa
import os
import pytest
from numpy.testing import assert_array_almost_equal as equal
import sys
solver_name = 'glpk'
@pytest.fixture
def n():
csv_folder = os.path.join(
os.path.dirname(__file__),
"..",
"examples",
"ac-dc-meshed",
"ac-dc-data"
)
return pypsa.Network(csv_folder)
@pytest.fixture
def n_r():
csv_folder = os.path.join(
os.path.dirname(__file__),
"..",
"examples",
"ac-dc-meshed",
"ac-dc-data",
"results-lopf"
)
return pypsa.Network(csv_folder)
@pytest.mark.parametrize("formulation", ["angles", "cycles", "kirchhoff", "ptdf"])
@pytest.mark.parametrize("free_memory", [{}, {"pypsa"}])
def test_lopf(n, n_r, formulation, free_memory):
"""
Test results were generated with GLPK; solution should be unique,
so other solvers should not differ (e.g. cbc or gurobi)
"""
n.lopf(
snapshots=n.snapshots,
solver_name=solver_name,
formulation=formulation,
free_memory=free_memory
)
equal(
n.generators_t.p.loc[:,n.generators.index],
n_r.generators_t.p.loc[:,n.generators.index],
decimal=4
)
equal(
n.lines_t.p0.loc[:,n.lines.index],
n_r.lines_t.p0.loc[:,n.lines.index],
decimal=4
)
equal(
n.links_t.p0.loc[:,n.links.index],
n_r.links_t.p0.loc[:,n.links.index],
decimal=4
)
def test_lopf_lowmem(n, n_r):
status, _ = n.lopf(
snapshots=n.snapshots,
solver_name=solver_name,
pyomo=False
)
assert status == 'ok'
equal(
n.generators_t.p.loc[:,n.generators.index],
n_r.generators_t.p.loc[:,n.generators.index],
decimal=2
)
equal(
n.lines_t.p0.loc[:,n.lines.index],
n_r.lines_t.p0.loc[:,n.lines.index],
decimal=2
)
equal(
n.links_t.p0.loc[:,n.links.index],
n_r.links_t.p0.loc[:,n.links.index],
decimal=2
)