oemof.solph package

Submodules

oemof.solph.blocks module

Creating sets, variables, constraints and parts of the objective function for the specified groups.

oemof.solph.components module

This module is designed to hold components with their classes and associated individual constraints (blocks) and groupings. Therefore this module holds the class definition and the block directly located by each other.

oemof.solph.constraints module

Additional constraints to be used in an oemof energy model.

oemof.solph.console_scripts module

This module can be used to check the installation.

This is not an illustrated example.

SPDX-FileCopyrightText: Uwe Krien <krien@uni-bremen.de> SPDX-FileCopyrightText: jnnr

SPDX-License-Identifier: MIT

oemof.solph.console_scripts.check_oemof_installation(silent=False)[source]

oemof.solph.custom module

This module is designed to hold in-development components with their classes and associated individual constraints (blocks) and groupings.

Requirements for documentation and unit tests are relaxed, so code within this module might not have production quality.

oemof.solph.groupings module

Groupings needed on an energy system for it to work with solph.

If you want to use solph on an energy system, you need to create it with these groupings specified like this:

from oemof.network import EnergySystem import solph

energy_system = EnergySystem(groupings=solph.GROUPINGS)

SPDX-FileCopyrightText: Uwe Krien <krien@uni-bremen.de> SPDX-FileCopyrightText: Simon Hilpert SPDX-FileCopyrightText: Cord Kaldemeyer SPDX-FileCopyrightText: Stephan Günther

SPDX-License-Identifier: MIT

oemof.solph.groupings.constraint_grouping(node, fallback=<function <lambda>>)[source]

Grouping function for constraints.

This function can be passed in a list to groupings of oemof.solph.network.EnergySystem.

Parameters:
  • node (Node <oemof.network.Node) – The node for which the figure out a constraint group.
  • fallback (callable, optional) – A function of one argument. If node doesn’t have a constraint_group attribute, this is used to group the node instead. Defaults to not group the node at all.

oemof.solph.helpers module

This is a collection of helper functions which work on their own and can be used by various classes. If there are too many helper-functions, they will be sorted in different modules.

SPDX-FileCopyrightText: Uwe Krien <krien@uni-bremen.de> SPDX-FileCopyrightText: Caroline Möller SPDX-FileCopyrightText: henhuy SPDX-FileCopyrightText: gplssm SPDX-FileCopyrightText: Stephan Günther SPDX-FileCopyrightText: elisapap

SPDX-License-Identifier: MIT

oemof.solph.helpers.calculate_timeincrement(timeindex, fill_value=None)[source]

Calculates timeincrement for timeindex

Parameters:
  • timeindex (pd.DatetimeIndex) – timeindex of energysystem
  • fill_value (numerical) – timeincrement for first timestep in hours
oemof.solph.helpers.extend_basic_path(subfolder)[source]

Returns a path based on the basic oemof path and creates it if necessary. The subfolder is the name of the path extension.

oemof.solph.helpers.flatten(d, parent_key='', sep='_')[source]

Flatten dictionary by compressing keys.

See: https://stackoverflow.com/questions/6027558/
flatten-nested-python-dictionaries-compressing-keys

d : dictionary sep : separator for flattening keys

Returns:dict
oemof.solph.helpers.get_basic_path()[source]

Returns the basic oemof path and creates it if necessary. The basic path is the ‘.oemof’ folder in the $HOME directory.

oemof.solph.models module

Solph Optimization Models.

SPDX-FileCopyrightText: Uwe Krien <krien@uni-bremen.de> SPDX-FileCopyrightText: Simon Hilpert SPDX-FileCopyrightText: Cord Kaldemeyer SPDX-FileCopyrightText: gplssm SPDX-FileCopyrightText: Patrik Schönfeldt

SPDX-License-Identifier: MIT

class oemof.solph.models.BaseModel(energysystem, **kwargs)[source]

Bases: pyomo.core.base.PyomoModel.ConcreteModel

The BaseModel for other solph-models (Model, MultiPeriodModel, etc.)

Parameters:
  • energysystem (EnergySystem object) – Object that holds the nodes of an oemof energy system graph
  • constraint_groups (list (optional)) – Solph looks for these groups in the given energy system and uses them to create the constraints of the optimization problem. Defaults to Model.CONSTRAINTS
  • objective_weighting (array like (optional)) – Weights used for temporal objective function expressions. If nothing is passed timeincrement will be used which is calculated from the freq length of the energy system timeindex .
  • auto_construct (boolean) – If this value is true, the set, variables, constraints, etc. are added, automatically when instantiating the model. For sequential model building process set this value to False and use methods _add_parent_block_sets, _add_parent_block_variables, _add_blocks, _add_objective
  • Attributes
  • ———–
  • timeincrement (sequence) – Time increments.
  • flows (dict) – Flows of the model.
  • name (str) – Name of the model.
  • es (solph.EnergySystem) – Energy system of the model.
  • meta (pyomo.opt.results.results_.SolverResults or None) – Solver results.
  • dual (… or None)
  • rc (… or None)
