Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace constraint tests #1080

Merged
merged 63 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
8caffe7
Adjust indexing for content of InvestStorageBlock
p-snft Jan 18, 2024
1fcf6ff
Remove constraint tests
p-snft Jun 11, 2024
ed0d677
Merge branch 'dev' into revision/replace-constraint-tests
p-snft Jul 2, 2024
4f11cb6
Improve testability of installation test
p-snft Jul 2, 2024
4276543
Compare bool according to style guide
p-snft Jul 2, 2024
23bcc39
Compare bool according to style guide
p-snft Jul 2, 2024
7ef38e1
Move test_constraints to own directory
p-snft Jul 2, 2024
6b1a2b3
Move create_time_index to helpers
p-snft Jul 2, 2024
0869463
Fix type hint in create_time_index
p-snft Jul 2, 2024
12f5bcf
Properly test create_time_index()
p-snft Jul 2, 2024
83e5645
Merge BaseModel into Model
p-snft Jul 3, 2024
1b04e70
Warn if model overwrites timeincrement
p-snft Jul 3, 2024
61a02a5
Test (invalid) arguments of OffsetConverter
p-snft Jul 3, 2024
fc12b2a
Adhere to Black
p-snft Jul 3, 2024
6a87fb4
Delete useless lines
p-snft Jul 3, 2024
9290ab2
Test coefficient check in OffsetTransformer
p-snft Jul 3, 2024
526ac1a
Merge branch 'dev' into revision/replace-constraint-tests
p-snft Aug 1, 2024
c483a84
Fix import order
p-snft Aug 1, 2024
91aca54
Refactor model solving tests
p-snft Aug 1, 2024
c4a770d
Delete unneccesary warnings filter
p-snft Aug 1, 2024
04efa3f
Adhere to Black
p-snft Aug 2, 2024
0b319e9
Remove remaints of cellular approach draft
p-snft Aug 2, 2024
5e3b90c
Merge branch 'revision/remove_remains_of_cellular' into revision/repl…
p-snft Aug 2, 2024
078d99a
Add test for storage_level_constraint
p-snft Aug 2, 2024
d6440a6
Properly format imports in test_storage_level_constraint
p-snft Aug 8, 2024
9c4d30c
Test integral_imit_constraint
p-snft Aug 8, 2024
848289a
Move flow class test to subdirectory
p-snft Aug 8, 2024
ba7cf70
Turn off unprented verbose output
p-snft Aug 8, 2024
99baf36
Add test for inital status
p-snft Aug 8, 2024
2d80800
Deaktivate failing test
p-snft Aug 8, 2024
f8af61e
Fix test_initial_status_on
p-snft Aug 8, 2024
b68014a
Remove unused import
p-snft Aug 13, 2024
c51e725
Add tests for startup and shutdown costs
p-snft Aug 13, 2024
40ef8ea
Add test for activity_costs
p-snft Aug 13, 2024
b3cef12
Refine test for activity_costs
p-snft Aug 13, 2024
6b937ac
Add test for inactivity_costs
p-snft Aug 13, 2024
896f73b
Add tests for maximum startups and shutdowns
p-snft Aug 13, 2024
be0c7ad
Remove unnecessary arrtibute checks
p-snft Aug 14, 2024
516277e
Add storage power investment tests
p-snft Aug 14, 2024
4b84d70
Add test for storage capacity invest
p-snft Aug 14, 2024
1597318
Fix initial time step of for InvestStorage
p-snft Aug 14, 2024
1e62bd1
Merge branch 'dev' into fix/invest_storage_content_revised
p-snft Aug 14, 2024
f2c9eed
Merge branch 'fix/invest_storage_content_revised' into revision/repla…
p-snft Aug 14, 2024
d9f7012
Fix storage dump test
p-snft Aug 14, 2024
ccd1b5d
Remove outdated comments
p-snft Aug 14, 2024
92a3504
Merge branch 'fix/invest_storage_content_revised' into revision/repla…
p-snft Aug 14, 2024
7ffc81f
Adjust test_results_with_recent_dump()
p-snft Aug 14, 2024
a6b3d55
Add test for min/max storage investment
p-snft Aug 14, 2024
9cb533b
Remove unneeded code in GenericInvestmentStorageBlock
p-snft Aug 14, 2024
2e0e251
Refactor ambigous conditional statement
p-snft Aug 14, 2024
d51d94e
Silence warnings in tests
p-snft Aug 15, 2024
7ea1ccc
Merge branch 'dev' into revision/replace-constraint-tests
p-snft Aug 15, 2024
a768fe3
Improve warning filter compatibility
p-snft Aug 15, 2024
a001ba8
Add test for "equate flows"
p-snft Aug 15, 2024
60ce70a
Add tests for SimpleFlowBlock
p-snft Aug 15, 2024
a127874
Refactor some style
p-snft Aug 15, 2024
0d8668d
Add test for limit_active_flow_count_by_keyword
p-snft Aug 15, 2024
eb050e7
Let tests pass with 85 % coverage
p-snft Aug 15, 2024
0cdecaf
Remove unused import
p-snft Aug 15, 2024
609cabd
Merge branch 'dev' into revision/replace-constraint-tests
p-snft Aug 19, 2024
2ec9a02
Refactor outdated names
p-snft Aug 19, 2024
c5a62ed
Remove internal discounting for nonconvex properties
p-snft Aug 20, 2024
c8263ce
Merge branch 'revision/remove-discounting-functionality' into revisio…
p-snft Aug 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tox_pytests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: tox

