Skip to content

Commit

Permalink
Merge pull request #943 from oemof/fix/gh-actions
Browse files Browse the repository at this point in the history
Fix GitHub actions
  • Loading branch information
p-snft authored Jun 6, 2023
2 parents 9627d12 + bbb7222 commit 7040c22
Show file tree
Hide file tree
Showing 137 changed files with 7,229 additions and 7,683 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def read(*names, **kwargs):
"dill",
"numpy",
"pandas >= 1.5.3",
"pyomo >= 6.0.0, < 7.0",
"pyomo >= 6.6.0, < 7.0",
"networkx",
"oemof.tools >= 0.4.2",
"oemof.network >= 0.5.0a1",
Expand Down
89 changes: 24 additions & 65 deletions tests/constraint_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

import logging
import re
from difflib import unified_diff
from os import path as ospath

import pandas as pd
import pytest
from pyomo.repn.tests.lp_diff import lp_diff

from oemof import solph

Expand Down Expand Up @@ -69,70 +69,29 @@ def compare_lp_files(self, filename, ignored=None, my_om=None):
filename,
)
) as expected_file:

def chop_trailing_whitespace(lines):
return [re.sub(r"\s*$", "", ln) for ln in lines]

def remove(pattern, lines):
if not pattern:
return lines
return re.subn(pattern, "", "\n".join(lines))[0].split(
"\n"
)

expected = remove(
ignored,
chop_trailing_whitespace(expected_file.readlines()),
)
generated = remove(
ignored,
chop_trailing_whitespace(generated_file.readlines()),
)

def normalize_to_positive_results(lines):
negative_result_indices = [
n
for n, line in enumerate(lines)
if re.match("^= -", line)
]
equation_start_indices = [
[
n
for n in reversed(range(0, nri))
if re.match(".*:$", lines[n])
][0]
+ 1
for nri in negative_result_indices
]
for start, end in zip(
equation_start_indices, negative_result_indices
):
for n in range(start, end):
lines[n] = (
"-"
if lines[n] and lines[n][0] == "+"
else "+"
if lines[n]
else lines[n]
) + lines[n][1:]
lines[end] = "= " + lines[end][3:]
return lines

expected = normalize_to_positive_results(expected)
generated = normalize_to_positive_results(generated)

assert generated == expected, (
"Failed matching expected with generated lp file:\n"
+ "\n".join(
unified_diff(
expected,
generated,
fromfile=ospath.relpath(expected_file.name),
tofile=ospath.basename(generated_file.name),
lineterm="",
)
),
)
exp = expected_file.read()
gen = generated_file.read()

# lp_diff returns two arrays of strings with cleaned lp syntax
# It automatically prints the diff
exp_diff, gen_diff = lp_diff(exp, gen)

# sometimes, 0.0 is printed, sometimes 0, harmonise that
exp_diff = [
line + " ".replace(" 0.0 ", " 0 ") for line in exp_diff
]
gen_diff = [
line + " ".replace(" 0.0 ", " 0 ") for line in gen_diff
]

assert len(exp_diff) == len(gen_diff)

# Created the LP files do not have a reproducible
# order of the lines. Thus, we sort the lines.
for exp, gen in zip(sorted(exp_diff), sorted(gen_diff)):
assert (
exp == gen
), "Failed matching expected with generated lp file."

def test_linear_transformer(self):
"""Constraint test of a Transformer without Investment."""
Expand Down
27 changes: 12 additions & 15 deletions tests/lp_files/activity_costs.lp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

min
objective:
+2 NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_0)
+2 NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_1)
+2 NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_2)
+10 flow(cheap_plant_activity_costs_Bus_C_0_0)
+10 flow(cheap_plant_activity_costs_Bus_C_0_1)
+10 flow(cheap_plant_activity_costs_Bus_C_0_2)
+2 NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_0)
+2 NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_1)
+2 NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_2)

s.t.