CONSTRAINT_GROUPS = []
receive_duals()[source]

Method sets solver suffix to extract information about dual variables from solver. Shadow prices (duals) and reduced costs (rc) are set as attributes of the model.

relax_problem()[source]

Relaxes integer variables to reals of optimization model self.

results()[source]

Returns a nested dictionary of the results of this optimization

solve(solver='cbc', solver_io='lp', **kwargs)[source]

Takes care of communication with solver to solve the model.

Parameters:
  • solver (string) – solver to be used e.g. “glpk”,”gurobi”,”cplex”
  • solver_io (string) – pyomo solver interface file format: “lp”,”python”,”nl”, etc.
  • **kwargs (keyword arguments) – Possible keys can be set see below:
Other Parameters:
 
  • solve_kwargs (dict) – Other arguments for the pyomo.opt.SolverFactory.solve() method Example : {“tee”:True}
  • cmdline_options (dict) – Dictionary with command line options for solver e.g. {“mipgap”:”0.01”} results in “–mipgap 0.01” {“interior”:” “} results in “–interior” Gurobi solver takes numeric parameter values such as {“method”: 2}
class oemof.solph.models.Model(energysystem, **kwargs)[source]

Bases: oemof.solph.models.BaseModel

An energy system model for operational and investment optimization.

Parameters:
  • energysystem (EnergySystem object) – Object that holds the nodes of an oemof energy system graph
  • constraint_groups (list) – Solph looks for these groups in the given energy system and uses them to create the constraints of the optimization problem. Defaults to Model.CONSTRAINTS
  • **The following basic sets are created**
  • NODES – A set with all nodes of the given energy system.
  • TIMESTEPS – A set with all timesteps of the given time horizon.
  • FLOWS – A 2 dimensional set with all flows. Index: (source, target)
  • **The following basic variables are created**
  • flow – Flow from source to target indexed by FLOWS, TIMESTEPS. Note: Bounds of this variable are set depending on attributes of the corresponding flow object.
CONSTRAINT_GROUPS = [<class 'oemof.solph.blocks.bus.Bus'>, <class 'oemof.solph.blocks.transformer.Transformer'>, <class 'oemof.solph.blocks.investment_flow.InvestmentFlow'>, <class 'oemof.solph.blocks.flow.Flow'>, <class 'oemof.solph.blocks.non_convex_flow.NonConvexFlow'>]

oemof.solph.network module

Classes used to model energy supply systems within solph.

Classes are derived from oemof core network classes and adapted for specific optimization tasks. An energy system is modelled as a graph/network of nodes with very specific constraints on which types of nodes are allowed to be connected.

oemof.solph.options module

Optional classes to be added to a network class.

SPDX-FileCopyrightText: Uwe Krien <krien@uni-bremen.de> SPDX-FileCopyrightText: Simon Hilpert SPDX-FileCopyrightText: Cord Kaldemeyer SPDX-FileCopyrightText: Stephan Günther SPDX-FileCopyrightText: Patrik Schönfeldt SPDX-FileCopyrightText: jmloenneberga

SPDX-License-Identifier: MIT

class oemof.solph.options.Investment(maximum=inf, minimum=0, ep_costs=0, existing=0, nonconvex=False, offset=0, **kwargs)[source]

Bases: object

Parameters:
  • maximum (float, P_{invest,max} or E_{invest,max}) – Maximum of the additional invested capacity
  • minimum (float, P_{invest,min} or E_{invest,min}) – Minimum of the additional invested capacity. If nonconvex is True, minimum defines the threshold for the invested capacity.
  • ep_costs (float, c_{invest,var}) – Equivalent periodical costs for the investment per flow capacity.
  • existing (float, P_{exist} or E_{exist}) – Existing / installed capacity. The invested capacity is added on top of this value. Not applicable if nonconvex is set to True.
  • nonconvex (bool) – If True, a binary variable for the status of the investment is created. This enables additional fix investment costs (offset) independent of the invested flow capacity. Therefore, use the offset parameter.
  • offset (float, c_{invest,fix}) – Additional fix investment costs. Only applicable if nonconvex is set to True.

For the variables, constraints and parts of the objective function, which are created, see oemof.solph.blocks.InvestmentFlow and oemof.solph.components.GenericInvestmentStorageBlock.

class oemof.solph.options.NonConvex(**kwargs)[source]

Bases: object