- name: Check test coverage
run: coverage report -m --fail-under=${{ matrix.vcs == 'bzr' && 89 || 90 }}
run: coverage report -m --fail-under=${{ matrix.vcs == 'bzr' && 84 || 85 }}

- name: Report to coveralls
run: coveralls
Expand Down
2 changes: 1 addition & 1 deletion src/oemof/solph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from . import processing
from . import views
from ._energy_system import EnergySystem
from ._energy_system import create_time_index
from ._groupings import GROUPINGS
from ._helpers import create_time_index
from ._models import Model
from ._options import Investment
from ._options import NonConvex
Expand Down
50 changes: 33 additions & 17 deletions src/oemof/solph/_console_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from oemof import solph


def check_oemof_installation(silent=False):
def _check_oemof_installation(solvers):
logging.disable(logging.CRITICAL)

date_time_index = pd.date_range("1/1/2012", periods=6, freq="h")
Expand Down Expand Up @@ -48,22 +48,38 @@ def check_oemof_installation(silent=False):
om = solph.Model(energysystem)

# check solvers
solver = dict()
for s in ["cbc", "glpk", "gurobi", "cplex"]:
solver_status = dict()
for s in solvers:
try:
om.solve(solver=s)
solver[s] = "working"
solver_status[s] = True
except Exception:
solver[s] = "not working"

if not silent:
print()
print("*****************************")
print("Solver installed with oemof:")
print()
for s, t in solver.items():
print("{0}: {1}".format(s, t))
print()
print("*****************************")
print("oemof successfully installed.")
print("*****************************")
solver_status[s] = False

return solver_status


def check_oemof_installation():

solvers_to_test = ["cbc", "glpk", "gurobi", "cplex"]

solver_status = _check_oemof_installation(solvers_to_test)

print_text = (
"***********************************\n"
"Solver installed with oemof.solph:\n"
"\n"
)
for solver, works in solver_status.items():
if works:
print_text += f"{solver}: installed and working\n"
else:
print_text += f"{solver}: not installed/ not working\n"
print_text += (
"\n"
"***********************************\n"
"oemof.solph successfully installed.\n"
"***********************************\n"
)

print(print_text)
70 changes: 0 additions & 70 deletions src/oemof/solph/_energy_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

"""

import calendar
import datetime
import warnings

import numpy as np
Expand Down Expand Up @@ -244,71 +242,3 @@ def get_period_duration(self, period):
- self.periods[period].min().year
+ 1
)


def create_time_index(
year: int = None,
interval: float = 1,
number: int = None,
start: datetime.datetime or datetime.date = None,
):
"""
Create a datetime index for one year.