Expand Down Expand Up @@ -39,42 +39,39 @@ c_e_NonConvexFlowBlock_status_nominal_constraint(cheap_plant_activity_costs_Bus_
= 0

c_u_NonConvexFlowBlock_min(cheap_plant_activity_costs_Bus_C_0_0)_:
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_0)
-1 flow(cheap_plant_activity_costs_Bus_C_0_0)
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_0)
<= 0

c_u_NonConvexFlowBlock_min(cheap_plant_activity_costs_Bus_C_0_1)_:
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_1)
-1 flow(cheap_plant_activity_costs_Bus_C_0_1)
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_1)
<= 0

c_u_NonConvexFlowBlock_min(cheap_plant_activity_costs_Bus_C_0_2)_:
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_2)
-1 flow(cheap_plant_activity_costs_Bus_C_0_2)
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_2)
<= 0

c_u_NonConvexFlowBlock_max(cheap_plant_activity_costs_Bus_C_0_0)_:
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_0)
+1 flow(cheap_plant_activity_costs_Bus_C_0_0)
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_0)
<= 0

c_u_NonConvexFlowBlock_max(cheap_plant_activity_costs_Bus_C_0_1)_:
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_1)
+1 flow(cheap_plant_activity_costs_Bus_C_0_1)
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_1)
<= 0

c_u_NonConvexFlowBlock_max(cheap_plant_activity_costs_Bus_C_0_2)_:
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_2)
+1 flow(cheap_plant_activity_costs_Bus_C_0_2)
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_2)
<= 0

c_e_ONE_VAR_CONSTANT:
ONE_VAR_CONSTANT = 1.0

bounds
0 <= flow(cheap_plant_activity_costs_Bus_C_0_0) <= 10
0 <= flow(cheap_plant_activity_costs_Bus_C_0_1) <= 10
0 <= flow(cheap_plant_activity_costs_Bus_C_0_2) <= 10
0 <= flow(cheap_plant_activity_costs_Bus_C_0_0) <= 10.0
0 <= flow(cheap_plant_activity_costs_Bus_C_0_1) <= 10.0
0 <= flow(cheap_plant_activity_costs_Bus_C_0_2) <= 10.0
0 <= NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_0) <= 1
0 <= NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_1) <= 1
0 <= NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_2) <= 1
Expand Down
51 changes: 24 additions & 27 deletions tests/lp_files/activity_costs_multi_period.lp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

min
objective:
+10 flow(cheap_plant_activity_costs_Bus_C_0_0)
+10 flow(cheap_plant_activity_costs_Bus_C_0_1)
+9.80392156862745 flow(cheap_plant_activity_costs_Bus_C_1_2)
+9.80392156862745 flow(cheap_plant_activity_costs_Bus_C_1_3)
+9.611687812379854 flow(cheap_plant_activity_costs_Bus_C_2_4)
+9.611687812379854 flow(cheap_plant_activity_costs_Bus_C_2_5)
+2 NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_0)
+2 NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_1)
+1.9607843137254901 NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_2)
+1.9607843137254901 NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_3)
+1.9223375624759707 NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_4)
+1.9223375624759707 NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_5)
+10 flow(cheap_plant_activity_costs_Bus_C_0_0)
+10 flow(cheap_plant_activity_costs_Bus_C_0_1)
+9.8039215686274499 flow(cheap_plant_activity_costs_Bus_C_1_2)
+9.8039215686274499 flow(cheap_plant_activity_costs_Bus_C_1_3)
+9.6116878123798539 flow(cheap_plant_activity_costs_Bus_C_2_4)
+9.6116878123798539 flow(cheap_plant_activity_costs_Bus_C_2_5)

s.t.

Expand Down Expand Up @@ -72,75 +72,72 @@ c_e_NonConvexFlowBlock_status_nominal_constraint(cheap_plant_activity_costs_Bus_
= 0

c_u_NonConvexFlowBlock_min(cheap_plant_activity_costs_Bus_C_0_0)_:
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_0)
-1 flow(cheap_plant_activity_costs_Bus_C_0_0)
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_0)
<= 0