Parameters:
  • startup_costs (numeric (iterable or scalar)) – Costs associated with a start of the flow (representing a unit).
  • shutdown_costs (numeric (iterable or scalar)) – Costs associated with the shutdown of the flow (representing a unit).
  • activity_costs (numeric (iterable or scalar)) – Costs associated with the active operation of the flow, independently from the actual output.
  • minimum_uptime (numeric (1 or positive integer)) – Minimum time that a flow must be greater then its minimum flow after startup. Be aware that minimum up and downtimes can contradict each other and may lead to infeasible problems.
  • minimum_downtime (numeric (1 or positive integer)) – Minimum time a flow is forced to zero after shutting down. Be aware that minimum up and downtimes can contradict each other and may to infeasible problems.
  • maximum_startups (numeric (0 or positive integer)) – Maximum number of start-ups.
  • maximum_shutdowns (numeric (0 or positive integer)) – Maximum number of shutdowns.
  • initial_status (numeric (0 or 1)) – Integer value indicating the status of the flow in the first time step (0 = off, 1 = on). For minimum up and downtimes, the initial status is set for the respective values in the edge regions e.g. if a minimum uptime of four timesteps is defined, the initial status is fixed for the four first and last timesteps of the optimization period. If both, up and downtimes are defined, the initial status is set for the maximum of both e.g. for six timesteps if a minimum downtime of six timesteps is defined in addition to a four timestep minimum uptime.
max_up_down

Compute or return the _max_up_down attribute.

oemof.solph.plumbing module

Plumbing stuff.

SPDX-FileCopyrightText: Uwe Krien <krien@uni-bremen.de> SPDX-FileCopyrightText: Simon Hilpert SPDX-FileCopyrightText: Cord Kaldemeyer SPDX-FileCopyrightText: henhuy

SPDX-License-Identifier: MIT

oemof.solph.plumbing.sequence(iterable_or_scalar)[source]

Tests if an object is iterable (except string) or scalar and returns a the original sequence if object is an iterable and a ‘emulated’ sequence object of class _Sequence if object is a scalar or string.

Parameters:iterable_or_scalar (iterable or None or int or float)

Examples

>>> sequence([1,2])
[1, 2]
>>> x = sequence(10)
>>> x[0]
10
>>> x[10]
10
>>> print(x)
[10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]

oemof.solph.processing module

Modules for providing a convenient data structure for solph results.

Information about the possible usage is provided within the examples.

SPDX-FileCopyrightText: Uwe Krien <krien@uni-bremen.de> SPDX-FileCopyrightText: Simon Hilpert SPDX-FileCopyrightText: Cord Kaldemeyer SPDX-FileCopyrightText: Stephan Günther SPDX-FileCopyrightText: henhuy

SPDX-License-Identifier: MIT

oemof.solph.processing.convert_keys_to_strings(result, keep_none_type=False)[source]

Convert the dictionary keys to strings.

All (tuple) keys of the result object e.g. results[(pp1, bus1)] are converted into strings that represent the object labels e.g. results[(‘pp1’,’bus1’)].

oemof.solph.processing.create_dataframe(om)[source]

Create a result dataframe with all optimization data.

Results from Pyomo are written into pandas DataFrame where separate columns are created for the variable index e.g. for tuples of the flows and components or the timesteps.

oemof.solph.processing.get_timestep(x)[source]

Get the timestep from oemof tuples.

The timestep from tuples (n, n, int), (n, n), (n, int) and (n,) is fetched as the last element. For time-independent data (scalars) zero ist returned.

oemof.solph.processing.get_tuple(x)[source]

Get oemof tuple within iterable or create it.

Tuples from Pyomo are of type (n, n, int), (n, n) and (n, int). For single nodes n a tuple with one object (n,) is created.

oemof.solph.processing.meta_results(om, undefined=False)[source]

Fetch some meta data from the Solver. Feel free to add more keys.

Valid keys of the resulting dictionary are: ‘objective’, ‘problem’, ‘solver’.

om : oemof.solph.Model
A solved Model.
undefined : bool
By default (False) only defined keys can be found in the dictionary. Set to True to get also the undefined keys.
Returns:dict
oemof.solph.processing.parameter_as_dict(system, exclude_none=True)[source]

Create a result dictionary containing node parameters.

Results are written into a dictionary of pandas objects where a Series holds all scalar values and a dataframe all sequences for nodes and flows. The dictionary is keyed by flows (n, n) and nodes (n, None), e.g. parameter[(n, n)][‘sequences’] or parameter[(n, n)][‘scalars’].

Parameters:
  • system (energy_system.EnergySystem) – A populated energy system.
  • exclude_none (bool) – If True, all scalars and sequences containing None values are excluded
Returns:

dict (Parameters for all nodes and flows)

oemof.solph.processing.remove_timestep(x)[source]

Remove the timestep from oemof tuples.

The timestep is removed from tuples of type (n, n, int) and (n, int).

