1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
|
3
|
|
|
"""This module can be used to check the installation. |
4
|
|
|
|
5
|
|
|
This is not an illustrated example. |
6
|
|
|
|
7
|
|
|
SPDX-FileCopyrightText: Uwe Krien <[email protected]> |
8
|
|
|
SPDX-FileCopyrightText: jnnr |
9
|
|
|
|
10
|
|
|
SPDX-License-Identifier: MIT |
11
|
|
|
|
12
|
|
|
""" |
13
|
|
|
|
14
|
|
|
import logging |
15
|
|
|
|
16
|
|
|
import pandas as pd |
17
|
|
|
|
18
|
|
|
from oemof import solph |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
def _check_oemof_installation(solvers): |
22
|
|
|
logging.disable(logging.CRITICAL) |
23
|
|
|
|
24
|
|
|
date_time_index = pd.date_range("1/1/2012", periods=6, freq="h") |
25
|
|
|
energysystem = solph.EnergySystem( |
26
|
|
|
timeindex=date_time_index, |
27
|
|
|
infer_last_interval=False, |
28
|
|
|
) |
29
|
|
|
|
30
|
|
|
bgas = solph.buses.Bus(label="natural_gas") |
31
|
|
|
bel = solph.buses.Bus(label="electricity") |
32
|
|
|
solph.components.Sink(label="excess_bel", inputs={bel: solph.flows.Flow()}) |
33
|
|
|
solph.components.Source(label="rgas", outputs={bgas: solph.flows.Flow()}) |
34
|
|
|
solph.components.Sink( |
35
|
|
|
label="demand", |
36
|
|
|
inputs={ |
37
|
|
|
bel: solph.flows.Flow(fix=[10, 20, 30, 40, 50], nominal_value=1) |
38
|
|
|
}, |
39
|
|
|
) |
40
|
|
|
solph.components.Converter( |
41
|
|
|
label="pp_gas", |
42
|
|
|
inputs={bgas: solph.flows.Flow()}, |
43
|
|
|
outputs={ |
44
|
|
|
bel: solph.flows.Flow(nominal_value=10e10, variable_costs=50) |
45
|
|
|
}, |
46
|
|
|
conversion_factors={bel: 0.58}, |
47
|
|
|
) |
48
|
|
|
om = solph.Model(energysystem) |
49
|
|
|
|
50
|
|
|
# check solvers |
51
|
|
|
solver_status = dict() |
52
|
|
|
for s in solvers: |
53
|
|
|
try: |
54
|
|
|
om.solve(solver=s) |
55
|
|
|
solver_status[s] = True |
56
|
|
|
except Exception: |
57
|
|
|
solver_status[s] = False |
58
|
|
|
|
59
|
|
|
return solver_status |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
def check_oemof_installation(): |
63
|
|
|
|
64
|
|
|
solvers_to_test = ["cbc", "glpk", "gurobi", "cplex"] |
65
|
|
|
|
66
|
|
|
solver_status = _check_oemof_installation(solvers_to_test) |
67
|
|
|
|
68
|
|
|
print_text = ( |
69
|
|
|
"***********************************\n" |
70
|
|
|
"Solver installed with oemof.solph:\n" |
71
|
|
|
"\n" |
72
|
|
|
) |
73
|
|
|
for solver, works in solver_status.items(): |
74
|
|
|
if works: |
75
|
|
|
print_text += f"{solver}: installed and working\n" |
76
|
|
|
else: |
77
|
|
|
print_text += f"{solver}: not installed/ not working\n" |
78
|
|
|
print_text += ( |
79
|
|
|
"\n" |
80
|
|
|
"***********************************\n" |
81
|
|
|
"oemof.solph successfully installed.\n" |
82
|
|
|
"***********************************\n" |
83
|
|
|
) |
84
|
|
|
|
85
|
|
|
print(print_text) |
86
|
|
|
|