c_u_NonConvexFlowBlock_min(cheap_plant_activity_costs_Bus_C_0_1)_:
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_1)
-1 flow(cheap_plant_activity_costs_Bus_C_0_1)
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_1)
<= 0

c_u_NonConvexFlowBlock_min(cheap_plant_activity_costs_Bus_C_1_2)_:
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_2)
-1 flow(cheap_plant_activity_costs_Bus_C_1_2)
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_2)
<= 0

c_u_NonConvexFlowBlock_min(cheap_plant_activity_costs_Bus_C_1_3)_:
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_3)
-1 flow(cheap_plant_activity_costs_Bus_C_1_3)
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_3)
<= 0

c_u_NonConvexFlowBlock_min(cheap_plant_activity_costs_Bus_C_2_4)_:
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_4)
-1 flow(cheap_plant_activity_costs_Bus_C_2_4)
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_4)
<= 0

c_u_NonConvexFlowBlock_min(cheap_plant_activity_costs_Bus_C_2_5)_:
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_5)
-1 flow(cheap_plant_activity_costs_Bus_C_2_5)
+0.5 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_5)
<= 0

c_u_NonConvexFlowBlock_max(cheap_plant_activity_costs_Bus_C_0_0)_:
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_0)
+1 flow(cheap_plant_activity_costs_Bus_C_0_0)
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_0)
<= 0

c_u_NonConvexFlowBlock_max(cheap_plant_activity_costs_Bus_C_0_1)_:
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_1)
+1 flow(cheap_plant_activity_costs_Bus_C_0_1)
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_1)
<= 0

c_u_NonConvexFlowBlock_max(cheap_plant_activity_costs_Bus_C_1_2)_:
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_2)
+1 flow(cheap_plant_activity_costs_Bus_C_1_2)
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_2)
<= 0

c_u_NonConvexFlowBlock_max(cheap_plant_activity_costs_Bus_C_1_3)_:
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_3)
+1 flow(cheap_plant_activity_costs_Bus_C_1_3)
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_3)
<= 0

c_u_NonConvexFlowBlock_max(cheap_plant_activity_costs_Bus_C_2_4)_:
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_4)
+1 flow(cheap_plant_activity_costs_Bus_C_2_4)
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_4)
<= 0

c_u_NonConvexFlowBlock_max(cheap_plant_activity_costs_Bus_C_2_5)_:
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_5)
+1 flow(cheap_plant_activity_costs_Bus_C_2_5)
-1 NonConvexFlowBlock_status_nominal(cheap_plant_activity_costs_Bus_C_5)
<= 0

c_e_ONE_VAR_CONSTANT:
ONE_VAR_CONSTANT = 1.0

bounds
0 <= flow(cheap_plant_activity_costs_Bus_C_0_0) <= 10
0 <= flow(cheap_plant_activity_costs_Bus_C_0_1) <= 10
0 <= flow(cheap_plant_activity_costs_Bus_C_1_2) <= 10
0 <= flow(cheap_plant_activity_costs_Bus_C_1_3) <= 10
0 <= flow(cheap_plant_activity_costs_Bus_C_2_4) <= 10
0 <= flow(cheap_plant_activity_costs_Bus_C_2_5) <= 10
0 <= flow(cheap_plant_activity_costs_Bus_C_0_0) <= 10.0
0 <= flow(cheap_plant_activity_costs_Bus_C_0_1) <= 10.0
0 <= flow(cheap_plant_activity_costs_Bus_C_1_2) <= 10.0
0 <= flow(cheap_plant_activity_costs_Bus_C_1_3) <= 10.0
0 <= flow(cheap_plant_activity_costs_Bus_C_2_4) <= 10.0
0 <= flow(cheap_plant_activity_costs_Bus_C_2_5) <= 10.0
0 <= NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_0) <= 1
0 <= NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_1) <= 1
0 <= NonConvexFlowBlock_status(cheap_plant_activity_costs_Bus_C_2) <= 1
Expand Down
Loading

0 comments on commit 7040c22

Please sign in to comment.