oemof.solph.processing.results(om)[source]

Create a result dictionary from the result DataFrame.

Results from Pyomo are written into a dictionary of pandas objects where a Series holds all scalar values and a dataframe all sequences for nodes and flows. The dictionary is keyed by the nodes e.g. results[idx][‘scalars’] and flows e.g. results[n, n][‘sequences’].

oemof.solph.views module

Modules for providing convenient views for solph results.

Information about the possible usage is provided within the examples.

SPDX-FileCopyrightText: Uwe Krien <krien@uni-bremen.de> SPDX-FileCopyrightText: Simon Hilpert SPDX-FileCopyrightText: Cord Kaldemeyer SPDX-FileCopyrightText: Stephan Günther SPDX-FileCopyrightText: henhuy

SPDX-License-Identifier: MIT

class oemof.solph.views.NodeOption[source]

Bases: str, enum.Enum

An enumeration.

All = 'all'
HasInputs = 'has_inputs'
HasOnlyInputs = 'has_only_inputs'
HasOnlyOutputs = 'has_only_outputs'
HasOutputs = 'has_outputs'
oemof.solph.views.convert_to_multiindex(group, index_names=None, droplevel=None)[source]

Convert dict to pandas DataFrame with multiindex

Parameters:
  • group (dict) – Sequences of the oemof.solph.Model.results dictionary
  • index_names (arraylike) – Array with names of the MultiIndex
  • droplevel (arraylike) – List containing levels to be dropped from the dataframe
oemof.solph.views.filter_nodes(results, option=<NodeOption.All: 'all'>, exclude_busses=False)[source]

Get set of nodes from results-dict for given node option.

This function filters nodes from results for special needs. At the moment, the following options are available:

Additionally, busses can be excluded by setting exclude_busses to True.

Parameters:
  • results (dict)
  • option (NodeOption)
  • exclude_busses (bool) – If set, all bus nodes are excluded from the resulting node set.
Returns:

set – A set of Nodes.

oemof.solph.views.get_node_by_name(results, *names)[source]

Searches results for nodes

Names are looked up in nodes from results and either returned single node (in case only one name is given) or as list of nodes. If name is not found, None is returned.

oemof.solph.views.net_storage_flow(results, node_type)[source]

Calculates the net storage flow for storage models that have one input edge and one output edge both with flows within the domain of non-negative reals.

Parameters:
  • results (dict) – A result dictionary from a solved oemof.solph.Model object
  • node_type (oemof.solph class) – Specifies the type for which (storage) type net flows are calculated
Returns:

  • pandas.DataFrame object with multiindex colums. Names of levels of columns
  • are (from, to, net_flow.)

Examples

import oemof.solph as solph from oemof.outputlib import views

# solve oemof solph model ‘m’ # Then collect node weights views.net_storage_flow(m.results(), node_type=solph.GenericStorage)

oemof.solph.views.node(results, node, multiindex=False, keep_none_type=False)[source]

Obtain results for a single node e.g. a Bus or Component.

Either a node or its label string can be passed. Results are written into a dictionary which is keyed by ‘scalars’ and ‘sequences’ holding respective data in a pandas Series and DataFrame.

oemof.solph.views.node_input_by_type(results, node_type, droplevel=None)[source]

Gets all inputs for all nodes of the type node_type and returns a dataframe.

Parameters:
  • results (dict) – A result dictionary from a solved oemof.solph.Model object
  • node_type (oemof.solph class) – Specifies the type of the node for that inputs are selected
  • droplevel (list)

Notes

from oemof import solph from oemof.outputlib import views

# solve oemof solph model ‘m’ # Then collect node weights views.node_input_by_type(m.results(), node_type=solph.Sink)

oemof.solph.views.node_output_by_type(results, node_type, droplevel=None)[source]

Gets all outputs for all nodes of the type node_type and returns a dataframe.

Parameters:
  • results (dict) – A result dictionary from a solved oemof.solph.Model object
  • node_type (oemof.solph class) – Specifies the type of the node for that outputs are selected
  • droplevel (list)

Notes

import oemof.solph as solph from oemof.outputlib import views

# solve oemof solph model ‘m’ # Then collect node weights views.node_output_by_type(m.results(), node_type=solph.Transformer)

oemof.solph.views.node_weight_by_type(results, node_type)[source]

Extracts node weights (if exist) of all components of the specified node_type.

Node weight are endogenous optimzation variables associated with the node and not the edge between two node, foxample the variable representing the storage level.

Parameters:
  • results (dict) – A result dictionary from a solved oemof.solph.Model object
  • node_type (oemof.solph class) – Specifies the type for which node weights should be collected

Example

from oemof.outputlib import views

# solve oemof model ‘m’ # Then collect node weights views.node_weight_by_type(m.results(), node_type=solph.GenericStorage)