Passed
Pull Request — dev (#821)
by Uwe
02:17
created

solph._console_scripts.check_oemof_installation()   B

Complexity

Conditions 5

Size

Total Lines 46
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 37
dl 0
loc 46
rs 8.5253
c 0
b 0
f 0
cc 5
nop 1
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(silent=False):
22
    logging.disable(logging.CRITICAL)
23
24
    date_time_index = pd.date_range("1/1/2012", periods=5, freq="H")
25
    energysystem = solph.EnergySystem(timeindex=date_time_index)
26
27
    bgas = solph.buses.Bus(label="natural_gas")
28
    bel = solph.buses.Bus(label="electricity")
29
    solph.components.Sink(label="excess_bel", inputs={bel: solph.flows.Flow()})
30
    solph.components.Source(label="rgas", outputs={bgas: solph.flows.Flow()})
31
    solph.components.Sink(
32
        label="demand",
33
        inputs={
34
            bel: solph.flows.Flow(fix=[10, 20, 30, 40, 50], nominal_value=1)
35
        },
36
    )
37
    solph.components.Transformer(
38
        label="pp_gas",
39
        inputs={bgas: solph.flows.Flow()},
40
        outputs={
41
            bel: solph.flows.Flow(nominal_value=10e10, variable_costs=50)
42
        },
43
        conversion_factors={bel: 0.58},
44
    )
45
    om = solph.Model(energysystem)
46
47
    # check solvers
48
    solver = dict()
49
    for s in ["cbc", "glpk", "gurobi", "cplex"]:
50
        try:
51
            om.solve(solver=s)
52
            solver[s] = "working"
53
        except Exception:
54
            solver[s] = "not working"
55
56
    if not silent:
57
        print()
58
        print("*****************************")
59
        print("Solver installed with oemof:")
60
        print()
61
        for s, t in solver.items():
62
            print("{0}: {1}".format(s, t))
63
        print()
64
        print("*****************************")
65
        print("oemof successfully installed.")
66
        print("*****************************")
67