Notes
-----
To create 8760 hourly intervals for a non leap year a datetime index with
8761 time points need to be created. So the number of time steps is always
the number of intervals plus one.

Parameters
----------
year : int, datetime
The year of the index. If number and start is set the year parameter is
ignored.
interval : float
The time interval in hours e.g. 0.5 for 30min or 2 for a two hour
interval (default: 1).
number : int
The number of time intervals. By default number is calculated to create
an index of one year. For a shorter or longer period the number of
intervals can be set by the user.
start : datetime.datetime or datetime.date
Optional start time. If start is not set, 00:00 of the first day of
the given year is the start time.

Examples
--------
>>> len(create_time_index(2014))
8761
>>> len(create_time_index(2012)) # leap year
8785
>>> len(create_time_index(2014, interval=0.5))
17521
>>> len(create_time_index(2014, interval=0.5, number=10))
11
>>> len(create_time_index(2014, number=10))
11
>>> str(create_time_index(2014, interval=0.5, number=10)[-1])
'2014-01-01 05:00:00'
>>> str(create_time_index(2014, interval=2, number=10)[-1])
'2014-01-01 20:00:00'
"""
if number is None:
if calendar.isleap(year):
hoy = 8784
else:
hoy = 8760
number = round(hoy / interval)
if start is None:
start = f"1/1/{year}"
try:
time_index = pd.date_range(
start, periods=number + 1, freq=f"{interval}h"
)
except ValueError:
# Pandas <2.2 compatibility
time_index = pd.date_range(
start, periods=number + 1, freq=f"{interval}H"
)
return time_index
76 changes: 76 additions & 0 deletions src/oemof/solph/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@

"""

import calendar
import datetime
from warnings import warn

import pandas as pd
from oemof.tools import debugging


Expand Down Expand Up @@ -45,3 +48,76 @@ def warn_if_missing_attribute(obj, attribute):
msg.format(attribute, obj.label, type(obj)),
debugging.SuspiciousUsageWarning,
)


def create_time_index(
year: int = None,
interval: float = 1,
number: int = None,
start: datetime.date = None,
):
"""
Create a datetime index for one year.

Notes
-----
To create 8760 hourly intervals for a non leap year a datetime index with
8761 time points need to be created. So the number of time steps is always
the number of intervals plus one.

Parameters
----------
year : int, datetime
The year of the index.
Used to automatically set start and number for the specific year.
interval : float
The time interval in hours e.g. 0.5 for 30min or 2 for a two hour
interval (default: 1).
number : int
The number of time intervals. By default number is calculated to create
an index of one year. For a shorter or longer period the number of
intervals can be set by the user.
start : datetime.datetime or datetime.date
Optional start time. If start is not set, 00:00 of the first day of
the given year is the start time.

Examples
--------
>>> len(create_time_index(2014))
8761
>>> len(create_time_index(2012)) # leap year
8785
>>> len(create_time_index(2014, interval=0.5))
17521
>>> len(create_time_index(2014, interval=0.5, number=10))
11
>>> len(create_time_index(2014, number=10))
11
>>> str(create_time_index(2014, interval=0.5, number=10)[-1])
'2014-01-01 05:00:00'
>>> str(create_time_index(2014, interval=2, number=10)[-1])
'2014-01-01 20:00:00'
"""
if number is None:
if calendar.isleap(year):
hours_in_year = 8784
else:
hours_in_year = 8760
number = round(hours_in_year / interval)
if start is not None:
if year is not None:
raise ValueError(
"Arguments 'start' and 'year' are mutually exclusive."
)
else:
start = f"1/1/{year}"
try:
time_index = pd.date_range(
start, periods=number + 1, freq=f"{interval}h"
)
except ValueError:
# Pandas <2.2 compatibility
time_index = pd.date_range(
start, periods=number + 1, freq=f"{interval}H"
)
return time_index
Loading
Loading