Skip to content

Commit fd288e6

Browse files
committed
update tcopflow test outline
1 parent ecd641f commit fd288e6

File tree

3 files changed

+66
-25
lines changed

3 files changed

+66
-25
lines changed

interfaces/python/exago_python_tcopflow.cpp

+13-16
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,25 @@ void init_exago_tcopflow(pybind11::module &m) {
3030

3131
pybind11::class_<TCOPFLOW_wrapper>(m, "TCOPFLOW")
3232
.def(pybind11::init())
33+
.def("set_up",
34+
[](TCOPFLOW_wrapper &w) {
35+
PetscErrorCode ierr;
36+
ierr = TCOPFLOWSetUp(w.tcopf);
37+
ExaGOCheckError(ierr);
38+
})
3339
.def("set_tolerance",
3440
[](TCOPFLOW_wrapper &w, double tol) {
3541
PetscErrorCode ierr;
3642
ierr = TCOPFLOWSetTolerance(w.tcopf, tol);
3743
ExaGOCheckError(ierr);
3844
})
39-
.def("get_tolerance", [](TCOPFLOW_wrapper &w) -> double {
40-
PetscErrorCode ierr;
41-
double tol;
42-
ierr = TCOPFLOWGetTolerance(w.tcopf, &tol);
43-
ExaGOCheckError(ierr);
44-
return tol;
45+
.def("get_tolerance",
46+
[](TCOPFLOW_wrapper &w) -> double {
47+
PetscErrorCode ierr;
48+
double tol;
49+
ierr = TCOPFLOWGetTolerance(w.tcopf, &tol);
50+
ExaGOCheckError(ierr);
51+
return tol;
4552
});
4653

47-
/* Setters */
48-
49-
// Example
50-
// .def("set_model",
51-
// [](SOPFLOW_wrapper &w, std::string model) {
52-
// PetscErrorCode ierr;
53-
// ierr = SOPFLOWSetModel(w.sopf, model.c_str());
54-
// ExaGOCheckError(ierr);
55-
// })
56-
;
5754
}

tests/interfaces/python/CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ exago_add_test(
5757
"
5858
export PYTHONPATH=${pythonpath}
5959
cd ${PROJECT_SOURCE_DIR}/tests/interfaces/python
60-
${CMD} -m MPI -v ${TEST_FILES}
60+
${CMD} -m MPI -v ${TEST_FILES}
6161
"
6262
DEPENDS
6363
MPI
6464
)
65+
66+
# add --capture=no flag to pytest to see full output, maybe a --full-trace too
67+
# ${CMD} --capture=no -m MPI -v ${TEST_FILES}

tests/interfaces/python/test_5_tcopflow.py

+49-8
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,61 @@
1212

1313
exago_ignore = -1000000
1414

15-
16-
@pytest.mark.nocomm
17-
@pytest.mark.MPI
15+
''' cannot run just creating tcopflow object bc opflow sub objects
16+
won't be allocated (done in TCOPFLOWSetUp) so destructor seg faults
1817
def test_creating_tcopflow():
19-
'''Testing creation of tcopflow object'''
2018
tcopf = exago.TCOPFLOW()
19+
'''
20+
def run_tcopflow(solver):
21+
tcopf = exago.TCOPFLOW()
22+
path = exago.prefix()
23+
24+
tcopf.set_tolerance(1.0E-03)
25+
tcopf.set_network_data(os.path.join(
26+
path, 'share', 'exago', 'datafiles', 'case9', 'case9mod_gen3_wind.m'))
27+
tcopf.set_solver(solver)
28+
#set_time_step_and_duration
29+
#set_load_profiles
30+
#set_wind_gen_profiles
31+
32+
tcopf.setup()
33+
tcopf.solve()
34+
35+
assert tcopf.get_convergence_status()
2136

37+
obj = tcopf.get_objective()
38+
assert isinstance(obj, float)
2239

40+
n = tcopf.get_num_iterations()
41+
assert isinstance(n, int)
42+
43+
#get_solution
44+
#print_solution
45+
46+
oname = os.path.join(tempfile.gettempdir(), "tcopflow_test_solution.csv")
47+
tcopf.save_solution(0, exago.OutputFormat.CSV, oname)
48+
assert os.path.exists(oname)
49+
os.unlink(oname)
50+
51+
oname = os.path.join(tempfile.gettempdir(), "tcopflow_test_solution.m")
52+
tcopf.save_solution(0, exago.OutputFormat.MATPOWER, oname)
53+
assert os.path.exists(oname)
54+
os.unlink(oname)
55+
56+
oname = os.path.join(tempfile.gettempdir(), "tcopflow_test_solution_dir")
57+
tcopf.save_solution_all(exago.OutputFormat.MATPOWER, oname)
58+
assert os.path.exists(oname)
59+
shutil.rmtree(oname)
60+
61+
62+
# From sopflow_multicontingency.toml:
63+
# description =
64+
# 'datafiles/case9/case9mod_gen3_wind.m IPOPT 3scen contingencies SOPFLOW'
2365
@pytest.mark.nocomm
2466
@pytest.mark.MPI
25-
def test_get_prefix():
26-
'''Test retrieving datafile path'''
27-
path = exago.prefix()
28-
assert isinstance(path, str)
67+
def test_tcopflow_1():
68+
run_tcopflow('IPOPT')
69+
2970

3071

3172
''' example

0 commit comments

Comments
 (0)